VC写的接口函数:
//显示窗体
void ShowImage()
{
CShowImageDlg dlg;
dlg.DoModal(); //会执行,但是窗体不会弹出,为什么?
}Delphi调用Vc:
procedure TShowimageClass.InitLib_DLL;
Var
DLLFile : String;
begin
try
Begin
DLLFile :=ExtractFilePath(ParamStr(0))+'ShowImage.DLL';
if not FileExists(DllFile) then
begin
Application.MessageBox('动态库ShowImage.DLL丢失','信息提示',MB_ICONWARNING+MB_OK);
exit;
end;
hHandle := LoadLibrary(pchar(DLLFile));
if hHandle <> 0 then @FShowImage := GetProcAddress(hHandle,'ShowImage');
End
except
end;
end;procedure TShowimageClass.ShowImage(Str: String);
Var
m_Path : String;
begin
if Str='' then Exit;
m_Path := GetCurrentDir;
if Not FileExists(Str) then
Begin
MessageBox(Application.Handle,PChar('文件 '+Str+' 不存在!'),'系统提示',MB_OK+MB_ICONWARNING);
Exit;
End;
WriteFileName(m_Path+'\Path',PChar(Str));
FShowImage;
end;
//显示窗体
void ShowImage()
{
CShowImageDlg dlg;
dlg.DoModal(); //会执行,但是窗体不会弹出,为什么?
}Delphi调用Vc:
procedure TShowimageClass.InitLib_DLL;
Var
DLLFile : String;
begin
try
Begin
DLLFile :=ExtractFilePath(ParamStr(0))+'ShowImage.DLL';
if not FileExists(DllFile) then
begin
Application.MessageBox('动态库ShowImage.DLL丢失','信息提示',MB_ICONWARNING+MB_OK);
exit;
end;
hHandle := LoadLibrary(pchar(DLLFile));
if hHandle <> 0 then @FShowImage := GetProcAddress(hHandle,'ShowImage');
End
except
end;
end;procedure TShowimageClass.ShowImage(Str: String);
Var
m_Path : String;
begin
if Str='' then Exit;
m_Path := GetCurrentDir;
if Not FileExists(Str) then
Begin
MessageBox(Application.Handle,PChar('文件 '+Str+' 不存在!'),'系统提示',MB_OK+MB_ICONWARNING);
Exit;
End;
WriteFileName(m_Path+'\Path',PChar(Str));
FShowImage;
end;
...@一个数字。这个数字的大小就是动态库的出入参的字节数大小。
我建议还是参考Delphi上的帮助吧。
上面有例子。
extern "C" BOOL PASCAL EXPORT ExportedFunction()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// normal function body here
}
#ifdef EXPORT
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __declspec(dllimport)
#endif
好歹才能跑起来呀