/*
To Marc
Here is the error message.
Thanks.
Error message:
------ Build started: Project: messageBox, Configuration: Debug Win32 ------
Compiling...
stdafx.cpp
Compiling...
AssemblyInfo.cpp
messageBox.cpp
messageBox.cpp(13) : error C2039: 'Windows' : is not a member of 'System'
messageBox.cpp(15) : error C2144: syntax error : 'void' should be preceded
by ';'
messageBox.cpp(15) : error C2871: 'Forms' : a namespace with this name does
not exist
messageBox.cpp(15) : fatal error C1004: unexpected end of file found
Generating Code...
Build log was saved at "file://c:\project2\messageBox\Debug\BuildLog.htm"
messageBox - 4 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
*/
#include "stdafx.h"
#include <gcroot.h>
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Windows::Forms
typedef void* HWND;
[DllImportAttribute("User32.dll", CharSet=CharSet::Auto)]
extern "C" int MessageBox(HWND hw, String* text,
String* caption, unsigned int type);
__gc class MClass
{
public:
int val;
MClass(int n) //costructor
{
val = n;
}
};
class UClass
{
public :
gcroot<MClass*> mc;
UClass(MClass* pmc) //constructor
{
mc = pmc;
}
int getValue() //get function
{
return mc->val;
}
};
int _tmain()
{
Console::WriteLine(S"Testing...");
//Create a managed object and assign 3 to it
MClass* pm = new MClass (3);
//Create an unmanaged object and assign the
//value of the manged object (pm)to it
UClass uc(pm);
Console::WriteLine(S"Value is {0}", __box(uc.getValue()));
//^-------- This will work # 1
//MessageBox(0, uc.getValue(), S"Message Box...", 0 );
//^------- this will not work # 2
return 0;
}
[quoted text, click to view] "Marc Gravell" <marc.gravell@gmail.com> wrote in message
news:1180856932.317442.19120@w5g2000hsg.googlegroups.com...
> MessageBox is not a method - it is a class with some static methods.
>
> You also need to make sure that you reference System.Windows.Forms and
> add System.Windows.Forms to your namespace list (I've never used
> managed C++, but I'd guess (from your code) "using namespace
> System::Windows::Forms;").
>
> After that, you should be able to call MessageBox.Show(...)
>
> If this doesn't work, please post the *actual* error message shown,
> indicating whether it is compiler or runtime; copy and paste, not
> paraphrased.
>
> Marc
>