别的公司给的C++
sum(const char *InName, const char * OutName)
无返回值的dll
dll名称为sum.dll
我delphi中应当怎么怎么调用?声明方法?使用方法?
我这样:
1、procedure CISOC_LOGP(const InName:Array [0..255] Of Char;const OutName:Array [0..255] Of Char);stdcall;external 'CISOC_LOGP.dll';
2、//procedure CISOC_LOGP(const InName:Pointer;const OutName:Pointer;stdcall;external 'CISOC_LOGP.dll';
均不能给其赋值,返回错误提示都是:
Access violation at address 00000000. Read of address 00000000'.编译环境:Delphi 2006 5张CD的完整版
sum(const char *InName, const char * OutName)
无返回值的dll
dll名称为sum.dll
我delphi中应当怎么怎么调用?声明方法?使用方法?
我这样:
1、procedure CISOC_LOGP(const InName:Array [0..255] Of Char;const OutName:Array [0..255] Of Char);stdcall;external 'CISOC_LOGP.dll';
2、//procedure CISOC_LOGP(const InName:Pointer;const OutName:Pointer;stdcall;external 'CISOC_LOGP.dll';
均不能给其赋值,返回错误提示都是:
Access violation at address 00000000. Read of address 00000000'.编译环境:Delphi 2006 5张CD的完整版
解决方案 »
- treeview和DBGrid的问题?
- 請問在DELPHI中如何製作HTML編輯器,可以讓網站直接讀取的那種,像DW那樣的.
- excel导出的中文方格问题
- 使用TWebBrowser.GoBack为什么会出错
- Tjpegimage产生得jpg图片能以TMemoryStream存到数据库里面吗?怎样存?
- dbexpress 连接数据库 急!!!!!
- 怎么安装DevExpress套件?很急!
- edit输入问题。(在线等)
- 打听一下:深圳在4月27日是不是有个毕业生专场招聘会?
- 关于delphi 的网络编程
- ~~~求 <刘艺的delphi面向对象编程> 这本书~~~
- 你好,打扰了。请帮帮看看这段代码的算法是什么好吗?
var
InName,OutName:array[0..60000]of Char;
begin
InName:='1.txt';
OutName:='2.TXT';
sum(@InName,@OutName);
end;请问那怎么使用呢?
这里因为定义的是const所以在dll里不会对这个指针进行重新赋值,所以用char的数组,或者用pchar都可以,甚至string都没问题。
但注意pchar要分配内存,释放内存.
http://blog.csdn.net/fenger8293
procedure TFormMain.bsSkinSpeedButton3Click(Sender: TObject);
var
InName,OutName:array[0..60000]of Char;
begin
InName:='1.txt';
OutName:='2.TXT';
sum(@InName,@OutName);
end;
错误提示:
Access violation at address 00000000. Read of address 00000000'.
winexec(pp,sw_show);
使用:
sum('1.txt','2.txt');
错误:
Access violation at address 00000000. Read of address 00000000'.
var
InName,OutName:string;
InName := 'c:\1.jpg';
OutName := 'C:\2.jpg';sum(pchar(InName),pchar(OutName));
sum(const char *InName, const char * OutName)
InName,OutName都是传入的参数
按名字来说
OutName似乎是传出的参数(难道给的C++声明有错误?)
楼主试试吧
如果是sum(const char *InName, char **OutName)的话
要改成
procedure(const InName:Pchar; var OutName:Pchar);stdcall;external''sum.dll;
这样声明的话,连编译都出错!!这是我完整的声明部分:
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
sum:procedure(const InName:PChar;Const OutName:PChar);stdcall;
end;var
Form1: TForm1;implementationprocedure sum;external 'sum.dll';帮忙看看有问题吗?这是完整的调用部分:
procedure TForm1.Button1Click(Sender: TObject);
var
InName,OutName:String;
begin
InName:='1.txt';
OutName:='2.TXT';
sum(@InName,@OutName);
end;这是完整的C语言给出的实例代码:
extern "C" __declspec(dllimport) void __stdcall sum(const char *InName,const char * OutName); //函数声明void main()
{
//………………………….
sum("1.txt","2.txt");//调用函数 输入txt文件
//……………………
}无论是
sum(pchar(InName),pchar(OutName));
还是
sum(@InName[1],@OutName[1]);
都不行?
都是一句错误代码:
Access violation at address 00000000. Read of address 00000000'. 大家帮帮忙?谢谢了!!!
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationprocedure sum(const InName:PAnsiChar;const OutName:PAnsiChar);stdcall;external 'sum.dll';procedure TForm1.Button1Click(Sender: TObject);
begin
sum('1.txt','2.txt'); //文字常量调用
sum(PAnsiChar(Edit1.Text),PAnsiChar(Edit2.Text));
end;
a,b:pChar;
begin
a:='1.txt';
b:='2.txt';
sum(a,b);
//试试
只能用全局函数像15楼那样
您这样声明之后,程序一运行就出错:
Access violation at address 0x7c957a50. write of address 0x00030d24'.
procedure(const InName:Pchar; const OutName:Pchar);stdcall;external 'sum.dll';
直接这样声明是不能使用的,缺少函数名。但用15楼的才可以声明,但运行出错。我想我的程序,是不是没有自动加载dll呀???
program ProjectUseDLL;下有什么声明吗?
Access violation at address 00000000. Read of address 00000000'. 动态加载内存代码:
procedure TForm1.Button3Click(Sender: TObject);
type
T_sum=procedure(const PAnsiChar:Pchar; const OutName:PAnsiChar);stdcall;
var
tmpHandle:THandle;
sum:T_sum;
begin
if not FileExists('sum.dll') then Exit;
tmpHandle:=LoadLibrary('sum.dll');
if tmpHandle<>0 then
@sum:=GetProcAddress(tmpHandle,'sum');
sum('c:\1.txt','c:\2.txt');
FreeLibrary(tmpHandle);
end;
用进程查看软件,可以看到sum.dll已经被加载了。能告诉我这到底是哪里错了?我觉得,我只是一个非常小的错误。否则不会这么难找!!!
大家帮帮忙呀!!!
抱歉,此dll文件是我们公司花钱买的。
extern "C" __declspec(dllimport) void __stdcall sum(const char *InName,const char * OutName); //函数声明
至少他们得技术支持
你应该使用pchar, getmem 调用完后再free.
而且也不能用'1.txt', '2.txt'这样的常量,因为这也是栈变量。
另外声明不必用const
procedure(const InName:Pchar; const OutName:Pchar);stdcall;external''sum.dll;procedure(InName:Pchar; OutName:Pchar);stdcall;external''sum.dll;
这样就行了。
type
T_sum = procedure(const InName: PAnsiChar; const OutName: PAnsiChar); stdcall;
var
tmpHandle: THandle;
sum: T_sum;
outName: array[0..500] of Char;//用一个Array预先分配好空间传给Dll
begin
if not FileExists('sum.dll') then Exit;
tmpHandle := LoadLibrary('sum.dll');
if tmpHandle <> 0 then
begin
@sum := GetProcAddress(tmpHandle, 'sum');//注意如果不行,请确认Dll中的函数名的大小写
if @sum <> nil then
begin
sum('c:\1.txt', outName);
ShowMessage(outName);
end
else
ShowMessage('在sum.dll中找不到sum函数');
FreeLibrary(tmpHandle);
end;
end;