471,315 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,315 software developers and data experts.

call c# dll function from another app

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?

Feb 2 '06 #1
4 1664
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"dotnetchic" <do********@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
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?

Feb 2 '06 #2

"dotnetchic" <do********@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
| 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.

Feb 2 '06 #3
Here is an example which uses COM Interop to expose a .NET assembly to
COM clients. This particular example exposes the DLL to a Java client,
but the COM Interop steps for generating the COM callable wrapper are
the same for any COM client.

http://j-integra.intrinsyc.com/suppo...?article=78813

Regards,
Shane Sauer
------------------------------------------------------------------------------
J-Integra Interoperability Solutions
http://j-integra.intrinsyc.com/
high performance interop middleware for java, corba, com & .net

Feb 2 '06 #4
Thanks. I may try that route. I was hoping to opt for the easy way
out, though...

Feb 3 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by mygoogleaccount | last post: by
46 posts views Thread by Steven T. Hatton | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.