getting IntPtr of -1

G

Guest

hi...can anyone tell me why im getting an IntPtr of -1 being returned? the
device is plugged in and being recognized by windows....so i dont understand
this. Thanks

private void GetFiles(String str)
{

IntPtr ptrHandle;
IntPtr lpData;

short shrtInLength;
short shrtOutLength;

HidCaps oCaps;

try
{

ptrHandle = CreateFile(str, GENERIC_READ | GENERIC_WRITE, 0,
IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, IntPtr.Zero);

HidD_GetPreparsedData(ptrHandle, out lpData);

HidP_GetCaps(lpData, out oCaps); // extract the device
capabilities from the internal buffer

shrtInLength = oCaps.InputReportByteLength; // get the
input...
shrtOutLength = oCaps.OutputReportByteLength; // ... and
output report lengths

//FileStream fs = new System.IO.FileStream(ptrHandle,
FileAccess.ReadWrite);

}
catch (Exception ex)
{

}
finally
{

HidD_FreePreparsedData(lpData);

}

}
 
T

Tom Shelton

iwdu15 said:
hi...can anyone tell me why im getting an IntPtr of -1 being returned? the
device is plugged in and being recognized by windows....so i dont understand
this. Thanks

private void GetFiles(String str)
{

IntPtr ptrHandle;
IntPtr lpData;

short shrtInLength;
short shrtOutLength;

HidCaps oCaps;

try
{

ptrHandle = CreateFile(str, GENERIC_READ | GENERIC_WRITE, 0,
IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, IntPtr.Zero);

HidD_GetPreparsedData(ptrHandle, out lpData);

HidP_GetCaps(lpData, out oCaps); // extract the device
capabilities from the internal buffer

shrtInLength = oCaps.InputReportByteLength; // get the
input...
shrtOutLength = oCaps.OutputReportByteLength; // ... and
output report lengths

//FileStream fs = new System.IO.FileStream(ptrHandle,
FileAccess.ReadWrite);

}
catch (Exception ex)
{

}
finally
{

HidD_FreePreparsedData(lpData);

}

}

Can you show your actual declaration for CreateFile and the constants
your passing to it?

Thanks.
 
W

Willy Denoyette [MVP]

"iwdu15" <jmmgoalsteratyahoodotcom> wrote in message
| hi...can anyone tell me why im getting an IntPtr of -1 being returned? the
| device is plugged in and being recognized by windows....so i dont
understand
| this. Thanks
|
| private void GetFiles(String str)
| {
|
| IntPtr ptrHandle;
| IntPtr lpData;
|
| short shrtInLength;
| short shrtOutLength;
|
| HidCaps oCaps;
|
| try
| {
|
| ptrHandle = CreateFile(str, GENERIC_READ | GENERIC_WRITE,
0,
| IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, IntPtr.Zero);
|
| HidD_GetPreparsedData(ptrHandle, out lpData);
|
| HidP_GetCaps(lpData, out oCaps); // extract the device
| capabilities from the internal buffer
|
| shrtInLength = oCaps.InputReportByteLength; // get the
| input...
| shrtOutLength = oCaps.OutputReportByteLength; // ... and
| output report lengths
|
| //FileStream fs = new System.IO.FileStream(ptrHandle,
| FileAccess.ReadWrite);
|
| }
| catch (Exception ex)
| {
|
| }
| finally
| {
|
| HidD_FreePreparsedData(lpData);
|
| }
|
| }
|
| --
| -iwdu15

No we can't, but you can if you call Marshal.GetLastWin32Error after the
failing API call. This will return the windows error code, provided you have
declared your DllImport correctly (mind to post the declaration also??).
Note that you should always call GetLastWin32Error for API's that return
error information after the call.

Willy.
 
G

Guest

i think i figured it out...which was a big mistake on my part. i was trying
to communicate with my MP3 player, USB Device, using HID APIs....my bad,
thanks though
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top