I need to call a 'classic' DLL C# (not COM) from Powerbuilder. The creation of the DLL in C# I based on this example: RGiesecke dll Export template.
And I managed to call the DLL from within Powerbuilder.
BUT I want to pass the string 'as reference': so I added 'ref' to the function declaration:
[DllExport("ExpTest", CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public static string ExpTest([MarshalAs(UnmanagedType.LPWStr)] ref string sText, out int length)
{
MessageBox.Show(sText, "ExpTest");
length = sText.Length;
//sText = "def";
return sText;
}
The code from Powerbuilder calling this function:
String ls_arg, ls_ret
ls_arg = "abc"
long ll_len
ls_ret = ExpTest(ls_arg, ll_len)
messagebox(ls_arg, ls_ret)
When calling the original functio (without 'ref' to the 'string sTest' declaration), it returns "abc". When I add 'ref' to the 'string sTest' declaration, it returns some 'chinese characters').
Can anyone help? Even better: how to pass an array of strings (by ref) from and to Powerbuilder?
Thanks for your help!!
Msc.
Tried to define the External functions in Powerbuilder like this:
- FUNCTION String ExpTest(REF String value, REF long len) LIBRARY "Classicdll.dll"
- FUNCTION String ExpTest(String value, REF long len) LIBRARY "Classicdll.dll"
- and both with ALIAS FOR "ExpTest;Ansi"...