在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
//结构体 typedef struct tagNET_EHOME_XML_REMOTE_CTRL_PARAM { DWORD dwSize; void* lpInbuffer; //控制参数缓冲区 DWORD dwInBufferSize; //控制参数缓冲区长度 DWORD dwSendTimeOut; //数据发送超时时间,单位ms,默认5s DWORD dwRecvTimeOut; //数据接收超时时间,单位ms,默认5s void *lpOutBuffer; //输出缓冲区 DWORD dwOutBufferSize; //输出缓冲区大小 void *lpStatusBuffer; //状态缓冲区,若不需要可置为NULL DWORD dwStatusBufferSize; //状态缓冲区大小 BYTE byRes[16]; }NET_EHOME_XML_REMOTE_CTRL_PARAM, *LPNET_EHOME_XML_REMOTE_CTRL_PARAM; //转换的方法 BOOL A2UTF8(const char* pCont, char* pOut, DWORD dwOutSize, DWORD* pOutLen) { if (pCont == NULL) { if (pOutLen != NULL) { *pOutLen = (DWORD)0; } return TRUE; } if (pOut == NULL) { return FALSE; } int iNum = MultiByteToWideChar(CP_ACP, NULL, pCont, -1, NULL, NULL); /*lint -e{119} 没有多余参数*/ wchar_t* pBuffw = new(std::nothrow) wchar_t[(DWORD)iNum]; if (pBuffw == NULL) { return FALSE; } if (MultiByteToWideChar(CP_ACP, NULL, pCont, -1, pBuffw, iNum) <= 0) { //MultiByteToWideChar执行失败 delete[] pBuffw; pBuffw = NULL; return FALSE; } int iLen = WideCharToMultiByte(CP_UTF8, 0, pBuffw, iNum - 1, NULL, NULL, NULL, NULL); if (iLen <= 0) { //MultiByteToWideChar执行失败 delete[] pBuffw; pBuffw = NULL; return FALSE; } if ((DWORD)(iLen) > dwOutSize) { delete[] pBuffw; pBuffw = NULL; return FALSE; } /*lint -e{119} 没有多余参数*/ char* pLpsz = new char[(DWORD)iLen]; if (pLpsz == NULL) { delete[] pBuffw; pBuffw = NULL; return FALSE; } if (WideCharToMultiByte(CP_UTF8, 0, pBuffw, iNum - 1, pLpsz, iLen, NULL, NULL) <= 0) { //WideCharToMultiByte执行失败 delete[] pBuffw; pBuffw = NULL; delete[] pLpsz; pLpsz = NULL; return FALSE; } memset(pOut, 0, dwOutSize); memcpy(pOut, pLpsz, (DWORD)iLen); if (pOutLen != NULL) { *pOutLen = (DWORD)iLen; } delete[] pBuffw; pBuffw = NULL; delete[] pLpsz; pLpsz = NULL; return TRUE; } //改成C#的 CString strInputXml; strInputXml.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"\ "<PPVSPMessage>\r\n"\ "<Version>4.0</Version>\r\n"\ "<Sequence>1</Sequence>\r\n"\ "<CommandType>REQUEST</CommandType>\r\n"\ "<Method>CONTROL</Method>\r\n"\ "<Command>UPLOADPIC</Command>\r\n"\ "<Params>\r\n"\ "<Chan>1</Chan>\r\n"\ "<Filename>%s</Filename>\r\n"\ "</Params>\r\n"\ "</PPVSPMessage>", csFileName); NET_EHOME_XML_REMOTE_CTRL_PARAM struXMLCfg = { 0 }; char szInBuffer[1500] = { 0 }; strcpy(szInBuffer, strInputXml); struXMLCfg.lpInbuffer = szInBuffer; struXMLCfg.dwInBufferSize = sizeof(szInBuffer); DWORD dwSeq = 0; struXMLCfg.lpOutBuffer = &dwSeq; struXMLCfg.dwOutBufferSize = 4; char szStatus[1000] = { 0 }; struXMLCfg.lpStatusBuffer = szStatus; struXMLCfg.dwStatusBufferSize = 1000; //需要将字符串字段转换成UTF-8 A2UTF8((char*)struXMLCfg.lpInbuffer, (char*)struXMLCfg.lpInbuffer, 1500, &struXMLCfg.dwInBufferSize); struXMLCfg.dwSize = sizeof(NET_EHOME_XML_REMOTE_CTRL_PARAM); struXMLCfg.dwRecvTimeOut = 30 * 1000; |
请发表评论