首页 > Windows开发 > 详细

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

时间:2015-06-04 15:44:10      阅读:520      评论:0      收藏:0      [点我收藏+]

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

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

vc的DLL源码地址 http://blog.csdn.net/lqena/article/details/46357165

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参数报错奇怪现象

原文:http://blog.csdn.net/lqena/article/details/46361753

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!