C的源程序如下:
/*-------------- test.h -------------------*/
#include <windows.h>
#define EXPORT extern "C" __declspec (dllexport)
EXPORT int testfunc(int i);
/*-------------- test.c -------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <windows.h>
#include "test.h"
int testfunc(int i)
{
return ++i;
}
DELPHI的源程序如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function testfunc(i:integer):integer;external 'test6.DLL';
procedure TForm1.Button1Click(Sender: TObject);
var k,kk,i:integer;
begin
kk:=99;
k:=testfunc(kk);
label1.Caption:=inttostr(k);
end;
end.
执行程序时,无论kk为什么值,label1总显示“6813441”这个数,真不知道怎么办。