type
Tseekcrypt=Function(flag:integer;instr:pchar;instrlen:integer;key:pchar;outstr:pchar;outstrlen_ptr:integer):Integer;stdcall;
Thandle=Integer;implementationuses max;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
instring,keystring,outstring:Pchar;
pflag,instringlen,outstringlen:integer;
handle:Thandle;
seekcrypt:Tseekcrypt;
begin
instring:=StrAlloc(17*Sizeof(char));
strpcopy(instring,'1111111111111111');
keystring:=StrAlloc(17*Sizeof(char));
strpcopy(keystring,'0000000000000000');
outstring:=stralloc(17*sizeof(char));
strpcopy(outstring,'');
pflag:=1;
instringlen:=16;
outstringlen:=0;
handle:=LoadLibrary('seekcrypt.dll');
if handle<>0 then
begin
@seekcrypt:=GetProcAddress(handle,'SeekCrypt');
if (@seekcrypt<>nil)then
begin
//执行的时候在这里出问题,就是说在调用Dll中的函数时出错了。
Edit1.Text:=inttostr(seekcrypt(pflag,instring,instringlen,keystring,outstring,outstringlen));
end
else begin
showmessage('fail');
end;
end;
StrDispose(instring);
StrDispose(keystring);
StrDispose(outstring);
Freelibrary(handle);
end;end.编译没有问题。就是在运行的时候出问题!
我在VC中调用这个DLL没有问题,现在就是转过来在Delphi中调用出问题了。
解决方案 »
- 关于树型列表求组
- 怎么样判断键盘输入时间,如果大于2秒则清空。
- 请问。现在delphi三层结构。主流是用什么服务器组件和客户端组件。可以让客户端和服务器端有好的松偶合。
- 抽奖程序问题
- 关于报表纸张自定义大小问题,谢谢各位
- 使用installshield制作安装程序得时候如何添加使用说明!
- 不同的ORACLE驱动程序对存储或读取TBlobField有不同的影响?欢迎讨论
- Application.Run时窗体显示问题?高手解疑>
- 有报表开发经验的朋友进来探讨探讨?? 不仅可以学东东&哪分!!!
- Grid++Report报表点击打印很慢
- 如何捕捉DOS命令窗是否关闭?请各位大侠请点,在线等待!!!
- 为什么调用服务器端的方法没有反应,代码是从系统编抄的
我的DLL中的供调用的函数是
extern "C" int __declspec(dllexport) __stdcall SeekCrypt (int flag,unsigned char* instr,int instrlen,unsigned char* key,unsigned char* outstr,int* outstrlen_ptr)
{
if (flag == DECRYPT)
return qq_decrypt(instr, instrlen, key, outstr, outstrlen_ptr);
else if (flag == ENCRYPT)
qq_encrypt(instr, instrlen, key, outstr, outstrlen_ptr); AfxMessageBox("seekcrypt_ex0");
return 1;
}// seekcrypt 在Delphi中调用都能返回AfxMessageBox("seekcrypt_ex0");提示框的信息"seekcrypt_ex0"。也就是说明在Delphi中执行了这个函数,是在最后的返回时出错的!那个朋友能指点迷津的啊?
Tseekcrypt=Function(flag:integer;instr:pchar;instrlen:integer;key:pchar;outstr:pchar;outstrlen_ptr:integer):Integer;stdcall;outstrlen_ptr:integer类型好象不一致吧,outstrlen_ptr你把这个参数换成整型指针试试吧!
在你的C程序中执行没出错应该是outstrlen_ptr为整数所以没报错。
DLL代码:extern "C" _declspec(dllexport) int ChangePrinterName(TCHAR CharSource[],TCHAR CharResult[])
调用 type TChangePrinterName=function(source,result:pchar):integer stdcall;
我 把dll调用写成了一个函数:
function TDllFunction.ChangeprinterName(SourcePrinterName,ResultPrinterName:string):string;
var
SourcePrinterName1,ResultPrinterName1:pchar;
PHandle:Thandle;
PFunc:TFarProc;
nresult:integer;
begin
nresult:=0;
PHandle := LoadLibrary(Pchar('ReNamePrinter.dll'));//DLLName为DLL名称
if Phandle > 32 then //如果加载dll成功
begin
try
PFunc := GetProcAddress(Phandle, PChar('ChangePrinterName')); //获得函数地址
if PFunc<>nil then //如果加载函数成功
begin
ResultPrinterName1:=stralloc(256);
SourcePrinterName1:=stralloc(256);
ResultPrinterName1:=StrPCopy(ResultPrinterName1,pansichar(ResultPrinterName));
SourcePrinterName1:=StrPCopy(SourcePrinterName1,pansichar(SourcePrinterName));
TChangePrinterName(PFunc)(SourcePrinterName1,ResultPrinterName1); //取得函数返回值
end
except on e:exception do
begin
FreeLibrary(phandle); //如果发生调用DLL过程出错
showmessage(e.Message);
end;
end;
end;
if nresult=0 then
begin
result:='Dll调用失败';
end
else
begin
result:='调用成功';//SourcePrinterName;// 返回修改后打印机名称
showmessage('调用成功');
end;
FreeLibrary(phandle);
end;
希望对你有帮组
http://community.csdn.net/Expert/topic/3218/3218576.xml?temp=6.762332E-02