System.NullRefernceException Error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to use a DLL in my C# application.

The code that I have is:
..
..
..
[DllImport("atfuncs.dll")]
public static extern int AT_Device_Get_Status(int DeviceNumber);
..
..
..
serial = AT_Device_Get_Status(1);
It is at this point in the code that the following message appears on the
screnn:
Microsoft Development Environment
! An unhandled exception of type 'System.NullReferenceException' occurred in
Vaprel.exe

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

I don't know what I am doing wrong. I hope that someone in this group can
tell me what is wrong with my application.

John Vogel (lost in C# land)
 
I am trying to use a DLL in my C# application.

The code that I have is:
.
.
.
[DllImport("atfuncs.dll")]
public static extern int AT_Device_Get_Status(int DeviceNumber);
.
.
.
serial = AT_Device_Get_Status(1);
It is at this point in the code that the following message
appears on the screnn:
Microsoft Development Environment
! An unhandled exception of type 'System.NullReferenceException'
occurred in Vaprel.exe

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

I don't know what I am doing wrong. I hope that someone in this
group can tell me what is wrong with my application.

John,

There are several possibilities to check:

- The DLL routine has a bug in it. Test the routine in the same
language as it was written in. For example, if the DLL was compiled
with C++, write a small C++ application to test the routine.

- The DLL was compiled in a language like C++ that performs "name
mangling" on the routine name. If this happens, the .Net P/Invoke
system won't be able to find AT_Device_Get_Status in the DLL. To
determine if this is the case, use a command line utility like
Microsoft's DUMPBIN or Borland's TDUMP to find out exactly what
method names are being exported from the DLL.

- Specify the CharSet and EntryPoint parameters in the DllImport
attribute:

[DllImport("atfuncs.dll", CharSet = CharSet.Auto,
EntryPoint = "AT_Device_Get_Status")]

See this link for more info:

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpguide/html/cpconconsumingunmanageddllfunctions.asp

or

http://tinyurl.com/jc41
 
Back
Top