R
redleaf_wgm
Unregistered / Unconfirmed
GUEST, unregistred user!
我想了解DELPHI编写的DLL是否是标准的DLL,在DELPHI编写DLL时使用字符串参数时使用什么类型比较合适呀?我试过String、WideString、ShortString、PChar等都不行,在运行时通过RUNDLL32.EXE调用时都报错,请问是什么原因呢?因为我编写DLL不是为了在DELPHI中调用而是在其它语言中调用,看DELPHI中写DLL的前面的注释中有一句需要在USES中第一个加入ShareMem单元,我也加了,都无济于事,但是在DELPHI程序中调用就可以,不知道是怎么回事。<br> 具体的代码参见如下:<br>//调试语句为:rundll32.exe DllCode.dll,ShowMsg TestString<br>library DLLCode;<br><br>{ Important note about DLL memory management: ShareMem must be the<br> first unit in your library's USES clause AND your project's (select<br> Project-View Source) USES clause if your DLL exports any procedures or<br> functions that pass strings as parameters or function results. This<br> applies to all strings passed to and from your DLL--even those that<br> are nested in records and classes. ShareMem is the interface unit to<br> the BORLNDMM.DLL shared memory manager, which must be deployed along<br> with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> using PChar or ShortString parameters. }<br><br>uses<br> ShareMem,<br> SysUtils,<br> Classes,<br> 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> procedure ShowMsg( B : PChar );stdcall;<br> begin<br> ShowMessage( B );<br> 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> procedure ShowMsg( B : PChar );stdcall;<br> begin<br> ShowMessage( '123' );<br> end;<br><br>//第二种是使用参数B的类型不是字符串型<br> procedure ShowMsg( B : Integer );stdcall;<br> begin<br> ShowMessage( IntToStr( B ) );<br> end;<br><br>}<br><br>exports<br> ShowMsg;<br>begin<br><br>end.<br>