救命啊,我用delphi7调用c++写的dll,碰到问题了,请高手救我! ( 积分: 100 )

  • 主题发起人 主题发起人 ohtinon
  • 开始时间 开始时间
O

ohtinon

Unregistered / Unconfirmed
GUEST, unregistred user!
问题是这样的:<br>这是dll函数说明文档:<br><br>(1)压缩接口:<br> int&nbsp;Compress(<br>const&nbsp;byte*&nbsp;pbyteSource,&nbsp;<br>long&nbsp;lngSourceSize,&nbsp;<br>byte*&nbsp;pbyteDest,&nbsp;<br>long*&nbsp;plngDestSize);<br> 参数:<br> pbyteSource:需要压缩数据的指针地址<br> lngSourceSize:需要压缩数据的字节长度<br> pbyteDest:需要保存压缩后的数据指针<br> plngDestSize:实际压缩数据的长度,如果传入0,则返回需要保存压缩数据长度<br><br> 返回:<br> 0:成功<br> -1:失败<br><br>示例:<br><br> (2)解压缩接口<br> int&nbsp;Descompress(<br>const&nbsp;byte*&nbsp;pbyteSource,&nbsp;<br>long&nbsp;lngSourceSize,&nbsp;<br>byte*&nbsp;pbyteDest,&nbsp;<br>long*&nbsp;plngDestSize);<br> 参数:<br> pbyteSource:需要解压缩数据的指针地址<br> lngSourceSize:需要解压缩数据的字节长度<br> pbyteDest:需要保存解压缩后的数据指针<br> plngDestSize:实际解压数据的长度,如果传入0,则返回需要保存解压数据长度<br><br> 返回:<br> 0:成功<br> -1:失败<br><br> 示例:<br><br> (3)压缩算法的版本号<br> int&nbsp;CompressVersion(char*&nbsp;pszVersion);<br>参数:<br> pszVersion:需要返回版本号的字符指针,至少已分配10个字节长度,返回的格式为:x.x.yyyy.z,例如:1.0.0001.0<br> 返回:<br> 0:成功<br> -1:失败<br><br>---我用delphi调用试了N遍,都不行,请高手救我!帮我写一下怎么调用compress及Descompress<br><br><br>下面是用powerbuild&nbsp;调用的例子,试了可以通过,贴出来参考下<br>&nbsp;PowerBuilder语言调用示例<br>//函数声明<br>FUNCTION&nbsp;long&nbsp;Compress(blob&nbsp;pbyteSource,&nbsp;long&nbsp;lngSourceSize,&nbsp;ref&nbsp;blob&nbsp;pbyteDest,&nbsp;ref&nbsp;long&nbsp;plngDestSize)&nbsp;library&nbsp;&quot;sehr.crypto.dll&quot;;<br>FUNCTION&nbsp;long&nbsp;Decompress(blob&nbsp;pbyteSource,&nbsp;long&nbsp;lngSourceSize,&nbsp;ref&nbsp;blob&nbsp;pbyteDest,&nbsp;ref&nbsp;long&nbsp;plngDestSize)&nbsp;library&nbsp;&quot;sehr.crypto.dll&quot;;<br>FUNCTION&nbsp;long&nbsp;CompressVersion(ref&nbsp;string&nbsp;strVersion)&nbsp;library&nbsp;&quot;sehr.crypto.dll&quot;;<br><br>//调用示例<br>string&nbsp;ls_version;&nbsp;<br>ls_version&nbsp;=&nbsp;space(11);&nbsp;//分配内存,&nbsp;版本号是10个字节&nbsp;+&nbsp;1个结尾符<br>int&nbsp;li_result;<br>li_result&nbsp;=&nbsp;CompressVersion(ls_version);&nbsp;//获取压缩版本号<br><br>//压缩<br>blob&nbsp;lblob_source,&nbsp;lblob_dest;<br>lblob_source&nbsp;=&nbsp;blob(ls_version);<br>long&nbsp;ll_dest;<br>ll_dest&nbsp;=&nbsp;0;<br>li_result&nbsp;=&nbsp;Compress(lblob_source,&nbsp;len(lblob_source),&nbsp;lblob_dest,&nbsp;ll_dest);&nbsp;//先检查需要多少内存&nbsp;保存到ll_dest<br>if(li_result&nbsp;&lt;&gt;&nbsp;0)&nbsp;&nbsp;then&nbsp;return;<br><br>lblob_dest&nbsp;=&nbsp;blob(space(ll_dest));&nbsp;//分配内存<br>li_result&nbsp;=&nbsp;Compress(lblob_source,&nbsp;len(lblob_source),&nbsp;lblob_dest,&nbsp;ll_dest);<br>if(li_result&nbsp;&lt;&gt;&nbsp;0)&nbsp;then&nbsp;&nbsp;return;<br><br>//解压缩<br>long&nbsp;ll_len;<br>ll_len&nbsp;=&nbsp;0;<br>blob&nbsp;lblob_target;<br>li_result&nbsp;=&nbsp;Decompress(lblob_dest,&nbsp;ll_dest,&nbsp;lblob_target,&nbsp;ll_len);//先检查需要多少内存&nbsp;保存到ll_len<br>if(li_result&nbsp;&lt;&gt;&nbsp;0)&nbsp;then&nbsp;&nbsp;return;<br><br>lblob_target&nbsp;=&nbsp;blob(space(ll_len));//分配内存<br>li_result&nbsp;=&nbsp;Decompress(lblob_dest,&nbsp;ll_dest,&nbsp;lblob_target,&nbsp;ll_len);<br>if(li_result&nbsp;&lt;&gt;&nbsp;0)&nbsp;then&nbsp;&nbsp;return;<br><br>//检查解压缩后和压缩前是否一致<br>if(ls_version&nbsp;=&nbsp;left(string(lblob_target),&nbsp;ll_len))&nbsp;then<br> MessageBox(&quot;提示&quot;,&nbsp;&quot;解压缩成功&quot;);<br>else<br> MessageBox(&quot;提示&quot;,&nbsp;&quot;解压缩失败&quot;);<br>end&nbsp;if
 
