调用C语言动态链接库遇到问题?请帮忙看看
implementation
  function PrepareModify(answerfilename:pchar;TotalMark:double):integer;
  stdcall;external 'Read2.dll' name 'PrepareVBModify';
  function ReadModify(sourcefilename:pchar;SubjectNumber:integer):double;
  stdcall;external 'Read2.dll' name 'ReadVBModify';procedure TForm1.Button1Click(Sender: TObject);
var
p:integer;
count:double;
begin
 p:=PrepareModify('D:\1.26\阅卷系统\VBM.ans',20);
 if p=1 then
 begin
  count:=ReadModify('D:\1.26\阅卷系统\MODIFY.BAS',1);
  showmessage(floattostr(count));
 end;
end;
能正常运行但是逻辑上count应该为20而不是0,是不是c中的float在delphi中不能用double替代??
动态链接库头文件如下:
#ifndef READ2_H
#define READ2_H#ifdef READ2_DLL
#define EXTERN __declspec(dllexport)
#else
#define EXTERN __declspec(dllimport)
#endif//
extern "C" EXTERN int  PrepareVBModify(const char* lpszAnswerFileName,float fTotalMark);
//
extern "C" EXTERN float  ReadVBModify(const char* lpszSourceFileName,int iSubjectNumber);
#endif

解决方案 »

  1.   

    1. C中float为4个字节,delphi中double为8个字节,delphi中使用single
    2.
    extern "C" EXTERN int PrepareVBModify(const char* lpszAnswerFileName,float fTotalMark);
    extern "C" EXTERN float ReadVBModify(const char* lpszSourceFileName,int iSubjectNumber);
    改为:
    extern "C" EXTERN int WINAPI PrepareVBModify(const char* lpszAnswerFileName,float fTotalMark);
    extern "C" EXTERN float WINAPI ReadVBModify(const char* lpszSourceFileName,int iSubjectNumber);