memz
memz

Reputation: 45

Compile C++ .lib files make them DLL for C# enviroment

I've got plenty of these object file library : addrstor.exp authhlp.lib

I would like to have them as a DLL and add into the C# project and try to use the method which involved.

How could I achieve that ?

Thanks

Upvotes: 0

Views: 477

Answers (2)

peterept
peterept

Reputation: 4427

C# is ideally suited to calling in to "C" functions. One way is to create an C adapter to the C++ functionality:

Step 1: Expose a C function from the DLL:

extern "C" __declspec(dllexport) int someMethod(int paramA);

Step 2: Import in to C#

[DllImport("your.dll", EntryPoint="someMethod")]
public static extern UInt32 NiceNameFunc(UInt32 paramA);

Upvotes: 2

Alexei Levenkov
Alexei Levenkov

Reputation: 100630

Assuming you want calling native DLL (C++/libs) called from managed (C#) code:

  • make sure your functions are exported form the DLL
  • use whatever favorite linker to link Libs to DLL.
  • create C# class with methods annotated with DllImport
  • make sure your C# project is set for same bitness (x86/x64) as native DLL

If you want compile C++ Libs to managed DLL (assembly) - you can't do that. You may be able to use managed C++ to compile sources to a assembly.

Upvotes: 1

Related Questions