为什么我在我写的dll中调用另一个dll的函数编译时报错,应该如何写(100分)

  • 主题发起人 主题发起人 conanbos
  • 开始时间 开始时间
C

conanbos

Unregistered / Unconfirmed
GUEST, unregistred user!
在dllA中这样写Function encrypt_str(password:string):pchar;stdcall;external 'encrypt.dll';<br><br>可总是编译报错invalid compiler directive:'EXTERNAL'<br>怎么解决呀?
 
貼出更多代码看看,我遇到過.
 
library UserList_option;<br><br>{ Important note about DLL memory management: ShareMem must be the<br>&nbsp; first unit in your library's USES clause AND your project's (select<br>&nbsp; Project-View Source) USES clause if your DLL exports any procedures or<br>&nbsp; functions that pass strings as parameters or function results. This<br>&nbsp; applies to all strings passed to and from your DLL--even those that<br>&nbsp; are nested in records and classes. ShareMem is the interface unit to<br>&nbsp; the BORLNDMM.DLL shared memory manager, which must be deployed along<br>&nbsp; with your DLL. To avoid using BORLNDMM.DLL, pass string information<br>&nbsp; using PChar or ShortString parameters. }<br><br>uses<br>&nbsp; SysUtils,<br>&nbsp; Classes,windows;<br><br>{$R *.res}<br>Function encrypt_str(password:string):pchar;stdcall;external 'encrypt.dll';<br><br>
 
dll的名稱有大小寫的區分.<br>encrypt.dll 必須與dllA的名稱一樣.如dlla的名稱為ENCRYPT.DLL你這樣的調用就不可以了<br>
 
我没明白两个dll名称怎么能相同呢,我现在要做的是在连接库B(UserList_option.dll)中调用连接库A(encrypt.dll).
 
既然编译通不过就要找语法的问题了.<br>不过看你这个函数的定义就有点怪异:)<br>为什么要将string和pchar混用呢?当然虽然这并不影响你的dll的执行,但你得额外的增加<br>一个borlandmm的分发<br>
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2257794
 
语法我想肯定没问题Function encrypt_str(password:string):pchar;stdcall;external 'encrypt.dll';<br>
 
你定義到<br>implementation<br>後面看看。
 
注意DLL中的调用要区分大小写,有一点区别都不行!
 
看出问题来了<br>library UserList_option;<br><br>{ Important note about DLL memory management: ShareMem must be the<br>&nbsp;first unit in your library's USES clause AND your project's (select<br>&nbsp;Project-View Source) USES clause if your DLL exports any procedures or<br>&nbsp;functions that pass strings as parameters or function results. This<br>&nbsp;applies to all strings passed to and from your DLL--even those that<br>&nbsp;are nested in records and classes. ShareMem is the interface unit to<br>&nbsp;the BORLNDMM.DLL shared memory manager, which must be deployed along<br>&nbsp;with your DLL. To avoid using BORLNDMM.DLL, pass string information<br>&nbsp;using PChar or ShortString parameters. }<br><br>uses<br>&nbsp;SysUtils,<br>&nbsp;Classes,windows;<br><br>{$R *.res}<br>Function encrypt_str(password:string):pchar;stdcall;external 'encrypt.dll';<br><br>这是一个dll单元,你现在需要导出encrypt_str<br><br>library UserList_option;<br><br>{ Important note about DLL memory management: ShareMem must be the<br>&nbsp;first unit in your library's USES clause AND your project's (select<br>&nbsp;Project-View Source) USES clause if your DLL exports any procedures or<br>&nbsp;functions that pass strings as parameters or function results. This<br>&nbsp;applies to all strings passed to and from your DLL--even those that<br>&nbsp;are nested in records and classes. ShareMem is the interface unit to<br>&nbsp;the BORLNDMM.DLL shared memory manager, which must be deployed along<br>&nbsp;with your DLL. To avoid using BORLNDMM.DLL, pass string information<br>&nbsp;using PChar or ShortString parameters. }<br><br>uses<br>&nbsp;SysUtils,<br>&nbsp;Classes,windows;<br><br>{$R *.res}<br>Function encrypt_str(password:string):pchar;stdcall;<br>begin<br>&nbsp; .....<br>end;<br>exports encrypt_str;<br><br>&nbsp;<br>
 
你还是没理解意思 呀<br>encrypt_str函数是写在encrypt.dll中的,而且现在在UserList_option.dll中要调用它。<br><br>按你上面的写法,我是在UserList_option.dll中把encrypt_str函数再写一次,这不等于没用吗。
 
你不要在這裡定義啊,在要使用該函數的UNIT處定義,且義到<br>implementation<br>後面。
 
52free说的没错,最好统一用pchar,我也曾做过这样,动态A调用动态B的函数,就和在EXE文件里调一样,格式对了,就没问题的
 
已经可以了,不要写在dpr中,加入一个新unit,在那写就行。但我不知道为什么
 
多人接受答案了。
 

Similar threads

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