I have a DLL written in Delphi from where i know only his signature like:
function GeResultToStream(Param1: PChar; Param2: PChar; Param3:PChar; Param4: integer; out Param5: DWord; ParamStream: IStream; Error: PChar; ErrorSize: integer):BOOL;stdcall; external 'MYDLL.dll';
I am having some trouble calling this DLL method from C#. The method supposed to also transport some data in the ParamStream
and return true
if everything went fine.
I have tried the following(and other various changes in the DLL's method parameters) but unsuccessful(each time i was calling this function using references or out parameters i was getting errors):
public class TestDLL
{
internal class DLLInternal
{
const string _dllLocation = "MYDLL.dll";
[DllImport(_dllLocation,
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Ansi,
EntryPoint = "GeResultToStream")]
public static extern bool GeResultToStream(string Param1, string Param2, string Param3, int Param4, char[] Param5, ref Stream ParamStream, string Error, int ErrorSize);
}
public TestDLL()
{
}
~TestDLL()
{
}
public Stream GetStream(string Param1, string Param2, string Param3, int Param4, char[] Param5, string Error, int ErrorSize)
{
try
{
Stream stream = new MemoryStream();
bool x = DLLInternal.GeResultToStream(Param1, Param2, Param3, Param4, Param5, ref stream, Error, ErrorSize);
//here i think i might need to use somehow the Marshal class
return stream;
}
catch (Exception ex)
{
Console.WriteLine("Exception GetStream:" + ex.ToString());
return null;
}
}
}
My guess is that i did not understood how to translate the signature in a proper way to use it in C#. I can provide more info if needed(like the errors i got, but mostly they are corrupt memory).