Here is the cpp code to call the dll function”
typedef void (__stdcall *Terminal)(TApplication*, TFileStream *k, HANDLE N, int D);
Here is my C# code to call the function”
[DllImport("somedll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
static extern void terminal(IntPtr Application, IntPtr FileStream, IntPtr CommHandle, int mode);
and the function call:
terminal(IntPtr.Zero, FileHandle.DangerousGetHandle(), CommHandle, 0);
if i call terminal with the Application ptr set to this.Handle i get a System.AccessViolationException was unhandled
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
You can’t create a Delphi
TApplicationfrom .net. You can’t create a DelphiTFileStreamfrom .net. This DLL appears to be inaccessible from anything other than Delphi or C++ Builder.The only way you could hope for it to work from .net would be if the DLL also exported functions that created instances of
TApplicationorTFileStream, which you could then pass on to the function in your question.The
TApplicationclass is a VCL class representing the application. It is the equivalent of the WinFormsApplicationclass. LikewiseTFileStreamis a VCL class wrapping file I/O in a stream-like interface. The .netFileStreamclass is similar. But you simply cannot synthesise working instances of Delphi/VCL classes from .net.