parker1107
New member
- Joined
- Jan 30, 2024
- Messages
- 2
- Programming Experience
- 1-3
I have a Delphi DLL(x64) that provides a method to log in to the server.
I tried to add this method in a specific SDK. (COM Visible=true,select x64 for the platform)
I set a breakpoint at MessageBox.Show and get the message that I expected.
Then, throw the exception:
Managed Debugging Assistant 'FatalExecutionEngineError': 'The runtime has encountered a fatal error. The address of the error was at 0x0a283aad, on thread 0xd774. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.'
Is it possible to confirm what caused the problem to occur?
I tried to add this method in a specific SDK. (COM Visible=true,select x64 for the platform)
Here is Delphi Code:
Function LoginLic(sFD,sVD,sINI,sCh,sSD: string) : PWideChar; stdcall;
var sysServer,sysPort,sysLN,sysCN,sysIP,sysMac,sysDN,sysFN,sysFV,sysSN,
sFile,sHost,sPort,sSN,
sTempPath : string;
myIni : TIniFile;
begin
{ example:
[Connection]
HostName = 192.168.1.187
Port = 220
}
sHost := '127.0.0.1';
sPort := '220';
sSN := 'SN109001';
sTempPath := sINI;
ForceDirectories(sTempPath);
sFile := sTempPath;
if FileExists(sFile) then
begin
myIni := TIniFile.Create(sFile);
sHost := myIni.ReadString('Connection', 'HostName', '127.0.0.1');
sPort := myIni.ReadString('Connection', 'Port', '220');
sSN := myIni.ReadString('Connection', 'SerialNo', 'SN109001');
end
else
begin
myIni := TIniFile.Create(sFile);
myIni.WriteString('Connection', 'HostName', '127.0.0.1');
myIni.WriteString('Connection', 'Port', '220');
myIni.WriteString('Connection', 'SerialNo', 'SN109001');
end;
sysServer := sHost;
sysPort := sPort;
sysDN := GetDomainName;
sysLN := GetLoginName;
sysCN := GetMyHostName;
sysIP := GetIP;
sysMac := GetMac;
sysFN := sFD;
sysFV := sVD;
sysSN := sSN;
try
Result := PWideChar(DoConnect(sysServer,sysPort,sysLN,sysCN,sysIP,sysMac,sysDN,sysFN,sysFV,sysSN,sCh,sSD));
except
Result := PWideChar('0;'+Result);
end;
Result := PWideChar(Result);
end;
Method in Main.cs:
public class EDABank
{
[DllImport(nameof(EDABank), CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.LPTStr)]
public static extern string LoginLic(string name, string version, string inipath, string checkDate, string subDate);
}
string msg = EDABank.LoginLic(name, version, ini file path, "0", "");
MessageBox.Show(msg);
I set a breakpoint at MessageBox.Show and get the message that I expected.
Then, throw the exception:
Managed Debugging Assistant 'FatalExecutionEngineError': 'The runtime has encountered a fatal error. The address of the error was at 0x0a283aad, on thread 0xd774. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.'
Is it possible to confirm what caused the problem to occur?
Last edited: