Christopher Howarth

Hello ~

I have finnally managed to install the PSDK after revamping VC++'s directorys. But now, after including windows.h in stdafx.h, I double clicked on a button in my windows forms app and entered this code:

Code Snippet
MessageBox(GetActiveWindow(),
"Wow you clicked me!", "Elixir ID3 Editor", MB_OK | MB_ICONINFORMATION);

I got these errors:

------ Build started: Project: WinForm, Configuration: Debug Win32 ------

Compiling...

WinForm.cpp

c:\documents and settings\christopher\my documents\visual studio 2005\projects\winform\winform\Form1.h(86) : error C2872: 'MessageBox' : ambiguous symbol

could be 'C:\Program Files\Microsoft Visual Studio 8\VC\include\winuser.h(7205) : int MessageBox(HWND,LPCTSTR,LPCTSTR,UINT)'

or 'c:\windows\microsoft.net\framework\v2.0.50727\system.windows.forms.dll : System::Windows::Forms::MessageBox'

c:\documents and settings\christopher\my documents\visual studio 2005\projects\winform\winform\Form1.h(86) : error C2872: 'MessageBox' : ambiguous symbol

could be 'C:\Program Files\Microsoft Visual Studio 8\VC\include\winuser.h(7205) : int MessageBox(HWND,LPCTSTR,LPCTSTR,UINT)'

or 'c:\windows\microsoft.net\framework\v2.0.50727\system.windows.forms.dll : System::Windows::Forms::MessageBox'

c:\documents and settings\christopher\my documents\visual studio 2005\projects\winform\winform\Form1.h(86) : error C2664: 'MessageBox' : cannot convert parameter 2 from 'const char [20]' to 'LPCTSTR'

Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Build log was saved at "file://c:\Documents and Settings\Christopher\My Documents\Visual Studio 2005\Projects\WinForm\WinForm\Debug\BuildLog.htm"

WinForm - 3 error(s), 0 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Why

Thanks;

~ Christopher Howarth




Re: Visual C++ General Problem with Windows Forms App

scor7910

Hi Christopher.

If you want use unmanaged function, use a Interop.

reference this page.

http://msdn2.microsoft.com/en-us/library/2x8kf7zx(VS.80).aspx

Or you're just want to show message box.

Code like this

Code Snippet

MessageBox::Show("message Box");

Good luck~






Re: Visual C++ General Problem with Windows Forms App

Christopher Howarth

Do you mean put a #pragma unmanaged in front of it That didn't seem to work...

Code Snippet

#pragma unmanaged

[message box code]

#pragma managed

Like that

Hmm... it is strange, I was told that C++ would work in VC++ WinForms... how do I just get it to compile!!! Sad






Re: Visual C++ General Problem with Windows Forms App

scor7910

HI..

I didn't mentioned #pragma..

I mean use InteropServices interface, as I linked.

Code Snippet

using namespace System::Runtime::InteropServices;

// Implicit DLLImport specifying calling convention
[DllImport("user32.dll", EntryPoint = "MessageBox", CallingConvention = CallingConvention::Cdecl, CharSet = CharSet::Ansi)]
extern "C" int __stdcall MessageBox(void*, System::String^, System::String^, unsigned int );

....

MessageBox(0, "sdfsdf", "dsff", 0x00000000L);

//0x00000000L : MB_OK declared at user32.h






Re: Visual C++ General Problem with Windows Forms App

Christopher Howarth

Yay! It works at last!

However, will this work for any WinAPI function The thing I just don't understand about VC++ is that is won't compile standard C++. And then I can't find any tutorials for the language that it does compile! I found that on the link you gave me Micorsoft tlak about the fact that you can use real C++ with WinForms. I mean, frankly, if it didn't do that then it shouldn't be called Visual C++. As you can see, I am very puzzled and frustrated at VC++. Please explain what it is all about! And thankyou. Big Smile






Re: Visual C++ General Problem with Windows Forms App


Re: Visual C++ General Problem with Windows Forms App

Sheng Jiang

Use :: in front of MessageBox. or remove your using System::Windows::Forms; statement. That's why name space is introduced in the first place.






Re: Visual C++ General Problem with Windows Forms App

Christopher Howarth

OK, thanks. Just one more thing. I have just tried to store the value returned by a function in a variable. It look like this

[code]char* fname = OpenFile->ShowDialog[/code]

This could just be because ShowDialog returns void, but I suspect that it is something to do with all this managed code stuff. Am I correct If so, how do I get the value ShowDialog returns Thankyou.