LPCSTR from System::String for newbie please

G

Guest

Please advise, why does
MessageBox(NULL, textBox1.Text, "Error", MB_OK)
work fine in VB
but
MessageBox(NULL, textBox1->Text, "Error", MB_OK)
will not compile in VC++.NET?

Have tried the obvious casts to (LPCSTR) but this tricky System::String__gc*
type is getting away from me.
 
J

Jochen Kalmbach [MVP]

Hi Richard!
Please advise, why does
MessageBox(NULL, textBox1.Text, "Error", MB_OK)
work fine in VB
but
MessageBox(NULL, textBox1->Text, "Error", MB_OK)
will not compile in VC++.NET?

Please do

#undef MessageBox

AFTER including <windows.h> !!!

This will solve the problem!

Have tried the obvious casts to (LPCSTR) but this tricky System::String__gc*
type is getting away from me.

http://blog.kalmbachnet.de/?postid=18

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
G

Guest

Hi Jochen
Thanks for the advice. I had the #include <windows.h> and now added #undef
MessageBox. Did a clean and build.
Now get error C2514 'System::Windows::Forms::MessageBox': class has no
constructors.
Using MessageBoxA and MessageBoxW fails to compile as before with type
mismatch.

If it helps, this is a C++ Windows Forms Application (.NET) with a textbox,
button and one line of code in the button1_click method.

Cheers,
Richard
 
J

Jochen Kalmbach [MVP]

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top