这样声明函数
function GetInformation(Const Con:PChar;Const Service:PChar; var OutPut:PChar):Integer;stdcall;external 'VEHDRVEXT.DLL';
这样调用:var
vi:integer;
vcon,vserverice:string;
//voutput:array[0..999] of char;
voutput: PChar;//string;//
begin
//vi:='110';
// FillChar(vi, SizeOf(vi), ord(' '));
voutput:='1122345678';
Username :='Xubo';
Password :='123456';
Username := trim(medt1.Text);
// parambyname('password').AsString := trim(edit2.Text);
Password := trim(medt2.Text);
try
begin
//GetMem(vi,2048);
GetMem(voutput,2048);
vi:=GetInformation('amag@amag123','checkLogin',voutput);
end;
finally
begin
//FreeMem(vi);
FreeMem(voutput);
end;
end;但是 为什么 voutput总是得到乱码 呢??
function GetInformation(Const Con:PChar;Const Service:PChar; var OutPut:PChar):Integer;stdcall;external 'VEHDRVEXT.DLL';
这样调用:var
vi:integer;
vcon,vserverice:string;
//voutput:array[0..999] of char;
voutput: PChar;//string;//
begin
//vi:='110';
// FillChar(vi, SizeOf(vi), ord(' '));
voutput:='1122345678';
Username :='Xubo';
Password :='123456';
Username := trim(medt1.Text);
// parambyname('password').AsString := trim(edit2.Text);
Password := trim(medt2.Text);
try
begin
//GetMem(vi,2048);
GetMem(voutput,2048);
vi:=GetInformation('amag@amag123','checkLogin',voutput);
end;
finally
begin
//FreeMem(vi);
FreeMem(voutput);
end;
end;但是 为什么 voutput总是得到乱码 呢??
解决方案 »
- 奇怪的问题!
- 关于申明变量的小问题,怪,怪,怪,大家一块来看看,小弟太菜了!
- ExtractStrings函数的用法
- 很奇怪哦!俺在窗体上放个frReport1 再放个Button1 ,执行一下frReport1.ShowReport;,都居然连预览都不出来!!怎么办的?
- 如何调用 com 组件?
- 100分求购《DELPHI6从入门到精通》一书的配套源代码
- delphi怎么全部替换图标,我替换了以后用工具查看没有成功,只是桌面显示的图标变了
- serverSocket的点对多点的编程
- 为什么升级ADOUPDATE2后仍出现错误?“ACCESS VIOLATION”
- 对大侠来说忒简单的问题...如果删除表中空的数据?小弟这里先谢了!
- vcl对创建子控件的封装
- 奇怪的问题
因为你刚刚申请的内存没有初始化,里边的值都是随机的。
而函数
vi:=GetInformation('amag@amag123','checkLogin',voutput);
不知道这个函数的实现,猜想voutput的值已经被填充了不过只是开头的几个字节而已
所以你跟踪调试的时候看起来好像总是乱码。
可以showmessage(voutput)出来看看。如果函数是以#0结尾的字符串填充的话
vi 就能得到 正常的值 但是执行到 FreeMem(vi); 的时候出现 invalid pointer opertion
这个指针错误 有办法解决吗?
.....
vi:=GetInformation('amag@amag123','checkLogin',voutput);
showmessage(voutput);//voutput的内容
showmessage(inttostr(length(voutput)));//voutput的长度....
dispose(voutput);
dll
library VEHDRVEXT;uses
SysUtils,
Classes;{$R *.res}
function GetInformation(Const Con:PChar;Const Service:PChar; var OutPut:PChar):Integer;stdcall;
begin
OutPut:='hello world';
Result:=1;
end;
exports GetInformation;
begin
end.调用unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
FGetInformation = function (Const Con:PChar;Const Service:PChar; var OutPut:PChar):Integer;stdcall; TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation function GetInformation(Const Con:PChar;Const Service:PChar; var OutPut:PChar):Integer;stdcall;external 'VEHDRVEXT.DLL';
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
vi:Integer;
voutput: PChar;
str:string;
hHandle:THandle;
//GetInformation:FGetInformation;
Con:PChar;
begin
str:='amag@amag123';
GetMem(con,2048);
strcopy(con,PChar(str));
{
hHandle:=LoadLibrary('VEHDRVEXT.dll');
if hHandle>0 then
begin
@GetInformation:=GetProcAddress(hHandle,'GetInformation') ;
if @GetInformation<>nil then
begin
vi:=GetInformation(con,'checkLogin',voutput);
showmessage(voutput);
end;
end;
FreeLibrary(hHandle);
FreeMem(con);
} vi:=GetInformation(con,'checkLogin',voutput);
showmessage(voutput);
FreeMem(con);
end;end.
new(voutput);
.....
vi:=GetInformation(pchar('amag@amag123'),pchar('checkLogin'),voutput);
showmessage(voutput);//voutput的内容
showmessage(inttostr(length(voutput)));//voutput的长度 ....
dispose(voutput);
各位老大
用 yunqianyi1974 的 没有值 在执行到dispose(voutput); 的时候出现
invalid pointer opertion 错误 所以不对用hongqi162 专家的 voutput:nil 好像没调用成功 还是怎么回事
不给 voutput 分GetMem(voutput,2048);好像就这样dll 是别人写的 他里面有很多 函数所以
他这样写的
library VEHDRVEXT;uses
ShareMem,
GetInfoServer in '..\unit\GetInfoServer.pas',
SaveInfoServer in '..\unit\SaveInfoServer.pas',
ExportInter in '..\unit\ExportInter.pas',
Config in '..\unit\Config.pas',
Globalvar in '..\unit\Globalvar.pas',
Picconvert in '..\unit\Picconvert.pas';exports
InitMem,
UnInitMem,
GetInformation,
SaveInformation;
{$R *.res}beginend.
写的人有个 exe 他都调用成功了 的(汗 但没源文件) 所以我怀疑 是 我调用的问题
但有找不出来
各位 大大 在给点提示啊 谢个了!
没有出现 invalid pointer opertion 的指针错误
但是 voutput 还是乱码 好像没调用成功似的 但 没什么错误提示 快帮帮忙啊 各位大大 这个问题卡 我好些天了
voutput:pchar;
//new(voutput);
.....
vi:=GetInformation(pchar('amag@amag123'),pchar('checkLogin'),voutput);
showmessage(voutput);//voutput的内容
showmessage(inttostr(length(voutput)));//voutput的长度 ....
//dispose(voutput);
这样行不行
voutput:pchar;
//new(voutput);
.....
vi:=GetInformation(pchar('amag@amag123'),pchar('checkLogin'),voutput);
showmessage(voutput);//voutput的内容
showmessage(inttostr(length(voutput)));//voutput的长度 ....
//dispose(voutput);
这样行不行
var
voutput:pchar;
new(voutput);
.....
vi:=GetInformation(pchar('amag@amag123'),pchar('checkLogin'),voutput);
showmessage(voutput);//voutput的内容
showmessage(inttostr(length(voutput)));//voutput的长度 ....
voutput:=nil;
dispose(voutput);
动态库都一样 但是 我把 函数这样 一变
function GetInformation(Const Con:PChar;Const Service:PChar; var OutPut:PChar):PChar;stdcall;external 'VEHDRVEXT.DLL'; 把vi:PChar 调用出来的 vi =‘2:登录成功’是我要的答案
但是在 dispose(vi)的时候出现 invalid pointer opertion 的指针错误 这是为什么出现错误啊 有没办法解决呢?各位大大 ??
都来帮小弟 转转啊!
和
function GetInformation(Const Con:PChar;Const Service:PChar; var OutPut:PChar):Integer;stdcall;external 'VEHDRVEXT.DLL';
不一样的你声明有问题当然不好用了
dispose(vi); 加了vi:=nil; 到是不出 invalid pointer opertion 的指针错误
了 但是 vi 始终 都是 nil了 为什么 位换了声明 vi能得到 想要的东西呢? 照理 该是调用 dll不成功啊
function GetInformation(Const Con:PChar;Const Service:PChar; var OutPut:PChar):PChar;stdcall;external 'VEHDRVEXT.DLL'; 最后 vi 值 就是我想要的 加了vi:=nil;
dispose(vi); 也不出 指针错误了 .就暂时先这样用吧 但是我很 困惑的是 我看了dll
里面 函数 明明是 function GetInformation(Const Con:PChar;Const Service:PChar; var OutPut:PChar):Integer;stdcall; 这样的
怪 事 .
在次谢谢各位 大大啊 特别是1974 .