Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Char 将字符*转换为包含特殊字符的BSTR*_Char_Character_Bstr - Fatal编程技术网

Char 将字符*转换为包含特殊字符的BSTR*

Char 将字符*转换为包含特殊字符的BSTR*,char,character,bstr,Char,Character,Bstr,我正在尝试将char*转换为BSTR*,而我的char*中有特殊字符,无法进行加密。我曾尝试过在web上找到的几种方法,但在调用vb代码时,我总是得到一些不同的结果。我很确定这和特殊角色有关,因为如果我没有这些角色的话,看起来没问题 我的代码是这样的 _export myFunction(BSTR *VBtextin, BSTR *VBpassword, BSTR *VBtextout, FPINT encrypt) { BSTR password = SysAllocString (*VBp

我正在尝试将char*转换为BSTR*,而我的char*中有特殊字符,无法进行加密。我曾尝试过在web上找到的几种方法,但在调用vb代码时,我总是得到一些不同的结果。我很确定这和特殊角色有关,因为如果我没有这些角色的话,看起来没问题

我的代码是这样的

_export myFunction(BSTR *VBtextin, BSTR *VBpassword, BSTR *VBtextout, FPINT encrypt) {

BSTR password = SysAllocString (*VBpassword);
char* myChar;
myChar = (char*) password  //is this ok to cast? it seems to remain the same when i print out.

//then I encrypt the myChar in some function...and want to convert back to BSTR
//i've tried a few ways like below, and some other ways i've seen online...to no avail.

_bstr_t temp(myChar);
SysReAllocString(VBtextout, myChar);
任何帮助都将不胜感激


谢谢

如果要操作缓冲区,可能不希望直接操作char*。先复印一份:

_export myFunction(BSTR *VBtextin, BSTR *VBpassword, BSTR *VBtextout, FPINT encrypt) {

  UINT length = SysStringLen(*VBpassword) + 1;
  char* my_char = new char[length];
  HRESULT hr = StringCchCopy(my_char, length, *VBpassword);
如果所有这些都成功了,请执行转换。也要确保根据自己的情况处理故障

  if (SUCCEEDED(hr)) {
    // Perform transformations...
  }
然后复制回:

  *VBtextout = SysAllocString(my_char);
  delete [] my_char;
}

另外,请阅读。

您到底想做什么?你想把VB和C代码连接起来吗?是的……没错……VB代码正在调用C代码……然后返回到VB代码。你找到这个问题的解决方案了吗?