2

I have recived a SDK from a 3. party. The SDK provides a big bunch of .dll / .lib / .h files But I cannot access any of the files from C#.

I have tried to add the dll's as reference to my C# project, but it pops up and says: "A reference to 'xxx.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component."

And I am not sure how to use the .lib / .h file to access the 3. party SDK. The SDK comes with some sample code that is written in C which accesses the SDK using the .lib/.h files.

How do I access the SDK from C#?

Mr. JWolf
  • 1,375
  • 2
  • 14
  • 33

1 Answers1

2

If the SDK provided to you just contains .dll .lib and .h files means that is a native library (C or C++ library).

For use it you should have a wrapper from this SDK to your managed C# code.

If there isn't the wrapper inside the SDk you should make one by your own via P/Invoke.

This is a summary from MSDN about P/Invoke (not esaustive, just for give you the idea): Platform Invoke Basics

  • I was going to add this as a comment to question but seems more relavant here... [Access a method from a DLL from C# program](http://stackoverflow.com/questions/6392372/access-a-method-from-a-dll-from-c-sharp-program) – Sayse Nov 19 '13 at 10:08
  • I have got this to work, thanks alot. But, the SDK is rather big, so making all the wrappers is going to be a big deal. Is there any tools to create a C# wrapper from a .h file? I have tried SWIG ( http://www.swig.org/ ) but that requires that I have the source code of the SDK which I does not. – Mr. JWolf Nov 19 '13 at 11:19
  • The only tool i can suggest to you is [P/Invoke Interop Assistant ](http://clrinterop.codeplex.com/releases/view/14120). For some complex API can be inaccurate – Salvatore Sorbello Nov 19 '13 at 13:04
  • P/Invoke Interop Assistant doesn't seem to work with my dlls. – Mr. JWolf Nov 19 '13 at 16:52