bcb动态库传递 string 参数问题

yangshunjun 2007-02-13 10:14:43
在 BCB中将string参数传递给动态库时,string参数的长度大于128时出现异常,用devcpp没有这种现象,不知道是什么原因?怎么解决啊?
...全文
396 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
勉励前行 2007-02-15
  • 打赏
  • 举报
回复
如果參數用的是std::string,編譯DLL及調用DLL都該使用同一版本的編譯器才行。

用char * 才具有通用性。std::string不存在限制128個字符的問題。

kangji 2007-02-15
  • 打赏
  • 举报
回复
我刚才试了一下,确实有楼主所说的问题,呵呵
BeRoy 2007-02-15
  • 打赏
  • 举报
回复
佩服PPower(月亮光光,照地堂) 的专业 :)
yangshunjun 2007-02-14
  • 打赏
  • 举报
回复
传的不是AnsiString,是c++标准库的 string。
i_love_pc 2007-02-14
  • 打赏
  • 举报
回复
fastmm是什么东东??
找来看看先
constantine 2007-02-14
  • 打赏
  • 举报
回复
建议使用fastmm,这样就简单多了,可以直接传
yangshunjun 2007-02-14
  • 打赏
  • 举报
回复
是用bcb编译,用bcb调用。
用devcpp编译的动态库没有那种问题,用bcb编译的就有那种问题,不知道是不是bcb的问题。用引用方式传递参数可以解决这个问题,只是感觉不太爽!
kangji 2007-02-14
  • 打赏
  • 举报
回复
是这样的,DLL开头一般都有说明
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
Maconel 2007-02-14
  • 打赏
  • 举报
回复
如果dll是bcb编译的,我没有经验,不过多半应该没有问题。
如果dll是其他编译器编译的,而用bcb来调用,那么不能在接口中传递类参数,参数或返回值都不行,因为他们在编译的时候对类内存的分配是不一样的,比如虚函数表。
老沙 2007-02-14
  • 打赏
  • 举报
回复
c++本来并没有STRING,STRING是一个类,可以理解为char的指针,在C和C++的DLL中传递STRING用char*
xiaoshi0 2007-02-13
  • 打赏
  • 举报
回复
由于AnsiString是VCL中的类,所以在用在DLL接口的时候,必须要求MEMMGR.LIB库的支持。这个库是Borland的静态库。
rainfall19831109 2007-02-13
  • 打赏
  • 举报
回复
楼主可以去查看下以前的帖子

都提出了好多遍说在DLL中,参数不要使用String类型(DLL的主文件注释都有说明了),而应该使用char*传递,并且确保char*的内存在调用的一方分配

13,822

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