.lib Files
-
Hi Everyone, I am faced with a bit of a problem. I suspect it is a problem only because of my non-existant knowledge of c/c++. I need to use a third party SDK to be able to control and/or monitor some telephony hardware from a popular vendor. My problem is that I have to do this from a .Net environment (C#) but the SDK file are .lib files. It is said that it is dynamically compiled (what that means I have no idea). Can anyone possibly tell me how I could use it from C# and if it's impossible, how I can wrap it in normal dll's (so I can use Dllimport) as normal. Thanks and Regards, Phi?
-
Hi Everyone, I am faced with a bit of a problem. I suspect it is a problem only because of my non-existant knowledge of c/c++. I need to use a third party SDK to be able to control and/or monitor some telephony hardware from a popular vendor. My problem is that I have to do this from a .Net environment (C#) but the SDK file are .lib files. It is said that it is dynamically compiled (what that means I have no idea). Can anyone possibly tell me how I could use it from C# and if it's impossible, how I can wrap it in normal dll's (so I can use Dllimport) as normal. Thanks and Regards, Phi?
As far as I know there is no way to include .lib files in a C# assembly. Your assumption is right in that you have to write a quick wrapper for the .lib but there's good news: the wrapper doesn't necessarily have to be a native DLL. You could start a Managed C++ .NET Control Library project which will create a .NET assembly DLL that you would be able to reference from C#. Granted the task is not trivial if you have no experience writing C/C++ but you should be able to find some examples on the web on how to wrap a .lib in a managed assembly using Managed Extentions for C++. Basically after you start the project you will have to do the follwing, in order to import the .lib: In the project settings, look for Linker Options, additional include files and add your .lib file in that list (make sure to include the fully qualified path if the file doesn't reside in the project folder or in the windows folder). The next thing to do is to use
#import "file_name.lib"
in the header for you assembly. Doing that will make the content of the .lib accesible to your project and then you'll be able to start writing the wrapper functions. You don't have to write wrappers for all the functions in the .lib; only for those that you will be using. The part that will be a little more complex will be data marshalling between the native api and the managed assembly, but there's a ton of documentation out there on how to accomplish that. Good luck!