469,629 Members | 1,254 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,629 developers. It's quick & easy.

HOWTO call static managed function from unmanaged code.

A little more info.

I have a unmanaged C++ DLL, compiled without /CLR.
Inside a Managed C++ DLL, I have the following class:

MarshalWrapper.h
----
#ifdef _MANAGED
__nogc
#endif
class MarshalWrapper
{
public:
MarshalWrapper();
~MarshalWrapper();

static bool IsExceptionActive();
};

MarshalWrapper.cpp
----
MarshalWrapper::MarshalWrapper()
{
}

MarshalWrapper::~MarshalWrapper()
{
}

bool MarshalWrapper::IsExceptionActive()
{
const unsigned long cnNoExceptionActive = 0xCCCCCCCC;
return Marshal::GetExceptionCode() != cnNoExceptionActive;
}

Inside my Unmanaged C++ project, I add a reference to the Managed C++
project, and call MarshalWrapper::IsExceptionActive().

I get the following error:
File1.obj : error LNK2019: unresolved external symbol "public: static
bool __cdecl MarshalWrapper::IsExceptionActive(void)"
(?IsExceptionActive@MarshalWrapper@@SA_NXZ) referenced in function
"public: __thiscall File1::~File1(void)" (??1File1@@QAE@XZ)

I tried changing the function declaration to be __cdecl, but this
caused other confusing problems.

All the examples I have are from calling managed code inside a managed
C++ project inside a #pragma unmanaged block, is it not possible to
make calls from a project not compiled with /CLR? If not, what are the
downsides to changing my unmanaged C++ project to /CLR? In particular,
are there any performance implications?

Thanks,
-ken
ra*************@gmail.com (Ken Durden) wrote in message news:<f3*************************@posting.google.c om>...
I'm trying to call

Marshall::GetExceptionCode() from Unmanaged C++.

Can I use gcroot to do this, or is there a simpler way?

-ken

Nov 17 '05 #1
0 1238

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by sunil s via DotNetMonster.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.