How to create a C++ wrapper DLL to expose functions from a C++ .lib and .h (header) file?
Posted on 2007-08-03
A hardware manufacturer has provided me with a .lib and header file to allow me to directly access some functions provided by their drivers. I have very limited C++ experience and have the bulk of a program I was going to use to control the driver written in VB.NET. I know that I cannot access the .lib file directly from VB.NET. I have to write a DLL in C++ to wrap the functions, constants, and structures that are exposed by the .lib file to make them available to a .NET application.
Again, I'm a real newbie with C++. I have found a couple of posts on how to this but not a set by step how to. I have gotten as far as the following steps:
- I Created a new Win32 C++ Project.
- Entered a Project name and in the new App Wizard popup, selected:
* Application type: DLL
* Additional options: Export symbols
- Clicked on Finish.
I know this isn't much. I know I have to link to the header file and the .lib file somehow. Then write functions to expose the .lib functions. Ideally I would like to expose the constants and structure that are detailed in the header file as well. I would like the new wrapper DLL to be reference as a COM object in VB.NET so that I can take advantage of intellisense and not have to worry about creating correct DllImport functions.
Please provide code example for the functions, constants, and structures. I can provide example functions, constants, and structures from the header file if it helps.