Convert char* to LPCWSTR from Variable?

Started by G_G, February 25, 2011, 07:06:07 pm

Previous topic - Next topic

G_G

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?

Blizzard

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.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Example please? D: I'm still learning C and C++ and whatnot.

Blizzard

"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. >.<
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

nathmatt

this 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
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script