Newbie: MissingMethodException error with managed/unmanaged C++

G

Guest

Hello,

I realize that MS doesn't support managed C++ on CF, but I was wondering if
anyone could help a newbie out....

On the WinCE .NET Emulator, I'm running a simple C# form that calls a method
inside a managed C++ class. That method uses new and delete to create and
destroy an unmanaged C++ object:

Code snippet in my C# form:

try
{
Test.Managed.f();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}

C++ code:

namespace Test
{
class Unmanaged
{
public:
Unmanaged() {}
};

public __gc class Managed
{
public:
static void f()
{
// This code causes a MissingMethodException in my form.
Unmanaged* um = new Unmanaged();
delete um;

// This code runs fine.
// Unmanaged um;
}
};
}

If I use the new/delete code in Managed.f(), I get a MissingMethodException
at the function call in my C# form code. I can't even step into Managed.f()
in the debugger. However, if I comment out the new/delete snippet, and
instead use the code below it to create an unmanaged object on the stack, the
code runs fine - no errors. I want to be able to use new and delete on a
pointer - what am I missing? Any thoughts?

Thanks!
 
P

Peter Foot [MVP]

Managed C++ is not supported in the Compact Framework, although it may be
possible to hack together something simple with managed C++ and have it run,
the cf runtime doesn't support many of the msil instructions specific to
managed c++ so you will be unlikely to do this sort of interop. You would be
better off wrapping your C++ classes with native C methods using eVC++ and
then calling these from managed code with P/Invoke.

Peter
 

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