U
Ulrika Ziverts
Hello!
I have a .NET application that communicates with an AS400 application
through PCOM. I call an unmanaged function in the PCOM API to get a
string back representing the screen in the host system. When I call
this function from VB.NET it works fine but from C# I only get a
string containing unreadable characters back. If anyone knows what's
wrong I'd be very happy!
VB.NET code that works:
Private Declare Function hllapi Lib "PCSHLL32.DLL" (ByRef Func As
Integer, ByVal DataString As String, ByRef Length As Integer, ByRef
RetC As Integer) As Integer
Dim testStr As New String(" ", 8000)
ret = hllapi(COPY_PRESENTATION_SPACE, testStr, HllLength,
HllReturnCode)
ResponseBuffer = testStr
testStr is the variable that contains the string I am interested in.
C# code that does not work:
[DllImport("pcshll32.dll",EntryPoint="hllapi",ExactSpelling=false,CharSet=CharSet.Auto,SetLastError=true)]
public static extern int hllapi(ref int Func,
[MarshalAs(UnmanagedType.LPWStr)] string DataString, ref int Length,
ref int RetC);
string hllData = new string(' ', 8000);
int hllLength;
int hllReturnCode;
int ret;
hllLength = 0;
hllReturnCode = 0;
ret = hllapi(ref COPY_PRESENTATION_SPACE, hllData, ref hllLength, ref
hllReturnCode);
responseBuffer = hllData;
hllData either contains nothing or unreadable characters depending on
how I write DllImport. I have tried the following alternatives as
well:
[DllImport("pcshll32.dll",EntryPoint="hllapi",ExactSpelling=false,CharSet=CharSet.Unicode,SetLastError=true)]
public static extern int hllapi(ref int Func,
[MarshalAs(UnmanagedType.LPWStr)] string DataString, ref int Length,
ref int RetC);
[DllImport("pcshll32.dll",EntryPoint="hllapi",ExactSpelling=false,CharSet=CharSet.Unicode,SetLastError=true)]
public static extern int hllapi(ref int Func, string DataString, ref
int Length, ref int RetC);
Regards
Ulrika
I have a .NET application that communicates with an AS400 application
through PCOM. I call an unmanaged function in the PCOM API to get a
string back representing the screen in the host system. When I call
this function from VB.NET it works fine but from C# I only get a
string containing unreadable characters back. If anyone knows what's
wrong I'd be very happy!
VB.NET code that works:
Private Declare Function hllapi Lib "PCSHLL32.DLL" (ByRef Func As
Integer, ByVal DataString As String, ByRef Length As Integer, ByRef
RetC As Integer) As Integer
Dim testStr As New String(" ", 8000)
ret = hllapi(COPY_PRESENTATION_SPACE, testStr, HllLength,
HllReturnCode)
ResponseBuffer = testStr
testStr is the variable that contains the string I am interested in.
C# code that does not work:
[DllImport("pcshll32.dll",EntryPoint="hllapi",ExactSpelling=false,CharSet=CharSet.Auto,SetLastError=true)]
public static extern int hllapi(ref int Func,
[MarshalAs(UnmanagedType.LPWStr)] string DataString, ref int Length,
ref int RetC);
string hllData = new string(' ', 8000);
int hllLength;
int hllReturnCode;
int ret;
hllLength = 0;
hllReturnCode = 0;
ret = hllapi(ref COPY_PRESENTATION_SPACE, hllData, ref hllLength, ref
hllReturnCode);
responseBuffer = hllData;
hllData either contains nothing or unreadable characters depending on
how I write DllImport. I have tried the following alternatives as
well:
[DllImport("pcshll32.dll",EntryPoint="hllapi",ExactSpelling=false,CharSet=CharSet.Unicode,SetLastError=true)]
public static extern int hllapi(ref int Func,
[MarshalAs(UnmanagedType.LPWStr)] string DataString, ref int Length,
ref int RetC);
[DllImport("pcshll32.dll",EntryPoint="hllapi",ExactSpelling=false,CharSet=CharSet.Unicode,SetLastError=true)]
public static extern int hllapi(ref int Func, string DataString, ref
int Length, ref int RetC);
Regards
Ulrika