动态连接库(10分)

  • 主题发起人 zhengyue
  • 开始时间
Z

zhengyue

Unregistered / Unconfirmed
GUEST, unregistred user!
动态连接库<br>我在用如下程序调用动态连接库返回的值不正确请问怎么回事?<br>应该怎样改?<br>功能:返回汉字的拼音头<br>var<br>&nbsp; txt1:pchar;<br>&nbsp; txt2:string;<br>&nbsp; moudle:thandle;<br>&nbsp; getpy:Tgetpy;<br>begin <br>&nbsp; moudle:=loadlibrary('pyhead'); &nbsp;//链接动态库<br>&nbsp; @getpy=getprocaddress(moudle,'getpy')//链接动态库已经成功<br>&nbsp; getmem(txt1,sizeof(pchar));<br>txt1=strpcopy(txt1,edit1.txt);<br>txt2:=strpas(getpy(txt1)); &nbsp;//? txt2返回值不正确<br>劳驾各位帮忙,怎样该?<br><br><br>说明:<br>如果不用动态链接库,直接调用getpy函数,着返回值是正确的<br><br>在动态库getpy函数定义为<br>function getpy( hzchar:pchar):pchar;<br>begin<br>&nbsp; case WORD(hzchar[0]) shl 8 + WORD(hzchar[1]) of<br>&nbsp; &nbsp; $B0A1..$B0C4 : result := 'A';<br>&nbsp; &nbsp; $B0C5..$B2C0 : result := 'B';<br>&nbsp; &nbsp; $B2C1..$B4ED : result := 'C';<br>&nbsp; &nbsp; $B4EE..$B6E9 : result := 'D';<br>&nbsp; &nbsp; $B6EA..$B7A1 : result := 'E';<br>&nbsp; &nbsp; $B7A2..$B8C0 : result := 'F'; <br>&nbsp; &nbsp; $B8C1..$B9FD : result := 'G';<br>&nbsp; &nbsp; $B9FE..$BBF6 : result := 'H'; <br>&nbsp; &nbsp; $BBF7..$BFA5 : result := 'J'; <br>&nbsp; &nbsp; $BFA6..$C0AB : result := 'K';<br>&nbsp; &nbsp; $C0AC..$C2E7 : result := 'L'; <br>&nbsp; &nbsp; $C2E8..$C4C2 : result := 'M'; <br>&nbsp; &nbsp; $C4C3..$C5B5 : result := 'N';<br>&nbsp; &nbsp; $C5B6..$C5BD : result := 'O'; <br>&nbsp; &nbsp; $C5BE..$C6D9 : result := 'P'; <br>&nbsp; &nbsp; $C6DA..$C8BA : result := 'Q';<br>&nbsp; &nbsp; $C8BB..$C8F5 : result := 'R'; <br>&nbsp; &nbsp; $C8F6..$CBF9 : result := 'S'; <br>&nbsp; &nbsp; $CBFA..$CDD9 : result := 'T';<br>&nbsp; &nbsp; $CDDA..$CEF3 : result := 'W'; <br>&nbsp; &nbsp; $CEF4..$D188 : result := 'X';<br>&nbsp; &nbsp; $D1B9..$D4D0 : result := 'Y';<br>&nbsp; &nbsp; $D4D1..$D7F9 : result := 'Z';<br>&nbsp; else <br>&nbsp; &nbsp; result := char(0);<br>&nbsp; end;<br><br>end;<br>exports getpy; <br><br>
 
你uses了memshare吗?用strings试试?<br><br>dll和你的程序不在一个进程(夷,好像是在同一个进程),传递指针好像有问题吧。
 
请问怎样 加 memshare
 
Getpy:function( hzchar:pchar):pchar;stdcall;<br><br>var<br>&nbsp; txt1:pchar;<br>&nbsp; txt2:string;<br>&nbsp; moudle:thandle;<br>&nbsp; //getpy:Tgetpy;<br>begin <br>&nbsp; moudle:=loadlibrary(pchar('pyhead')); &nbsp;//链接动态库<br>&nbsp; @getpy=getprocaddress(moudle,'Getpy')//链接动态库已经成功<br>&nbsp; getmem(txt1,sizeof(pchar));<br>txt1=strpcopy(txt1,edit1.text);<br>txt2:=strpas(Getpy(txt1)); &nbsp;//试试看?<br><br>Do not forget to free(Moudle);<br><br><br>在动态库getpy函数定义为<br>function Getpy( hzchar:pchar):pchar;<br>.<br>.<br>exports Getpy; <br>
 
to &nbsp;mgm <br>把Getpy:function( hzchar:pchar):pchar;stdcall 放在什么位置<br>我试了好几个位置都不行<br>
 
你如果是通过dll向导生成的dll,在它的注释里有说要叫memshare,和在哪儿加。
 
我在函数定义后加上stdcall 就没室了<br>谢谢
 
顶部