16,015,072 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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.