call c# dll function from another app

D

dotnetchic

What I'm trying to do is invoke a c# dll from a c++ application. I
don't know whether my problem is in the c# or the c++ code.

My c# dll contains a public static function that I'm trying to invoke.
However, I can't obtain a pointer to the function. Using
AfxLoadLibrary from the c++ side, the library loads fine, but
GetProcAddress returns null.

I've been searching through documentation, but came up empty. What am
I missing?
 
N

Nicholas Paldino [.NET/C# MVP]

dotnetchic,

.NET dlls can not be accessed in this manner, since they do not export
functions that can be found using GetProcAddress.

Rather, you have to expose your object as a COM object in order to use
it in unmanaged code, or use managed C++ to access it (the latter being the
easier, in my opinion).

Hope this helps.
 
W

Willy Denoyette [MVP]

| What I'm trying to do is invoke a c# dll from a c++ application. I
| don't know whether my problem is in the c# or the c++ code.
|
| My c# dll contains a public static function that I'm trying to invoke.
| However, I can't obtain a pointer to the function. Using
| AfxLoadLibrary from the c++ side, the library loads fine, but
| GetProcAddress returns null.
|
| I've been searching through documentation, but came up empty. What am
| I missing?
|

C# (or managed assemblies) cannot be loaded by LoadLibrary and family, what
you can do is build a wrapper library in C++ (mixed mode) that wraps the C#
classes and thunks the calls from C++. Yet another option is to use COM
interop to create and access your C# classes.
Check this: http://msdn2.microsoft.com/en-us/library/ms177552.aspx for "C++
interop", I would also suggest you to post your questions to a vc NG or one
the vc forums at http://forums.microsoft.com.


Willy.
 
D

dotnetchic

Thanks. I may try that route. I was hoping to opt for the easy way
out, though...
 

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