Chaos Project

Game Development => General Discussion => Topic started by: G_G on February 25, 2011, 07:06:07 pm

Title: Convert char* to LPCWSTR from Variable?
Post by: G_G on February 25, 2011, 07:06:07 pm
Alright so I'm creating a C library to be used in RPG Maker XP or any other engine/program that wants to use it. Anyways I thought I'd experiment with windows.h a little and decided to try and create a method that when called brings up a better message box than rmxp's. It'll allow custom message, title, buttons, and icons. So I know how to convert the char* to the LPCSTRW but only if its in quotes L"Hi". However I am pretty clueless when its in a variable.
char *msg = "Hi there";
LPCWSTR rmsg = TEXT(msg);
// Results in an error
// error C2065: 'Lmsg' : undeclared identifier


I've tried this too.
LPCWSTR rmsg = (LPCWSTR)msg;
// Converts msg to weird japanese letters


Method
	__declspec(dllexport) int MsgBox(char *msg, char *title, int b)
{
// Okay Button
int buttons = 0x00000000L;
switch (b)
{
case 0:
// Okay Button
buttons = 0x00000000L;
case 1:
// Yes No
buttons = 0x00000004L;
case 2:
// Yes No Cancel
buttons = 0x00000003L;
}
LPCWSTR rmsg = (LPCWSTR)msg;
LPCWSTR rtitle = (LPWSTR)title;
int r = MessageBox(0, rmsg, rtitle, buttons);
return r;
}


Any ideas?
Title: Re: Convert char* to LPCWSTR from Variable?
Post by: Blizzard on February 25, 2011, 07:16:04 pm
You will have to use itoa for int, ftoa for float, etc. and then convert the char* into LPCSTRW. Or you can sprintf the variables.
Title: Re: Convert char* to LPCWSTR from Variable?
Post by: G_G on February 25, 2011, 11:17:54 pm
Example please? D: I'm still learning C and C++ and whatnot.
Title: Re: Convert char* to LPCWSTR from Variable?
Post by: Blizzard on February 26, 2011, 03:34:26 am
"char* c = itoa(5)" I guess. Google it. You might want to use sprintf after all, I think that itoa isn't in the standard library. >.<
Title: Re: Convert char* to LPCWSTR from Variable?
Post by: nathmatt on February 26, 2011, 11:11:44 am
this (http://www.cprogramming.com/tutorial/lesson9.html) might help if you haven't resolved it yet

from what i can tell this is what you Are looking for
cout<<"Your long string was: "<< string <<endl;

string being the variable