繁体   English   中英

将字符串从R传递到C ++

[英]Passing strings from R to C++

我正在尝试在R中使用某些C ++函数。我已将所有C ++函数放置在DLL中。 我的R代码是

#load the c++ DLL
dyn.load("PathToDLL\\MyCPlusPlus.dll")    
#call the C++ function from R
a <- .C("MyFunc",as.character("Hello world"))

我的C ++ DLL函数是

char ** _stdcall MyFunc(char ** strInput)
{
 //display the string received from R
 MessageBox(NULL, LPCWSTR(*strInput), L"C++ program", NULL);
 return strInput;
}

我遇到的问题是,在消息框中显示时,我从R传递到C ++的字符串受到了干扰。 有没有人有过将R中的字符串传递给C ++的经验,如果可以,您能指出我正确的方向吗?

谢谢

编辑:我也尝试过使用char *代替char **,如下所示,但是没有运气

char * _stdcall MyFunc(char * strInput)
    {
     //display the string received from R
     MessageBox(NULL, LPCWSTR(strInput), L"C++ program", NULL);
     return strInput;
    }

看起来您DLL中的字符串是宽字符(16位),而传递的字符串是简单的ASCII字符。 尝试将字符串显示为ASCII字符。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM