i am doing my first c++/CLI project with windows form. The main idea is to make a graphical interface that uses data that i get from a server. I use curl to talk to server which gives me a json string. I then use rapidJson. I am new to c++ so please be patient with noobie mistakes. My file called Myform.h includes skapakonto.h. I am getting the following:
Error C2039 'UTF': is not a member of 'Project1' line 149
code where i am getting error is in file called skapaKonto.h
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int httpCode(0);
std::string readBuffer;
//string* retval;
if (curl) {
String^ anamn = this->textBox1->Text;
const char* url = "serverip/TP/Admin/funktioner/skapa.php";
string param = "nyckel=iRxOUsizwhoXddb4&funktion=skapaAKonto&anamn=" + msclr::interop::marshal_as<std::string>(anamn) + "&tjanst=47&rollid=6";
//string param = "nyckel=iRxOUsizwhoXddb4&funktion=skapaAKonto&anamn=BJORN&tjanst=47&rollid=6";
const char *data = param.c_str();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Project1::UTF::callback); //line 149, where error originates
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
ret = curl_easy_perform(curl);
if (ret != CURLE_OK)
Console::Write("fel på begäran");
cout << readBuffer;
curl_easy_cleanup(curl);
const char* json = readBuffer.c_str();
Document d;
d.Parse(json);
StringBuffer buffer;
Writer<StringBuffer, Document::EncodingType, UTF8<> > writer(buffer);
d.Accept(writer);
const char* output = buffer.GetString();
std::cout << output;
MessageBoxA(NULL, output, "serversvar:", MB_OK | MB_ICONQUESTION);
}
}
};
i have 2 namespace Project1, 1 in each file. MyForm.h has the namespace UTF in it. If i put the content of namespace UTF in skapakonto.h i get errors related to defining something multiple times (even if i name it something else). This is the top of skapaKonto.h where i have inclusions:
#pragma once
#include <ctime>
#include <list>
#include <string>
#include <cmath>
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include <iostream>
#include <msclr\marshal_cppstd.h>
#include "rapidjson/encodings.h"
#define CURL_STATICLIB
#include <curl/curl.h>
#include <algorithm>
#include <codecvt>
namespace Project1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace rapidjson;
using namespace std;
I am thinking this might be an error to do with inclusions or namespace. Any thoughts on what i am doing wrong/potential solutions?
What i had to do in the end was remove projekt1:: before UTF::Callback, and put inline infront of callback where i create the function. That solved the issue