all groups > visual studio .net debugging > september 2004 >
You're in the

visual studio .net debugging

group:

ERROR: Object Reference Not Set to an Instance of an Object


ERROR: Object Reference Not Set to an Instance of an Object Michael Chong
9/14/2004 4:19:36 PM
visual studio .net debugging:
I have an (exe) executable program created in VB.NET 2003 that calls to a
MFC DLL written in VC++.NET 2003. I always get an error msg
"NullReferenceException: Object Reference Not Set to an Instance of an
Object" when my exe calls the following codes:

in VB.NET

Declare Function test Lib "C:\Cyob\IOComm\Debug\IOComm.dll" _
(ByVal a As Long, ByRef b As Integer) As Integer

Dim did As Integer
Dim ret As Integer

ret = test(PortHnd, did) //ERROR: Object Reference Not Set to an
Instance of an Object


in VC++.NET

extern "C" int APIENTRY test(HANDLE a, int *b)
{
*b=55; //ERROR: Object Reference Not Set to an Instance of an
Object
return 99;
}


Why is this happening? Any idea in solving such matter?
Thanks in Advance

Michael.

RE: ERROR: Object Reference Not Set to an Instance of an Object Matthew Reiter
9/15/2004 7:21:05 PM
The sizes of integers in Visual Basic are not the same as in C++. "Integer"
in VB corresponds to "long" in C++, and "Short" in VB corresponds to "int" in
C++. To solve the problem, replace the function declaration in VB with:
Declare Function test Lib "C:\Cyob\IOComm\Debug\IOComm.dll" (ByVal a As
IntPtr, ByRef b As Short) As Short
I specified an IntPtr instead of an Integer so that it will be an Integer on
32-bit computers and a Long on 64-bit computers.
I hope this helps.

[quoted text, click to view]
AddThis Social Bookmark Button