注册 登录
编程论坛 Delphi论坛

delphi调用vc的dll的问题

xs1065 发布于 2007-08-14 16:06, 1633 次点击
在delphi调用了用vc写的dll,它的函数返回值为char *,在dll导出函数原型为:
PAPERDLL_API char *PAPERDLL_CALLCONV PD_Get_stuPaperInfo(LPCTSTR strSourceFileName,
LPCTSTR strTemplateFileName,
int paperPageSum,
LPCTSTR strInfoFileName,
LPCTSTR strCutFileName,
int scoreMode);
函数的参数没有问题,返回为一个char *;
在delphi我对该函数做了如下声明:
function PD_Get_stuPaperInfo(strSourceFileName,strTemplateFileName:string;
paperPageSum:integer;
strInfoFileName,strCutFileName:string;
scoreMode:integer):Pchar;stdcall;
external 'PaperDll.dll';
然后调用该函数:
var FStudInfo:PChar;
FStudInfo := PD_Get_stuPaperInfo(FStudentAnswPath,
FLabelPath,
FExamPaperNum,
FWritePath,
FCutPath,
FRegnPattern);
为什么参数返回的为nil?请教解决!谢谢了!
4 回复
#2
anthony6342007-08-14 19:13

改成这样看下行不?
function PD_Get_stuPaperInfo( strSourceFileName: PChar;
strTemplateFileName:PChar;
paperPageSum:integer;
strInfoFileName: PChar;
strCutFileName:PChar;
scoreMode:integer):Pchar;stdcall;


var
Form1: TForm1;

implementation

{$R *.dfm}
function PD_Get_stuPaperInfo; external 'PaperDll.dll' name 'PD_Get_stuPaperInfo';

#3
volte2007-08-19 18:43

在保证楼主VC的DLL正确的情况下,
楼上的正解,不过注意function有返回值。
{$R *.dfm}
function PD_Get_stuPaperInfo; external 'PaperDll.dll' name 'PD_Get_stuPaperInfo';

注意少了返回值!

#4
volte2007-08-19 18:44
vc中识别不了delphi的string类型
vc的LPCTSTR用delphi的PChar或者PWideChar
1