有关DLL的问题,很急,谢谢高手帮忙!(50分)

  • 主题发起人 主题发起人 redleaf_wgm
  • 开始时间 开始时间
R

redleaf_wgm

Unregistered / Unconfirmed
GUEST, unregistred user!
&nbsp; &nbsp;我想了解DELPHI编写的DLL是否是标准的DLL,在DELPHI编写DLL时使用字符串参数时使用什么类型比较合适呀?我试过String、WideString、ShortString、PChar等都不行,在运行时通过RUNDLL32.EXE调用时都报错,请问是什么原因呢?因为我编写DLL不是为了在DELPHI中调用而是在其它语言中调用,看DELPHI中写DLL的前面的注释中有一句需要在USES中第一个加入ShareMem单元,我也加了,都无济于事,但是在DELPHI程序中调用就可以,不知道是怎么回事。<br>&nbsp; &nbsp; 具体的代码参见如下:<br>//调试语句为:rundll32.exe DllCode.dll,ShowMsg TestString<br>library DLLCode;<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; ShareMem,<br>&nbsp; SysUtils,<br>&nbsp; Classes,<br>&nbsp; Dialogs;<br><br>{$R *.RES}<br>//以下几种方式均报错<br>//procedure ShowMsg( B : String );stdcall;<br>//procedure ShowMsg( B : WideString );stdcall;<br>//procedure ShowMsg( B : ShortString );stdcall;<br>&nbsp; procedure ShowMsg( B : PChar );stdcall;<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage( B );<br>&nbsp; end;<br><br>{<br>//以下几种方式不报错<br>//第一种是在代码中不使用参数B<br>//procedure ShowMsg( B : String );stdcall;<br>//procedure ShowMsg( B : WideString );stdcall;<br>//procedure ShowMsg( B : ShortString );stdcall;<br>&nbsp; procedure ShowMsg( B : PChar );stdcall;<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage( '123' );<br>&nbsp; end;<br><br>//第二种是使用参数B的类型不是字符串型<br>&nbsp; procedure ShowMsg( B : Integer );stdcall;<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage( IntToStr( B ) );<br>&nbsp; end;<br><br>}<br><br>exports<br>&nbsp; ShowMsg;<br>begin<br><br>end.<br>
 
甚麼語言調用?出甚麼錯?procedure改為function看看,也可以試試把ShowMessage改為標準的WinAPI看看,如:MessageBoxA。
 
PowerBuilder调用,好像问题不出在ShowMessage上,因为下面几种都行。
 
我已经知道了,原来这些传入的参数都是命令行参数,应该用ParamStr去取。
 

Similar threads

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