大概这样<br>function&nbsp;comp(const&nbsp;instr&nbsp;:&nbsp;string)&nbsp;:&nbsp;string;<br>var<br>&nbsp;&nbsp;source&nbsp;:&nbsp;pchar;<br>&nbsp;&nbsp;dest&nbsp;:&nbsp;pchar;<br>&nbsp;&nbsp;l&nbsp;:&nbsp;integer;<br>begin<br>&nbsp;&nbsp;result&nbsp;:=&nbsp;'';<br>&nbsp;&nbsp;source&nbsp;:=&nbsp;PChar(instr);<br>&nbsp;&nbsp;l&nbsp;:=&nbsp;0;<br>&nbsp;&nbsp;if&nbsp;Compress(source,&nbsp;length(insrt),&nbsp;nil,&nbsp;@l)&nbsp;=&nbsp;0&nbsp;then<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;getmem(dest,&nbsp;l);<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;Compress(source,&nbsp;length(insrt),&nbsp;dest,&nbsp;@l)&nbsp;=&nbsp;0&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result&nbsp;:=&nbsp;strpas(dest);<br>&nbsp;&nbsp;&nbsp;&nbsp;freemem(dest,&nbsp;l);<br>&nbsp;&nbsp;end;<br>end;
 
那这个dll的函数应该怎么声明呢<br>我有这个dll,我的QQ是3857673,谁加我拿这个dll去试下。<br>可以的话我把我的全部200分都送出去,我刚上来,就这么多分了。
 
谢谢啊,我稍微修动了下,已经可以了
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
898
import
I
I
回复
0
查看
810
import
I
后退
顶部