VC编写返回值是字符串,以及有引用型变量为参数的DLL

#include "stdafx.h"
#include "string.h"
#include   <string>
using std::string;

extern "C" __declspec(dllexport) char* __stdcall Encryption(char *as_password, char *as_key ,char* as_ret)
{
 string a  , b  ,c;
 char *d;
 a = as_password;
 b = as_key;
 c = a + b;
 d = new char[strlen(c.c_str())+1];
 strcpy(d,c.c_str());

 //as_ret = new char[strlen(c.c_str())+1]; //这句不要,需要在函数调用前进行初始化长度,只能大于等级于c.c_str()+1的长度
 strcpy(as_ret,c.c_str());
 return d;
}

 

这个函数可以正确的返回相加后的值,如这样调用

PB中定义function string Encryption(string pass, string key,ref string as_ret) Library "XX.dll" Alias for 'Encryption;ansi'

执行:

a = Encryption('123','456',b)

结果:

a = '123456'

b = '123456'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值