Hello,
I'm trying to convert a VB.Net app into C#. The VB app calls functions
in an unmanaged DLL. I'm able to call most of the functions in the DLL
from C# with the exception of the one below:
in VB.Net, the unmanaged function is declared through an interop as:
Public Overridable Function LocGetName(ByVa l pLoc As Integer, ByVal
pLocNum As Integer, ByVal pType As LOCOLELib.tLocN ameType, ByVal
pFullName As Boolean, ByRef pName As String, ByVal pMaxSize As Integer)
As String
and I've declared it in C# like:
[DllImport("Loca tion.dll")]
static extern string LocGetName(int location, int locationNumber,
locationNameTyp e locationNameTyp e, bool fullName, ref string name, int
maxSize);
when I run the following statement in VB.Net, it works fine:
LocOle.LocGetNa me(llLocations, llLocIndex,
LOCOLELib.tLocN ameType.eLocNam eState, True, lsStateName.Val ue,
LOCOLELib.tLocO leConstants.eLO C_NAME_STATE_LE N)
but when I run the following statement in C#, I get 'Object reference
not set to an instance of an object':
LocGetName(loca tions, i, locationNameTyp e.state, true, ref stateString,
MAX_STATE_LENGT H);
Every parameter sent is an integer with the exception of the 'true',
and the statestring. I've tried initializing the stateString to some
text, I've tried changing the parameter type to 'out', and pass by
value, to no avail. I've even tried declaring my stateString with a
marshaling attribute:
[MarshalAs(Unman agedType.ByValT Str, SizeConst=MAX_S TATE_LENGTH)]
string stateString = "";
and that didn't work. I also tried declaring stateString as a
StringBuilder object (changing the function parameter types
accordingly) and that didn't work. Is there anything else I'm missing?
thanks,
Sean
I'm trying to convert a VB.Net app into C#. The VB app calls functions
in an unmanaged DLL. I'm able to call most of the functions in the DLL
from C# with the exception of the one below:
in VB.Net, the unmanaged function is declared through an interop as:
Public Overridable Function LocGetName(ByVa l pLoc As Integer, ByVal
pLocNum As Integer, ByVal pType As LOCOLELib.tLocN ameType, ByVal
pFullName As Boolean, ByRef pName As String, ByVal pMaxSize As Integer)
As String
and I've declared it in C# like:
[DllImport("Loca tion.dll")]
static extern string LocGetName(int location, int locationNumber,
locationNameTyp e locationNameTyp e, bool fullName, ref string name, int
maxSize);
when I run the following statement in VB.Net, it works fine:
LocOle.LocGetNa me(llLocations, llLocIndex,
LOCOLELib.tLocN ameType.eLocNam eState, True, lsStateName.Val ue,
LOCOLELib.tLocO leConstants.eLO C_NAME_STATE_LE N)
but when I run the following statement in C#, I get 'Object reference
not set to an instance of an object':
LocGetName(loca tions, i, locationNameTyp e.state, true, ref stateString,
MAX_STATE_LENGT H);
Every parameter sent is an integer with the exception of the 'true',
and the statestring. I've tried initializing the stateString to some
text, I've tried changing the parameter type to 'out', and pass by
value, to no avail. I've even tried declaring my stateString with a
marshaling attribute:
[MarshalAs(Unman agedType.ByValT Str, SizeConst=MAX_S TATE_LENGTH)]
string stateString = "";
and that didn't work. I also tried declaring stateString as a
StringBuilder object (changing the function parameter types
accordingly) and that didn't work. Is there anything else I'm missing?
thanks,
Sean
Comment