本文介绍了将字符串作为引用类型从C ++/CLI传递到C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个C ++/CLI函数,该函数调用本机C ++函数,将字符串作为参考传递,如下所示:
I have a C++/CLI funtion that calls the native C++ function passing strings as reference as follows:
bool ConnectionsMgr::GetRespHeader([Out] String^ %eTimestamp,
[Out] String^ %UTimestamp,[Out] int% nCount)
{
bool bRet = true;
int resultCount = 0;
char* expTime;
char* lastUpdatedTime ;
//calling C++ function, I to pass the char* as reference
lMgr->getResponseHeader(expTime, lastUpdatedTime , resultSCount) ;
eTimestamp = gcnew String(expTime);
UTimestamp = gcnew String(lastUpdatedTime);
nSidsCount = resultSCount;
return bRet;
}
C ++函数看起来像这样
The C++ function looks like this
bool CLMgr::getResponseHeader(char *eTimestamp, char *UTimestamp, int &nSCount){
int nCnt = 0;
if(m_Response) {
eTimestamp = timestampToNewString(m_Response->m_eTime);
UTimestamp = timestampToNewString(m_Response->m_UTime);
for( int n = 0; n < m_Response->m_Count; n++){
if(bflag)
nCnt++;
}
}
nSCount = nCnt;
return true;
}
我必须将eTimestamp,UTimestamp,SCount的值转换为C#代码.我在做这些事情时做错了什么.在执行完C ++函数后,我什至没有得到它.
预先表示感谢.
I have to get the value of eTimestamp, UTimestamp, SCount to my C# Code. What am I doing wrong to get these values. I am not even getting it after executing out of the C++ function.
Thanks in advance.
推荐答案
for( int n = 0; n < m_Response->m_Count; n++){
if(bflag)
nCnt++;
}
//This does the same exact thing (which doesn''t make sense why you''re making a copy of a variable either but...)
if(bflag) nCnt = m_Response->m_Count;
这篇关于将字符串作为引用类型从C ++/CLI传递到C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!