有点难度的问题 ^^(100分)

  • 主题发起人 主题发起人 95927
  • 开始时间 开始时间
9

95927

Unregistered / Unconfirmed
GUEST, unregistred user!
C 头文件定义:<br>&nbsp; <br>typedef unsigned int &nbsp;UINT4;<br>typedef unsigned char UCHAR;<br><br>C 头文件函数声明:<br><br>int &nbsp;CreateKeyFromPassword(ATTRIB_TYPE &nbsp;keyAttrib,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;UCHAR &nbsp; &nbsp; &nbsp; *inPassword,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;UINT4 &nbsp; &nbsp; &nbsp; &nbsp;passwordLen,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;UCHAR &nbsp; &nbsp; &nbsp; *outKey,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;UINT4 &nbsp; &nbsp; &nbsp; *outKeyLen);<br><br>同志们先看看下面转的对不对,要说明的是outKey,outKeyLen是要返回的<br>CreateKeyFromPassword看函数返回的值(是不是调用成功)来处理outKey,outKeyLen的<br><br>以下是我转的Delphi 接口声明(不知道对不对): &nbsp;<br><br>&nbsp; function CreateKeyFromPassword(keyAttrib: ATTRIB_TYPE;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inPassword: PChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; passwordLen: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outKey: PChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outKeyLen: PWord): Integer; cdecl; external MyDll_Name;<br><br>Delphi 调用:<br><br>var<br>&nbsp; TempInt: Integer;<br>&nbsp; Password, Key: string;<br>&nbsp; KeyLen: Word;<br><br>begin<br>&nbsp; TempInt := CreateKeyFromPassword(ATTRIB_SDBI_KEY,<br>&nbsp; &nbsp; PChar(Password), Length(Password), PChar(Key), @KeyLen);<br>&nbsp; if RTN_OK &lt;&gt; TempInt then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('生成密钥失败, 错误代码:[ ' + IntToStr(TempInt) + ' ]');<br>&nbsp; end;<br><br>end;<br><br>程序运行是没有错,可就是调用失败
 
<br>function CreateKeyFromPassword(keyAttrib: ATTRIB_TYPE;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inPassword: PChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; passwordLen: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outKey: PChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var outKeyLen: Word): Integer; cdecl; external MyDll_Name;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /////////////////// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//// 如果不行再最后把这个改成 stdcall 试试<br>Delphi 调用:<br><br>var<br>&nbsp; TempInt: Integer;<br>&nbsp; Password, Key: array[0..255] of char;<br>&nbsp; KeyLen: Word;<br><br>begin<br>&nbsp; TempInt := CreateKeyFromPassword(ATTRIB_SDBI_KEY,<br>&nbsp; &nbsp; Password, 255, Key, KeyLen);<br>&nbsp; if RTN_OK &lt;&gt; TempInt then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('生成密钥失败, 错误代码:[ ' + IntToStr(TempInt) + ' ]');<br>&nbsp; end;<br><br>end;<br><br>其实上面的修改也无关紧要,只是你原来没有给 Password, Key 分配空间。<br>&nbsp;255 不够,再大一些。
 
还有其我的建意吗?
 
接受答案了.
 
后退
顶部