#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'