call c# dll function from another app

  • Thread starter Thread starter dotnetchic
  • Start date Start date
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?
 
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.
 
| 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.
 
Thanks. I may try that route. I was hoping to opt for the easy way
out, though...
 
Back
Top