Nick Tsui
Nick Tsui

Reputation: 634

native dll calls a .NET dll

I am trying to figure out how this can work:

So here is what I think where the problem is (I could be wrong tho):

How should I do this? Thanks for any suggestions.

Upvotes: 0

Views: 214

Answers (2)

Ted
Ted

Reputation: 48

Your native DLL can be a mixed-mode native-and-.NET assembly, using C++/CLI. Google or search here on "#pragma managed"/"#pragma unmanaged", or look at any of the books on C++/CLI. Basically, assuming you have Visual C++ 2010 or 2012, you can write something like this:

#pragma unmanaged

int main()
{
  CallManagedTrampoline();
}

#pragma managed

void CallManagedTrampoline()
{
  TypeFromDotnetDLL t = new TypeFromDotnetDLL();
  t.CallSomething();
}

In fact, depending on the details of what's in the .NET DLL, you may not even need to put the #pragma managed in front of the CallManagedTrampoline() call--you can sometimes call directly from unmanaged code. C++/CLI is your friend here.

Upvotes: 1

Daniel A. White
Daniel A. White

Reputation: 190905

You will have to expose something as COM in your .NET assembly.

Upvotes: 1

Related Questions