110,533
社区成员
发帖
与我相关
我的任务
分享
struct SrvInfo
{
string strSrvAddress;
int iSrvPort;
}
SrvInfo m_arrSrvInfos[1]; //里面已经存了1个SrvInfo类型的元素
void fnGetSrvInfos( SrvInfo *pInfo, int iLen )
{
if ( NULL == pInfo )
{
return;
}
for ( int i = 0; i < iLen; ++i )
{
pInfo[i] = m_arrSrvInfos[i];
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SrvInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 27)]
public string strSrvAddress;
int iSrvPort;
}
[DllImport("test.dll", EnrtyPoint="fnGetSrvInfos")]
public static extern void GetSrvInfos( SrvInfo[] arrSrvInfos, int iLen );
int iLen = 1;
SrvInfo[] info = new SrvInfo[iLen];
for ( int i = 0; i < info.Length; ++i )
{
info[i] = new SrvInfo();
}
GetSrvInfos( info, iLen ); //但是info没有得到C++中m_arrSrvInfos的数据 怎么办?
struct SrvInfo
{
TCHAR strSrvAddress[27]; //<-- 不能用std::string
int iSrvPort;
};