Hi Guys,
I need to interact with some old Delphi DLLs.
Unfortunately they use the Delphi shortstring variable.
Im having trouble accessing the DLL functions, Im trying to pass in a string parameter when the function requires a Delphi shortstring variable.
I found a reply online which suggested using a struct to create the shortstring variable in c#
http://stackoverflow.com/questions/30569111/how-can-i-marshal-a-delphi-short-string-using-p-invoke
I've pasted in the unsafe struct DelphiShortString struct to my code, but Im now having trouble passing the string to the struct.
DelphiShortString variablename;
How to I pass a string to variablename?
Thanks for your help.
Donald CPosted May 19, 2016, 5:35 AM
Hi Bhuvanesh,
Thanks for the reply.
I have tried using StdCall
[DllImport("Systir.dll", EntryPoint = "SystirFunction2", CallingConvention = CallingConvention.StdCall)]
public static extern string SystirFunction2(Int64 SiteHash, int Users, string AuthKey);
When calling the procedure using the following code:
string SF2 = SystirFunction2(SK, Users, AuthKey);
I get a "PInvokeStackImbalance occurred" error.
The data Im passing in is identical, the only difference I see is that Im using strings rather than the shortstrings that Delphi used.
How do I go about passing a string to the struct?
PS: What tags do you use when you want to display code? That looks far more readable than copying and pasting.
Thanks again for your reply.
Bhuvanesh MohankumarPosted May 19, 2016, 3:56 AM
Have you tried using "Convention"
Reference: