library HealthDocDll;uses
SysUtils,
Classes,
Forms,
Dialogs,
Windows,
HealthDoc in 'HealthDoc.pas' {frmHealthDoc},
pub in 'pub.pas';{$R *.res}
procedure ShowForm(DoctorName,UserName:string);stdcall;
begin
sDoctorName:=DoctorName;
sUserName:=UserName;
showmessage(sdoctorname);
showmessage(susername);
end;exports
ShowForm;beginend.HINSTANCE hDll;
hDll=LoadLibrary( _T("HealthDocDLL.DLL") );
typedef int(_stdcall *func)(const char*,const char*); func SmartWord= (func)GetProcAddress( hDll , "ShowForm" );
SmartWord( "aaaaaa" , "b" );
VC调用DELPHI DLL失败,我想用GETLASTERROR 来获得错误原因,如何使用
VC新手,最好能详细些,谢谢
SysUtils,
Classes,
Forms,
Dialogs,
Windows,
HealthDoc in 'HealthDoc.pas' {frmHealthDoc},
pub in 'pub.pas';{$R *.res}
procedure ShowForm(DoctorName,UserName:string);stdcall;
begin
sDoctorName:=DoctorName;
sUserName:=UserName;
showmessage(sdoctorname);
showmessage(susername);
end;exports
ShowForm;beginend.HINSTANCE hDll;
hDll=LoadLibrary( _T("HealthDocDLL.DLL") );
typedef int(_stdcall *func)(const char*,const char*); func SmartWord= (func)GetProcAddress( hDll , "ShowForm" );
SmartWord( "aaaaaa" , "b" );
VC调用DELPHI DLL失败,我想用GETLASTERROR 来获得错误原因,如何使用
VC新手,最好能详细些,谢谢
从你给的代码看,如果你调用SmartWord失败,而SmartWord内又没有设置错误信息的话,你将什么也得不到
这句,根本就没有加载成功的
#include <windows.h>
#include <strsafe.h>void ErrorExit(LPTSTR lpszFunction)
{
// Retrieve the system error message for the last-error code LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError(); FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL ); // Display the error message and exit the process lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf)+lstrlen((LPCTSTR)lpszFunction)+40)*sizeof(TCHAR));
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf),
TEXT("%s failed with error %d: %s"),
lpszFunction, dw, lpMsgBuf);
MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
ExitProcess(dw);
}void main()
{
// Generate an error if(!GetProcessId(NULL))
ErrorExit(TEXT("GetProcessId"));
}
GetLastError
看看返回值是多少
什么也没返回
然后查返回值看看是什么错误
如果没返回错误那就没办法了
DWORD dwRet = GetLastError();
CString strText(_T(""));
strText.Format(_T("%d"), dwRet);
AfxMessageBox(strText);