473,324 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Object reference problem

I've got a very strange error.
I get an error message:
"Object reference not set to an instance of an object",
which I've seen many times before, for good reason. But
this time, I cannot find fault with my code.

Here's my function call:
eError = CUCanApi.eUCanGetBootFirmwareInfo( hDevice, out
fw, 1000 );

The problem appears to be with the argument hDevice,
which is an IntPtr type. I set it with another function
called hDUT(), which returns an IntPtr type.

If I check hDevice just before the call of
eUCanGetBootFirmwareInfo, it appears to have a valid
value.

If I replace the hDevice argument with "(IntPtr)0", then
the error message goes away, indicating that I've
resolved the object reference issue.
Any ideas on what the problem is?

Nov 16 '05 #1
4 1106
db_from_mn wrote:
I've got a very strange error.
I get an error message:
"Object reference not set to an instance of an object",
which I've seen many times before, for good reason. But
this time, I cannot find fault with my code.

Here's my function call:
eError = CUCanApi.eUCanGetBootFirmwareInfo( hDevice, out
fw, 1000 );

The problem appears to be with the argument hDevice,
which is an IntPtr type. I set it with another function
called hDUT(), which returns an IntPtr type.

If I check hDevice just before the call of
eUCanGetBootFirmwareInfo, it appears to have a valid
value.

If I replace the hDevice argument with "(IntPtr)0", then
the error message goes away, indicating that I've
resolved the object reference issue.
Any ideas on what the problem is?


Hi db_from_mn!

Just an idea... have you yet tried to get the integer value of hDevice
and cast it to IntPtr when calling the function? Just like this:

eError = CUCanApi.eUCanGetBootFirmwareInfo( (IntPtr) intValueOfhDevice,
out fw, 1000 );

Best regards,

Michael

--
How to contact me
~~~~~~~~~~~~~~~~~
directly via mail: remove the "NOTUSEABLE" and the point after it and
reverse the characters
via my portal: go to
http://great.dynu.com/tools/contact....=de&ref=usenet
Nov 16 '05 #2
Hello Michael,
Yes, I've tried all kinds of different casts with no success.

Dennis

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

"db_from_mn" <db****@rtessentials.com> wrote in message
news:12****************************@phx.gbl...
If I check hDevice just before the call of
eUCanGetBootFirmwareInfo, it appears to have a valid
value.

If I replace the hDevice argument with "(IntPtr)0", then
the error message goes away...


hDevice is not a valid pointer/handle ... could it be an error value rather
than a pointer? or could something have happened since setting hDevice such
that the hDevice object gets freed/released? If you set hDevice immediately
before the uCanGetBootFirmwareInfo call is there still a problem?

Brad Williams
Nov 16 '05 #4
Hello Brad,

Thanks for the attention.
I have isolated this problem, and learned quite a bit in the process!
The function call was to unmanaged code, implemented in a dll. I had
assumed that the exception was being thrown by the .NET framework,
complaining about the IntPtr parameter passed to the function. What was
really happening, was that deep in the unmanaged code, I had a pointer
error: I was trying to access a member of a data object with a pointer
that had not yet been assigned a value.
I learned two things:
1. Exceptions can be propogated up from unmanaged code to managed code.
2. How to debug across the managed-unmanaged boundary.
Thanks for the help,
Best Regards,
Dennis

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

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

Similar topics

2
by: Pkpatel | last post by:
Hi, I keep getting this error every time I try to load crystalreportviewer on a webform with a dataset. Here is the error: -------------------------------------------------------- Server...
7
by: Nick Zdunic | last post by:
I have a remotable object running in my host application. The host starts up and creates the object. Within a method to start the remote object doing its thing it creates an object. ...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
6
by: blash | last post by:
Can someone help me? I really don't have a clue. My company staff told me they often got such error: "Object reference not set to an instance of an object." when they are in search result page...
4
by: Arapi | last post by:
I am having a very strange problem with my asp.net application. I am getting error: 'Object reference not set to an instance of an object' when I run my app from my hosting company. I have...
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.