Will,
If my managed header includes a #using <mscorlib.dll>, then the compiler
breaks on the unmanaged class with a
Error 1 fatal error C1190: managed targeted code requires a '/clr' option
c:\my code\ijwtest\ijwtest\managedkaboom.h 2
If I dont have that, of course it cant understand the module syntax and
reports the following
When I include the managed header in the unmanaged module the compiler
reports the following errors
Error 2 error C2871: 'System' : a namespace with this name does not exist
c:\my code\ijwtest\ijwtest\ManagedKaboom.h 4
Error 3 error C2059: syntax error : 'public' c:\my
code\ijwtest\ijwtest\ManagedKaboom.h 11
Error 4 error C2143: syntax error : missing ';' before '{' c:\my
code\ijwtest\ijwtest\ManagedKaboom.h 12
Error 5 error C2447: '{' : missing function header (old-style formal list?)
c:\my code\ijwtest\ijwtest\ManagedKaboom.h 12
ManagedKaboom.H
#pragma once
//#using <mscorlib.dll>
using namespace System;
namespace IJWTest {
public ref class ManagedKaboom
{
public:
ManagedKaboom(void)
{
}
~ManagedKaboom()
{
}
String^ HelloWorld();
};
}
the module is marked with /clr , here it is
#pragma managed
#include "ManagedKaboom.h"
String^ IJWTest::ManagedKaboom::HelloWorld()
{
return "Managed Howdy";
}
So using your technique what would a simple module look like that called
this from unmanaged code (my current prototype is below)
STDMETHOD(HelloWorld)(BSTR* pVal);
Thanks Again
robert
#"William DePalo [MVP VC++ ]" <wi***********@mvps.org> wrote in message
news:eV**************@TK2MSFTNGP10.phx.gbl...
"Robert Ginsburg" <ro*************@ver3.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... If I include the .NET class definition header, the compiler complains
about the format of it, and wont compile
If I dont include the header, the compiler complains that it is not
defined
If I try to use the gcroot template, it does not know the name of the
.NET class.
There are some here who are good at answering questions in the abstract.
I'm not among them.
In the concrete, I'd need to know why the compiler "complaining" about the
header? Is the module that includes it compiled with the /clr switch?
In the abstract, I'm not sure how much this will help, but it is my story
...
In an application of mine where there is an unmanaged function which needs
to create an instance of a managed class, I have a module which has both
managed and unmanaged sections. I delimit the sections with
#pragma managed
...
#pragma unmanaged
In the unmanaged function I call a managed helper function which creates
an instance of the managed class. I use the Alloc member function of the
GCHandle class to get a handle to the object. I convert that to an integer
with
GCHandle::op_Explicit( /* handle goes here */).ToInt32();
It is that integer which I hold on the native side of my application to
refer to the managed object. Of course, it has no meaning except in
managed code. There I use
GCHandle::op_explicit( /* integer goes here */) ;
to convert the integer to a GC handle. That handle can be used to get an
object with the get_target() function of the GCHandle class.
Note that I am not claiming this is a "best practice". It was simply the
most expedient way to add support for .Net plugins to an application of
mine two years ago. You may find it easier and more elegant to use the
gcroot template.
Regards,
Will