求助:我的 DLL ,在 delphi 中调用有错啊
TEST3
test3.h
#ifdef SENDCARD_EXPORTS
#define SENDCARD_API extern "C" __declspec(dllexport)
#else
#define SENDCARD_API extern "C" __declspec(dllimport)
#endif
#define ON 1
#define OFF 0
#define OK 0
#define FAIL 1
#define DATA 0
#define BufferSize 50
#define MCR1 4
#define MSR 6
#define LSR1 5
#define B0 0x01
#define B7 0x80
#define OFF 0
#define SPACE ' '
#define TRUE 1
#define FALSE 0
extern "C" _declspec(dllexport) int sum(int a,int b);//
test3.cpp
#include "stdafx.h"
#include "math.h"
#include "test3.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
extern "C" _declspec(dllexport) int sum(int a, int b)
{
return a+b;
}
编译生成了 test3.dll
我在 delphi 里:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
Function sum(i:integer; j:integer):integer;stdcall; //
implementation
Function sum(i:integer; j:integer):integer;external 'test3.dll'; //
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
m : integer;
begin
m := sum(20,30);
edit1.Text := inttostr(m);
end;
end.
可是按 Button1 出现内存地址错误
是不是
extern "C" _declspec(dllexport) int sum(int a,int b);//
应该改为
extern "C" _stdcall int sum(int a,int b);//
啊
如果是这样的话
#ifdef SENDCARD_EXPORTS
#define SENDCARD_API extern "C" __declspec(dllexport)
#else
#define SENDCARD_API extern "C" __declspec(dllimport)
#endif
应该改为什么呢?
谢谢!
我把
extern "C" _declspec(dllexport) int sum(int a, int b)
改为了 extern "C" int _stdcall sum(int a, int b)
也不行