473,505 Members | 15,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting IntPtr of -1

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
Nov 16 '06 #1
3 2064

iwdu15 wrote:
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
Can you show your actual declaration for CreateFile and the constants
your passing to it?

Thanks.

--
Tom Shelton

Nov 16 '06 #2

"iwdu15" <jmmgoalsteratyahoodotcomwrote in message
news:99**********************************@microsof t.com...
| 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.
Nov 16 '06 #3
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
--
-iwdu15
Nov 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1879
by: Jacek | last post by:
Hi If it is wrong newsgroup, please let me know where to find the answer. I am trying to get item text form ListView (there are few items and 5 columns) from other application (application written...
5
4645
by: Tedmond | last post by:
Dear all, How can I get all the titles of all openning windows? I found a API in win32 that called EnumWindows() but it returns only the windows handles, not titles. How can I get the list just...
6
5931
by: Roohi | last post by:
hi I am trying to copy an image to a clipboard and then get a handle to the clipboard using API calls GetClipboardData(). Following is the snippet of our code. Could any one please point out...
5
13438
by: Rik Hemsley | last post by:
How does one go about getting a pointer to method as an IntPtr? Example: public class A { public void X() { Y(Z); }
1
11846
by: Bruce Wood | last post by:
I'm having a devil of a time calling DeviceCapabilities() in order to get the list of paper names / codes / sizes for a printer. Here is my code and the input it produces: static extern Int32...
2
6307
by: pangel83 | last post by:
I've been trying for days to write a piece of VB.NET code that will read from winamp's memory space the paths of the files from the current winamp playlist. The GETPLAYLISTFILE command of the...
7
3500
by: Nathan Sokalski | last post by:
I would like to be able to get the ContentType of a file programmatically (for example, I want *.txt files to return "text/plain"). I could not find a way to do this using VB.NET's classes, but I...
13
9067
by: Mark Rae | last post by:
Hi, I have used the code below to return the default printer in 32-bit WinXP Pro, but now that I am running 64-bit Vista Business I'm getting an error: using System.Drawing.Printing; using...
5
7516
by: Sin Jeong-hun | last post by:
Hello. Speical folders, like Desktop, usually have different display names. For example, in Japanese Windows, it's displayed as "$B%G%9%/%H%C%W(B". I want to get the this displayed name of a...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.