当前位置:首页 > Windows程序 > 正文

发现个delphi调用vc写的Dll中包含pchar参数报错奇怪现象

2021-05-26 Windows程序

标签:delphi vc dll pchar

发现个delphi调用vc写的Dll中包含pchar参数奇怪现象

procedure中的第一行语句不能直接调用DLL的函数,否则会运行错,在之前任意加上条语句就不报错了奇怪!

vc的DLL源码地址

Delphi源码如下:

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) btn1: TButton; procedure btn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function GetStr(s:PChar):PChar; stdcall; external 'MyDLL.dll'; procedure TForm1.btn1Click(Sender: TObject); var p :PChar; s:string; begin s:='123'; //procedure中的第一行语句不能直接调用GetStr,否则会运行错,加上这行语句不报错了奇怪 p:= GetStr('63024823'); //接收必须是PChar,如果String可以编译通过,但运行报错 ShowMessage(p); end; end.

发现个delphi调用vc写的Dll中包含pchar参数报错奇怪现象

标签:delphi vc dll pchar

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/71305.html