Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / How do I use strings in C++? (LPSTR or LPCWSTR?)

Author
Message
Clonkex
Forum Vice President
9
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 13th Oct 2010 07:05 Edited at: 13th Oct 2010 07:06
Hey guys,

I have been experimenting with making DLLs in C++. I have been trying to make a message box pop up. Well, it pops up, but it's full of random and strange characters (like trying to open a non-text file in notepad). I tried using casting (I don't really know how but I found a tutorial on how and it got no errors so I was happy), but no matter what I do it just doesn't work. The reason I want it to work is because I'm assuming that if the message box gets messed-up text then anything that uses strings will be messed up. Here is the .cpp code so far:



And that compiles, and the getvalue things work in DBPro, but the messagebox still gets messed up. I will post my .h and .rc files as well. resource.h:



test9.rc:



Could someone please help???

EDIT: I'm using Visual Studio C++ 2008 Express, so I have no resource editor.

Clonkex

Making games is easy.....finishing them is a different matter.

Intel Core 2 Duo 2.8Ghz, Nvidia GeForce 9400 GT 512mb, 1gb ram.
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Oct 2010 15:29
Use either LPSTR or LPCSTR, and remove the casts from your MessageBox function as they aren't needed ... unless you've accidentally switched your application to be compiled in unicode mode, which is wrong.

If you have, then open up your project properties and switch the General/Character set to multibyte instead of unicode.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
Clonkex
Forum Vice President
9
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 17th Oct 2010 09:50
Ok, thanks heaps. I will try that after I have replied to my many emails (haven't replied for ages)

Clonkex

Making games is easy.....finishing them is a different matter.

Intel Core 2 Duo 2.8Ghz, Nvidia GeForce 9400 GT 512mb, 1gb ram.
Clonkex
Forum Vice President
9
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 17th Oct 2010 11:31
Btw, do you use that for the input or the output? With the MessageBox function you have to have the LPWCSTR, or it says it could not convert it or something (a fatal error). As far as I know, I haven't changed any unicode or multibyte settings, but I will have a look.

Plus, what do you need to have in the code to return strings with other functions? Because in the technical help files for DBPro (which seriously need to be updated), it says you need to jump all sorts of hoops to return strings.

Clonkex

Making games is easy.....finishing them is a different matter.

Intel Core 2 Duo 2.8Ghz, Nvidia GeForce 9400 GT 512mb, 1gb ram.
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Oct 2010 16:09
If MessageBox requires a LPWCSTR variable, then you have your project set to Unicode mode. See my previous post.

For returning strings, see the explanation & code in this post: http://forum.thegamecreators.com/?m=forum_view&t=109551&b=18 ... EXCEPT, that although everything there casts the strings to DWORD, you don't actually need to do that - just return a LPSTR.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
Clonkex
Forum Vice President
9
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 18th Oct 2010 03:00
Ok, thanks. It was in Unicode mode. Now in Multibyte. And it works now, so I can make my own error messages!

I tip, though, you really need to add an option to your error messages functions, so that you can turn off the "at line XXX" thing. I had real need of that (until I fixed my C++ stuff), but many people don't even have a C++ compiler so can't do that. It would be very simple, too.

Clonkex

P.S. Lol to your sig!

Making games is easy.....finishing them is a different matter.

Intel Core 2 Duo 2.8Ghz, Nvidia GeForce 9400 GT 512mb, 1gb ram.

Login to post a reply

Server time is: 2019-10-17 03:29:14
Your offset time is: 2019-10-17 03:29:14