EDN Admin
Well-known member
Hi!
First all the usual stuff - I would categorize myself as a novice C++ programmer...so my apologies if this is in the realm of RTFM questions; and Im using Visual Studio 2008.
Im trying to write a DLL wrapper around a LIB static library (all unmanaged stuff). Specifically, Im trying to wrap the open-source libusb library (found in http://sourceforge.net/projects/libusb-win32/). The wrapper is being written for LabView
to call the libusb functions "on a higher level" - that is, my wrapper will include some high-level device functions that call the "atomic" functions found in the libusb static library. Also, note that according to the
LabView docs, they frown upon using DEF files to export the DLL functions and recommend the "declspec(dllexport)" approach (something to do with finding function prototypes with their DLL "parser" module) That being said, Im having
some troubles.... when I debug the DLL (since calling DLLs from Labview is a multi-staged process, Im using Pythons "ctypes" module to attach to the DLL and call the functions for debug purposes), I cant be sure Im really calling the underlying
functions in the static library. Im not getting any error but Im not sure if the LIB functions are "really" being called. Heres a portion of the DLL code (note in one of the *.h files: #define DECLDIR __declspec(dllexport) ):
extern "C"<br/>
{<br/>
DECLDIR int Add( int a, int b )<br/>
{<br/>
return( a + b );<br/>
}<br/>
<br/>
<br/>
DECLDIR usb_dev_handle *open_dev(void)<br/>
{<br/>
struct usb_bus *bus;<br/>
struct usb_device *dev;<br/>
bus = usb_get_busses();<br/>
for (bus; bus; bus = bus->next)<br/>
{<br/>
for (dev = bus->devices; dev; dev = dev->next)<br/>
{<br/>
if (dev->descriptor.idVendor == MY_VID<br/>
&& dev->descriptor.idProduct == MY_PID)<br/>
{<br/>
return usb_open(dev);<br/>
}<br/>
}<br/>
}<br/>
return NULL;<br/>
}<br/>
}<br/>
Now, I included the Add() function to make sure my DLL was working. And it does...that function I can call from Python ctypes and it operates correctly. However, when I set a breakpoint at the line: "bus = usb_get_busses();", bus returns
as NULL (0x00000). Ive included usb.h in my project and right-clicking on "usb_get_busses()" brings me to the line:
struct usb_bus *usb_get_busses(void);
in usb.h (which comes with the libusb.lib library)
So, my main question. How can I be sure Im linking correctly to libusb.lib which I included in Additional Dependencies in the Linker->Input section? I dont get any errors when I compile/link the DLL project, so maybe thats enough.
But, barring bringing in the whole libusb-win32 source project into Visual Studio 2008, is there any way to insure that Im really getting accessing the usb_get_busses() function in the static libusb library?
Any thoughts welcome!
Best,
Hyped
View the full article
First all the usual stuff - I would categorize myself as a novice C++ programmer...so my apologies if this is in the realm of RTFM questions; and Im using Visual Studio 2008.
Im trying to write a DLL wrapper around a LIB static library (all unmanaged stuff). Specifically, Im trying to wrap the open-source libusb library (found in http://sourceforge.net/projects/libusb-win32/). The wrapper is being written for LabView
to call the libusb functions "on a higher level" - that is, my wrapper will include some high-level device functions that call the "atomic" functions found in the libusb static library. Also, note that according to the
LabView docs, they frown upon using DEF files to export the DLL functions and recommend the "declspec(dllexport)" approach (something to do with finding function prototypes with their DLL "parser" module) That being said, Im having
some troubles.... when I debug the DLL (since calling DLLs from Labview is a multi-staged process, Im using Pythons "ctypes" module to attach to the DLL and call the functions for debug purposes), I cant be sure Im really calling the underlying
functions in the static library. Im not getting any error but Im not sure if the LIB functions are "really" being called. Heres a portion of the DLL code (note in one of the *.h files: #define DECLDIR __declspec(dllexport) ):
extern "C"<br/>
{<br/>
DECLDIR int Add( int a, int b )<br/>
{<br/>
return( a + b );<br/>
}<br/>
<br/>
<br/>
DECLDIR usb_dev_handle *open_dev(void)<br/>
{<br/>
struct usb_bus *bus;<br/>
struct usb_device *dev;<br/>
bus = usb_get_busses();<br/>
for (bus; bus; bus = bus->next)<br/>
{<br/>
for (dev = bus->devices; dev; dev = dev->next)<br/>
{<br/>
if (dev->descriptor.idVendor == MY_VID<br/>
&& dev->descriptor.idProduct == MY_PID)<br/>
{<br/>
return usb_open(dev);<br/>
}<br/>
}<br/>
}<br/>
return NULL;<br/>
}<br/>
}<br/>
Now, I included the Add() function to make sure my DLL was working. And it does...that function I can call from Python ctypes and it operates correctly. However, when I set a breakpoint at the line: "bus = usb_get_busses();", bus returns
as NULL (0x00000). Ive included usb.h in my project and right-clicking on "usb_get_busses()" brings me to the line:
struct usb_bus *usb_get_busses(void);
in usb.h (which comes with the libusb.lib library)
So, my main question. How can I be sure Im linking correctly to libusb.lib which I included in Additional Dependencies in the Linker->Input section? I dont get any errors when I compile/link the DLL project, so maybe thats enough.
But, barring bringing in the whole libusb-win32 source project into Visual Studio 2008, is there any way to insure that Im really getting accessing the usb_get_busses() function in the static libusb library?
Any thoughts welcome!
Best,
Hyped
View the full article