困惑!我用C++ BIULDER写了一个DLL库,然后用DELPHI调用,函数能被正确调用,但是关闭用DELPHI写的程序,就会出现错误,不解?(50分)

  • 主题发起人 主题发起人 李逍遥_神仙居
  • 开始时间 开始时间

李逍遥_神仙居

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,另外我写的很简单的,代码如下
c++ BUILDER代码
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
//---------------------------------------------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, youdo
not need to
// explicitly add MEMMGR.LIB as this will bedo
ne implicitly for you
//---------------------------------------------------------------------------
#pragma argsused
extern "C" __declspec(dllexport) int __stdcall test();
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
return 1;
}
int __stdcall test()
{
return 3;
}
//---------------------------------------------------------------------------
DELPHI代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
function test():Integer;stdcall;external 'Project2.dll';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(inttostr(test()));
end;

end.
 
救救我阿!
 
没事啊!我运行了很好。
 
不会吧,我怎么不行阿,你是不是在编译C++的时候有什么特殊的选项
 
应该是delphi用完之后没释放
 
接受答案了.
 

Similar threads

后退
顶部