Click here to Skip to main content
16,015,072 members

Comments by froggz19 (Top 3 by date)

froggz19 16-May-15 7:11am View    
I tried to convert using wcstombs (found something on google)

wchar_t ip[16];
char ipstr[16];
wcstombs(ipstr, ip, 16);

and called it

Connect(ipstr, port); but it didn't worked, it seems wchar_t is not being converted to normal char, it gives me a chinese letter or something if I call it with MessageBox(nullptr, LPCWSTR(ipstr), L"Error", MB_OK | MB_ICONERROR);

I tried MessageBox(nullptr, va(ip), L"Error", MB_OK | MB_ICONERROR); and it shows the ip inside the ini...
froggz19 16-May-15 6:40am View    
Ok, tried again, thank you for trying to help me. Now the messagebox shows up saying Bad ip Configured.

if (GetFileAttributes(gamepath.c_str()) != INVALID_FILE_ATTRIBUTES)
{
char ip[16];
size_t nSize1 = 1 + strlen(ip);
LPWSTR wIPName = new WCHAR[nSize1];
mbstowcs(wIPName, ip, nSize1);
//now wIPName has the string in required fromat
//GetPrivateProfileString(L"Server", L"IP", L"127.0.0.1", wIPName, _countof(ip), gamepath.c_str());
//the _countof() function is also using 'ip', i hope it does not complain

//when you are done with wIPNmae then delete it

int port;

GetPrivateProfileString(L"Server", L"IP", L"127.0.0.1", wIPName, _countof(ip), gamepath.c_str());
delete[]wIPName;
GetPrivateProfileInt(L"Server", L"PORT", port, gamepath.c_str());

if (ip[0] == '\0')
{
MessageBox(nullptr, va(L"Bad ip configured! %s", ip), L"Error", MB_OK | MB_ICONERROR); // Shows this
ExitProcess(0);
}
else
{
Connect(ip, port);
}
}
else
{
MessageBox(nullptr, va(L"Unable to read ini"), L"Error", MB_OK | MB_ICONERROR);
ExitProcess(0);
}
froggz19 16-May-15 5:29am View    
Deleted
No, it didn't, maybe because I'm a noob, here is the entire code.

<pre lang="c++"> if (GetFileAttributes(gamepath.c_str()) != INVALID_FILE_ATTRIBUTES)
{
char ip[16];
int port;

GetPrivateProfileString(L"Server", L"IP", L"127.0.0.1", ip, _countof(ip), gamepath.c_str());
GetPrivateProfileInt(L"Server", L"PORT", port, gamepath.c_str());

if (ip[0] == '\0')
{
MessageBox(nullptr, va(L"Bad ip configured! %s", ip), L"Error", MB_OK | MB_ICONERROR);
ExitProcess(0);
}
else
{
Connect(ip, port);

}
}
else
{
MessageBox(nullptr, va(L"Unable to read ini"), L"Error", MB_OK | MB_ICONERROR);
ExitProcess(0);
}</pre>

I will go with a txt file instead of ini, it looks much easier.