-1

How do I create a class that I can reference to and directly use to call methods from an unmanaged dll? (assuming an unmanaged dll is a dll that doesn't exists/is known @ compile time)

For example I have a dll which contains the class helloWorld and I want to create an instance of the class and then call helloWorld.tell().

BenMorel
  • 34,448
  • 50
  • 182
  • 322
John
  • 1,095
  • 3
  • 15
  • 31
  • Dynamic does not always mean unmanaged. – Jim D'Angelo Jan 04 '12 at 17:12
  • @JamesD'Angelo could you explain the differents? – John Jan 04 '12 at 17:20
  • C# is a managed language, it uses a garbage collector for it's memory management. C++ is not managed-you must manage memory yourself. You can dynamically load a C# assembly and use reflection to load up classes, call methods, and all of that. This would be a dynamic, managed, assembly. – Jim D'Angelo Jan 04 '12 at 17:22
  • @JamesD'Angelo I see. Than its managed. I thought meant you didn't know the content of the dll @ runtime. the question stil stand on how to get an instance of it. Thanks for explaining so far! – John Jan 04 '12 at 17:26

2 Answers2

0

It appears that you are attempting to dynamically load an assembly, not neccessarily work with an unmanaged assembly. It seems you are looking for information on reflection. You can use Activator to create the objects you need. There are a lot of ways to do this, and I would read up on it. Here are a few resources to get started:

Code Project - Reflection in C# Tutorial

CSharp.Net - Reflection Introduction

CodeGuru.com - An Introduction to Reflection

Jim D'Angelo
  • 3,952
  • 3
  • 25
  • 39
0

You can use your assembly with a COM interface, which is available from unmanaged code.

There are some examples here that you can download. Check out the COM Interop Part II code. http://code.msdn.microsoft.com/windowsdesktop/Visual-Studio-2010-Samples-31b491f3

If you're feeling brave, here's another explanation: http://msdn.microsoft.com/en-us/library/aa645738(v=vs.71).aspx

Hope that helps.

Richard
  • 1,122
  • 1
  • 7
  • 14