|Online Development Notebook > Index > Programming Overview > MSVC++ Example|
MSVC++ Example using USBm.dll
This example uses MSVC++ to interface to the U4x1. The very minimum application would be to open the USB device and transmit a single command. This example shows the code that it takes to use USBm.dll to open the U401⁄U421 device and initialize the ports.
VC++ Dynamic Loading
using namespace std;
HINSTANCE hDll = 0;
typedef int (__stdcall *USBm_FindDevices_type) ();
typedef int (__stdcall *USBm_DeviceVID_type) (unsigned char device);
typedef int (__stdcall *USBm_DevicePID_type) (unsigned char device);
typedef int (__stdcall *USBm_DeviceDID_type) (unsigned char device);
typedef int (__stdcall *USBm_DirectionA_type) (unsigned char device, int);
typedef int (__stdcall *USBm_WriteA_type) (unsigned char device, int);
USBm_WDirection A_type USBm_DirectionA;
This is the type definition setup for dynamic DLL loading.
The main function makes use of the "LoadLibrary()" call to gain access to the DLL.
hDll = LoadLibrary("USBm.dll");
USBm_FindDevices = (USBm_FindDevices_type)GetProcAddress(hDll, "USBm_FindDevices");
USBm_DeviceVID = (USBm_DeviceVID_type)GetProcAddress(hDll, "USBm_DeviceVID");
USBm_DevicePID = (USBm_DevicePID_type)GetProcAddress(hDll, "USBm_DevicePID");
USBm_DeviceDID = (USBm_DeviceDID_type)GetProcAddress(hDll, "USBm_DeviceDID");
USBm_DirectionA = (USBm_DirectionA_type)GetProcAddress(hDll, "USBm_DirectionA");
USBm_WriteA = (USBm_WriteA_type)GetProcAddress(hDll, "USBm_WriteA");
result = USBm_FindDevices();
cout << "USBm_DeviceVID(0) = " << USBm_DeviceVID(0) << endl;
cout << "USBm_DevicePID(0) = " << USBm_DevicePID(0) << endl;
cout << "USBm_DeviceDID(0) = " << USBm_DeviceDID(0) << endl;
USBm_DirectionA(0, 0xFF, 0xFF);
|Hardware: U401 USB Interface U421 USB Interface U451 USB Interface|
Programming: USBm DLL Programming Download Files
Application Notes: U4x1 Application Notes Misc Applications and Information FAQ
While every effort has been made to make sure that the information posted on this site is correct, the author can not be held liable for any damages whatsoever for losses as a result of the application of this information. Use this information at your own risk.
USBmicro can design your custom and semi-custom USB product. Email about USB design can be directed to " Robert " at usbmicro.com.
Copyright © USBmicro, L.L.C., 2002-2010