0

I currently have a C# project that uses a 32 bit dll. What I am trying to do is to use the dll in a C++ project , unfortunately the dll referenced in the project does not come with a .h or .lib file so I am confused on how I could access the classes in the dll or use the dll file in my project in C++ (Visual Studio 2010) . I read here that if a dll file contains classes its a good chance it might be a COM component.Any suggestions on what I should be looking at in order to integrate and consume methods and objects in that dll.

Update:

I checked if it was a COM by doing an import statement. However I get a "cannot find .tlb file". Then I decided to use dependency walker to check for any exported methods (objects)it seems there are none. I clicked on the main file (which has been highlighted) and couldn't see any exported functions. Any hints on what I should check for next ?. Here is what I get from dependency walker. enter image description here

Community
  • 1
  • 1
Rajeshwar
  • 11,179
  • 26
  • 86
  • 158
  • 1
    Just add a reference to it under the "COM" or ".NET" tabs in VS's "Add reference..." dialog. If that complains, then bug the library's creator for an import library. :P – cHao Mar 11 '13 at 19:47
  • How do you add a reference in VS2010 in C++.? – Rajeshwar Mar 11 '13 at 19:53
  • Use COM via TLB, try [How to use tlb file in C?](http://stackoverflow.com/questions/4312711/how-to-use-tlb-file-in-c) – lsalamon Mar 11 '13 at 19:53
  • 1
    Have a look [here][1]. and [here][2], maybe someone already answered your question. [1]: http://stackoverflow.com/questions/4041149/how-to-dllimport-in-c [2]: http://stackoverflow.com/questions/1922580/import-a-dll-with-c-win32 – idoo Mar 11 '13 at 19:54

2 Answers2

5

With only a .dll and without a corresponding .h or .exp, one place that you might try looking would be the exports table. Tools such as Dependency Walker can show you this information.

One caveat with Dependency Walker is that you'll want to use the right version (x86 or x86_64) for the binary (your DLL). If you're not sure, pick one version and try loading it. Under the CPU column, middle panel, look to see if it says "x64" or "x86" to determine which one you should be using.

With the provided screenshot of Dependency Walker (indicating a dependency on MSCOREE.DLL), I agree with Eugene - this is most likely a .NET library, not a COM library. You will want to check one of the other questions about calling .NET managed code from C/C++.

user314104
  • 1,528
  • 14
  • 31
  • If it's not obvious, clicking on a module will show you many (but not necessarily all) of the available functions. The panel to the lower-left of the tree view shows you the exported functions for the selected portable executable ("PE") object. – user314104 Mar 11 '13 at 19:54
0

The dll is most likely a .Net assembly (seeing that it imports mscoree.dll), so you probably want this: How do I call a .NET assembly from C/C++?

Community
  • 1
  • 1
Eugene
  • 7,180
  • 1
  • 29
  • 36
  • So does this mean that I cant use it directly in C++ ? From the little that I have read from the link you posted it seems like I'll have to create a C# com wrapper over the methods that I need to use.I'll then have to use that new COM dll in my C++ probably through import ? Am I getting this correct ? – Rajeshwar Mar 12 '13 at 00:28
  • @Rajeshwar, Yep I think that will work. Assembly -> COM wrapper -> C++. – Eugene Mar 12 '13 at 15:19