Click to See Complete Forum and Search --> : Windows API error


parireddy
August 21st, 2002, 12:29 PM
Hi,

I am getting the following error when trying to call a Windows API function from Visual Basic.NET

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication5.exe

Additional information: Object reference not set to an instance of an object.


The code that I wrote is :

Declare Function RFVB_New Lib "RF2VB.DLL" (ByVal lObjectType As Long, ByVal pObject As Long) As Long


Dim lerror As Long
Dim lFI10Obj As Long
Public Const RFO_FAXINFO_10 = &H10000

lerror = RFVB_New(RFO_FAXINFO_10, lFI10Obj)


The error is occuring on the last line.

Please suggest the cause of the error.

Thanks
:o

DSJ
August 21st, 2002, 12:50 PM
Remeber that was used to be a LONG in vb6 is now an INTEGER in .NET. Change your delcares and vars and I think it'll work.

parireddy
August 21st, 2002, 12:57 PM
I tried changing the data type into integer but I am still getting the same error.

According to the API documentation
pObject is a Long variable into which the handle of the new object will be set.

I don't know if this is causing the error. If so, do you know how I can avoid it.

Thanks

parireddy
August 21st, 2002, 03:10 PM
I solved the problem at last. After browsing the internet for hours, I found out that I need to use ByRef instead of ByVal for the second parameter in the API function as the second parameter is an Object Handle that is returned by the function.