社区
资源
帖子详情
VC在调用BCB写的一个DLL的函数(参数为string&时发生错误,请大家帮忙解决。
qiong12
2005-03-13 06:48:47
我在BCB中的导出函数的参数为一个标准的C++的STRING,如:
void GetS(string &s)
{
return "hello the world";
}
结果在VC这边调用执行到时会抱错。
实在想不懂,请各位帮忙一下。
...全文
77
3
打赏
收藏
VC在调用BCB写的一个DLL的函数(参数为string&时发生错误,请大家帮忙解决。
我在BCB中的导出函数的参数为一个标准的C++的STRING,如: void GetS(string &s) { return "hello the world"; } 结果在VC这边调用执行到时会抱错。 实在想不懂,请各位帮忙一下。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
hotel9545
2005-03-15
打赏
举报
回复
是void 类型怎么又return "hello the world";?
应该是
string GetS(string &s)
{
return "hello the world";
}
晨星
2005-03-13
打赏
举报
回复
要么你在dll到处函数中不要使用C++特性,或许还会好一些。
晨星
2005-03-13
打赏
举报
回复
这应该是正常现象吧。一般的DLL不像COM组件,后者有统一的二进制标准。
黄历日期
DLL
组件 支持Delphi
VC
VB 完全免费
黄历日期
DLL
组件 版本:1.0 开发:小焱软件 网址:http://www.zystudios.cn
函数
说明: 输出
函数
原型:AlmanacOutPut(LicenseKey:
string
;Y,M,D:integer);
参数
说明: LicenseKey:授权密钥,
请
输入zystudios.cn Y,M,D分别为年月日 返回类型:PChar字符串,以"/"分割 返回
错误
说明: invalid date:日期
错误
,有效范围1901-1-1至2099-12-31 License Key Error:授权密钥
错误
,
请
输入 zystudios.cn 本组件对于个人使用完全免费,
请
在使用过程中遵守三方协议,如需应用商业,
请
联系作者! 本组件有完整的Delphi,
VC
和
BCB
调用
例子,VB,.net,java也可以
调用
,这里就不给出例子了O(∩_∩)O 任何建议欢迎反馈 2009年12月21日
实战delphi
dll
的创建和
调用
library fun
dll
; { 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
string
s as parameters or function results. This applies to all
string
s 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 Short
String
parameters. } uses ShareMem, // ShareMem 一定放第
一个
Windows, Messages, SysUtils, math, strutils, registry , StdCtrls, ExtCtrls, ADODB, DB,dateutils,Dialogs; // fucs in 'fucs.pas'; const INPASSSTR='89ABCDEFGcdefghijkHIJ%^KLMN0123opqrstuOP -_\|/?@#$&*' ; //切记:Library 的名字大小
写
没关系,可是
DLL
-Func的大小
写
就有关系了。 // 在
DLL
-Func-Name
写
成MyMax与myMAX是不同的。如果
写
错了,立即的结果是你
调用
到此
DLL
的AP根本开不起来。 //
参数
的大小
写
就没关系了。甚至不必同名。如原型中是 (X,Y:integer)但引用
时
写
成(A,B:integer),那是没关系的。 //切记:要再加个stdcall。书上讲,如果你是用Delphi
写
DLL
,且希望不仅给 Delphi-AP也希望
BCB
/
VC
-AP等使用的话,那你最好加个Stdcall ; //
参数
型态:Delphi有很多种它自己的变量型态,这些当然不是
DLL
所喜欢的,Windows/
DLL
的母语应该是C。所以如果要传进传出
DLL
的
参数
,我们尽可能照规矩来用。这两者
写
起来,后者会麻烦不少。如果你对C不熟的话,那也没关系。我们以后再讲。 //3.将这些可共享的Func送出
DLL
,让外界﹝就是你的Delphi-AP啦﹞使用: //光如此,你的AP还不能用到这些,你还要加个Exports才行。 代码: //=============比较大小的
函数
=============== Function MyMax ( X , Y : integer ) : integer ; stdcall ; //stdcall 可以让
BCB
/
VC
-AP等使用的 begin if X > Y then Result := X else Result := Y ; end ; //==============加密======================= function Inpass(s:
string
):
string
; stdcall ; var i:integer; passstr,dd:
string
; begin for i:=1 to length(s) do begin dd:=inttohex(ansipos(s[i],inpassstr),4); if dd='0000' then begin result:='0';exit end; passstr:=passstr+dd ; end; Result :=passstr; end; //==============解密======================= function Outpass(s:
string
):
string
;stdcall ; var pass,dd:
string
; i,leng:integer; begin leng:= floor(length(s)/4); pass:=''; for i:=1 to leng do begin dd:=ansimidstr(s,(i-1)*4+1,4); if strtoint('$'+dd)=0 then begin result:='0';exit;end; if strtoint('$'+dd)>78 then begin result:='0'; exit end; pass:=pass+ansimidstr(inpassstr,strtoint('$'+dd),1) ; end; Result :=pass ; end; //==========test========================= function jsjyh(strym:
string
):
string
;stdcall; var newstr1,he,oldstr:
string
; tj:boolean; i:integer; begin i:=1; he:=''; tj:=true; // 取出要参与校验和计算的字符串给oldstr if (length(strym) mod 2)0 then begin showmessage('你输入的源码个数有错,不能是奇数个,
请
重输入!'); exit; end; oldstr:=trim(strym); while tj=true do begin newstr1:=copy(oldstr,i,2); oldstr:=copy(oldstr,i+2,length(oldstr)-2); //开始计算校验和并给he变量 if he='' then begin he:=inttohex(strtointdef('$'+newstr1,16)+ strtointdef('$'+'00',16),2); he:=rightstr(he,2); end else begin he:=inttohex(strtointdef('$'+newstr1,16)+ strtointdef('$'+he,16),2); he:=rightstr(he,2); end; if length(oldstr) =0 then tj:=false; end; result:=strym+he; end; //============================================== {$R *.RES} //将这些可共享的Func送出
DLL
,让外界﹝就是你的Delphi-AP啦﹞使用: //光如此,你的AP还不能用到这些,你还要加个Exports才行。 代码: exports MyMax,Inpass,Outpass,jsjyh; begin end.
BCB
6
调用
C#
DLL
BCB
6
调用
C#
DLL
最近项目涉及第三方接口
调用
。第三方是用C#实现的WCF服务。而我们的程序是使用的
BCB
6开发。因此,打算将与WCF的通讯包含在C#的类库中,给
BCB
6
调用
。
BCB
6 是无法直接
调用
C#的
DLL
,但可以通过C#编
写
一个
COM组件,然后
BCB
调用
这个COM组件来
调用
。 用C#编
写
COM 大体步骤是 新建
一个
类库项目
C#
调用
C++
DLL
传递结构体数组的终极
解决
方案
在项目开发
时
,要
调用
C++封装的
DLL
,普通的类型C#上一般都对应,只要用
Dll
Import传入从
DLL
中引入
函数
就可以了。但是当传递的是结构体、结构体数组或者结构体指针的
时
候,就会发现C#上没有类型可以对应。这
时
怎么办,第一反应是C#也定义结构体,然后当成
参数
传弟。然而,当我们定义完
一个
结构体后想传递
参数
进去
时
,会抛异常,或者是传入了结构体,但是返回值却不是我们想要的,经过调试跟踪后发现,那些值
BCB
编
写
dll
转载
一.注意: 创建动态链接库
时
,如果想你创建的动态链接库并非只用于Borland开发工具,那么就需要遵循发下规则: (1).在导出
函数
的返回值和
参数
中不要使用Borland特有的数据类型和结构体,如Ansi
String
之类,
请
使用C/C++标准的数据类型或使用 C/C++标准数据类型定义的结构体(特别不要使用
String
数据类型,
BCB
DLL
向导生成的
DLL
工程文件中大篇幅的说明就是对此的说明
资源
2,586
社区成员
18,442
社区内容
发帖
与我相关
我的任务
资源
VC/MFC 资源
复制链接
扫一扫
分享
社区描述
VC/MFC 资源
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章