调用VC编写的普通dll的问题(50分)

  • 主题发起人 主题发起人 iseeks
  • 开始时间 开始时间
I

iseeks

Unregistered / Unconfirmed
GUEST, unregistred user!
我新建了一个application,在form内添加一个button控件,在button的onclick事件中调用SafeEngine.dll(用VC编写)中的SEH_InitialSession过程,<br>可是运行时会报如下错误:Access violation at address 1000C8B1 in module 'SafeEngine.dll'.Write of address 00000002.<br>请问主要是哪方面出错啦?<br><br>我的调用源码如下:<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, <br><br>Forms,<br>&nbsp; Dialogs, StdCtrls;<br>procedure SEH_InitialSession(PriKeyDevType: Integer; const <br><br>strPrivKeyDevParam: WideString;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const strPriKeyPass: WideString; <br><br>lPriKeyTimeout: Integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CertChainDevType: Integer; const <br><br>strCertChainDevParam: WideString;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const strCertChainPass: <br><br>WideString);StdCall;<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br>procedure SEH_InitialSession;external 'SafeEngine.dll' name <br><br>'SEH_InitialSession';<br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>SEH_InitialSession(2,'userkey.key','sheca',1000,2,'CertChain.spc','');<br>end;<br><br>end.<br>
 
Delphi 调用VC的DLL<br><br><br>VC中DLL声名格式: <br><br>Extern “C” void __declspec(dllexport) __stdcall ShowMess(HWND hwnd, char* mess);<br><br>输出格式为:_ShowMess@8,“8”为函数参数字节数<br><br>为了避免名称分裂,可采用以下方法解决:<br><br>1.声明中不加__stdcall,采用VC默认格式__cdecl,但在Delphi中要注明调用格式为cdecl。<br><br>2.在VC工程中添加def文件,如:<br><br>LIBRARY<br><br>EXPORTS<br><br>ShowMess @1<br><br>则DLL中输出函数名称不分裂。<br><br><br>Delphi中调用格式: <br><br>Procedure ShowMess (h:HWND; mess:PChar); Stdcall;{Cdecl;} external LibName;<br><br>如无Stdcall或Cdecl声名,Delphi默认Register(FastCall)调用格式。<br><br><br>注意Delphi与VC的对齐格式不同,在VC中定义结构时要用以下格式: <br><br>#pragma pack(4)<br><br>//结构定义<br><br>#pragma pack()<br><br><br>常用工具: <br><br>TDump.exe-Delphi 4 和 C++ Builder 3 提供<br><br>Impdef.exe 和 Implib.exe - C++ Builder 3提供<br><br>DumpBin.exe-VC5.0提供<br><br>Lib.exe-VC5.0提供<br><br>
 
贴出vc的函数声明的原形撒<br>这样怎么帮你呢,<br>如果数据类型这么声明的char *,你以为用widestring就能解决了吗?<br>用pchar吧
 
同意楼上, 用pchar
 
可是我只有这个.dll文件和接口说明文档,相关接口说明摘抄如下:<br><br>SHE_InitialSession函数<br>在调用以下函数前必须先调用此函数初始化.<br>功能:初始化环境,从设备中读取私钥、根证书。<br>语法:int &nbsp;SEH_InitialSession(unsigned short privatekeydevicetype, &nbsp;char *privatekeydeviceparameter, char *privatekeypassword, &nbsp;unsigned long privatekeytimeout, &nbsp;unsigned short rootcertdevicetype, &nbsp;char *rootcertdeviceparameter, &nbsp;char *rootcertpassword )<br><br>是不是我用的参数类型不对呀,指点我一下吧,谢谢了<br>
 
&nbsp; &nbsp;因为我比较菜,比较笨,所以能否给出完整的函数定义段哦,万分感激,这是我最后的50分了,<br>呜呜,再问一下哦,象我这种小菜鸟怎么可以再获得一些积分来问问题呀?
 
忘了忘了,除了函数定义段外,在onclick事件中<br>原先的SEH_InitialSession(2,'userkey.key','sheca',1000,2,'CertChain.spc','')又要怎样改呀?<br>不是我偷懒不肯自己动手改哦,只是我实在太菜,而要完成的时间又紧迫,所以请大家多费心了。
 
帮我吧,谢谢
 
后退
顶部