lnk 2028 and winusb

Hi
I'm a hardware designer attempting to use Visual C++ 2008 for the first time. I have modified some example code from Microchip that uses the winusb dll. I can write to my device but when attempting to read the programme hangs. I suspect that this is because the code is blocking and the timeout period is set to 0 (no timeout). When I attempt to set up the timeout using WinUsb_SetPipePolicy I get the lnk 2028 error, I have read that this is caused by not including libraries but my other code that uses this dll works. The problem code (from the cpp file) is reproduced below:

1
2
3
4
5
6
7
8
9
10
11
12
ErrorStatus = GetLastError();
				if(ErrorStatus == ERROR_SUCCESS)
				{
					//Now get the WinUSB interface handle by calling WinUsb_Initialize() and providing the device handle.
					USBOpen = WinUsb_Initialize(MyDeviceHandle, &MyWinUSBInterfaceHandle);

					//set the timeout to 1mS
					ReadTimeOut=1;
					ReadTimeOutPtr = &ReadTimeOut;
					WinUsb_SetPipePolicy(MyWinUSBInterfaceHandle, 1, 3, 1, ReadTimeOutPtr);		
					//
				}


If I comment out the SetPipe stuff it links OK,if I mouse over WinUsb_SetPipePolicy then the compiler shows the description OK too. The DLL includes are contained in my header as shown below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//WinUsb_Initialize() needs to be called before the application can begin sending/receiving data with the USB device.
	[DllImport("winusb.dll" , CharSet = CharSet::Seeifdef, EntryPoint="WinUsb_Initialize")]
	extern "C" BOOL WinUsb_Initialize(
		HANDLE	DeviceHandle,
		PWINUSB_INTERFACE_HANDLE InterfaceHandle);

	//WinUsb_WritePipe() is the basic function used to write data to the USB device (sends data to OUT endpoints on the device)
	[DllImport("winusb.dll" , CharSet = CharSet::Seeifdef, EntryPoint="WinUsb_WritePipe")]
	extern "C" BOOL WinUsb_WritePipe(
		WINUSB_INTERFACE_HANDLE InterfaceHandle,
		UCHAR PipeID,
		PUCHAR Buffer,
		ULONG BufferLength,
		PULONG LengthTransferred,
		LPOVERLAPPED Overlapped);

	//WinUsb_ReadPipe() is the basic function used to read data from the USB device (polls for and obtains data from
	//IN endpoints on the device)
	[DllImport("winusb.dll" , CharSet = CharSet::Seeifdef, EntryPoint="WinUsb_ReadPipe")]
	extern "C" BOOL WinUsb_ReadPipe(
		WINUSB_INTERFACE_HANDLE InterfaceHandle,
		UCHAR PipeID,
		PUCHAR Buffer,
		ULONG BufferLength,
		PULONG LengthTransferred,
		LPOVERLAPPED Overlapped);


Can anyone help me with this please?
If SetPipe appears in your header files, then the compiler can compiler the file and Intellisense can show you the prototype.

If you're using the wrong .lib file, you'll get a linker error.

But ulitmately, the code you want is in the dll. You can check the exported functions in the dll by loading it into depends. Depends ships with the Platform SDK or you can download it from http://dependencywalker.com/

If you have the right DLL but a bad LIB, you can load the DLL yourself (using LoadLibrary) and get the function yourself (using GetProcAddress).

If you have a cleanly installed system, you shouldn't be getting this sort of error. It only happens when files are copied onto the system.
I'm such an idiot sometimes, I spent a day looking at that and didn't see that setpipepolicy and getpipepolicy weren't in the (copied) header. I just realised reading back what I posted that those aren't the right includes.
I tried that link Trend blocks it with the message:

Threat details:
Verified fraud page or threat source.


I've seen something similar so back to Google.
Thanks
James
It's strange that the depends website is often blocked. You probably should install the Platform SDK as a rule anyway. You'll find it in there.
That seems to have fixed that but my original problem remains. In the original demo one byte of data was sent and then a read was performed. In my modified version I am attempting reading on a timer tick but the code hangs when I attempt a read. On most reads there will be no data present.

1
2
3
4
5
6
7
8
9
10
11
12
ULONG USBHandler::USBHandler::GetData(unsigned char* InBuffer, unsigned char PIPEID) 
{

		 ULONG BytesRead = 0;
		 		 
		 PIPEID = PIPEID | 0x80;				//Input bytes have MSB = 1

		 //The following call to WinUsb_ReadPipe() retrieves 64 bytes of data from the USB device.
		 WinUsb_ReadPipe(MyWinUSBInterfaceHandle, PIPEID, InBuffer, 64, &BytesRead, NULL);  

		 return BytesRead;
}


The handle looks OK, PIPEID is 0x81, The MSDN documentation states that the default setting for the pipe is no timeout, that sounds like it would stay here if no timeout was defined and no data was received. I have changed this to 1ms
Thanks
James
Topic archived. No new replies allowed.