delphi不是说的很清楚吗?你没看啊?Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters.
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters.
解决方案 »
- delphi 里怎么实现联合?
- exe 调用 bpl 时,datamodule 出现 CoInitialize尚未被呼叫 的错误,请问是什么原因呢?
- 小调查,承诺加到200分,谢谢大家
- 刷新image控件时出现闪烁问题
- 怎樣在dbgrid讓中一個網格的值等於同一列其它兩個網格的和
- 高手请进,这个字符表达式是不是不对啊?
- 高难度:如何禁止删除指定的文件或文件夹.
- 请大家关注Delphi版务管理专题
- TField.EditMask设置只输入两位小时加两位分钟格式问题?
- 挑战高难度!这个问题怎么解决?
- 关于证券之星的编程(超级难题)
- 小菜急需 socket 或 网吧管理 delphi方面的资料,哪位仁兄能雪中送炭????
我在使用过程发现,它是必须完全 配的,不知对否,总之我使用时,用这种方法解决过
var
V_String: string;procedure SetString(mStr: PChar);
begin
V_String := string(mStr);
end;function GetString: PChar;
begin
Result := PChar(V_String);
end;excetps
SetString,
GetString;
end.//Unit or Project
type
TSetString = procedure(mStr: PChar); stdcall;
TGetString = function: PChar; stdcall;var
vHandle: THandle
vStr: string;
begin
vHandle := LoadLibrary('XXX.dll');
vStr := '我是一个字符串';
TSetString(GetProcAddress('SetString'))(PChar(vStr));
ShowMessage(string(TGetString(GetProcAddress('GetString'))));
FreeLibrary(vHandle);
end;
如果不是,则一定要用PChar,因为String是Delphi专有的,C/C++不识别,会出乱子的。