Dynamic load of a c++ dll in C#?

  • Thread starter Thread starter lallous
  • Start date Start date
L

lallous

Hello

I'm new to C# and wonder if it is possible, as it is possible in C++, to
dynamically load a DLL and use it in C#.

The dll is written in C++ (unmanaged) and has the following export:

int test(void);

and the code resides in test.dll

I want a C# application that when I press "Button1", it should
dynamically load test.dll and its 'test' function and call it and get
its return value.

Is this possible in C#? If so, how?

The ultimate goal is to store that external dependency in my C#'s
application resources then extract/use/delete on demand.
 
The dll is written in C++ (unmanaged) and has the following export:
int test(void);

and the code resides in test.dll

I want a C# application that when I press "Button1", it should
dynamically load test.dll and its 'test' function and call it and get
its return value.

Is this possible in C#? If so, how?

you can PInvoke to call Win32 functions, LoadLibrary and GetProcAddress. you
will find a lot of examples via google.

take for example a look here:
http://www.codeproject.com/csharp/dyninvok.asp

Regards, Wiktor Zychla
 
While this works, this has the unfortunate overhead of having to declare
a separate function for every function you wish to call. This can get quite
unwieldy.

While it is a ways off, in the next release of .NET, you will be able to
take an unmanaged function pointer and assign it to a delegate, calling the
function pointer through the delegate.
 
While it is a ways off, in the next release of .NET, you will be able
to
take an unmanaged function pointer and assign it to a delegate, calling the
function pointer through the delegate.

will it be type-safe?
or, in fact, it will not be type-safe, will it?
 

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

Back
Top