Tag:const style pre div receive strcpy [] vsp enc
Structural Body typedef struct tagnet_ehome_xml_remote_ctrl_param{ dword dwsize; void* lpinbuffer; // Control parameter Buffer dword dwinbuffersize; //control parameter buffer length dword dwsendtimeout; //data Send time-out, unit MS, default 5s dword dwrecvtimeout; //data receive time-out, unit MS, default 5s void * lpoutbuffer; //Output Buffers DWORD dwOutBufferSize; //Output buffer size void *lpstatusbuffer; //state buffer, if not required, can be reset to null dword dwstatusbuffersize; //State Buffer Size BYTE &NBSP;BYRES[16];} Method of net_ehome_xml_remote_ctrl_param, *lpnet_ehome_xml_remote_ctrl_param;//conversion Bool a2utf8 (const char* pcont,&Nbsp;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} no extra Parameters */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 execution failed delete[] pbuffw;pbuffw = null;return false;} Int ilen = widechartomultibyte (cp_utf8, 0, pbuffw, inum - 1, null , null, null, null);if (ilen <= 0) {//multibytetowidechar execution failed delete[] Pbuffw;pbuffw = null;return false;} if ((dworD) (Ilen) > dwoutsize) {delete[] pbuffw;pbuffw = null;return false;} /*lint -e{119} no extra parameter */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 execution failed 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;} Change to 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);D word dwseq = 0; struxmlcfg.lpoutbuffer = &dwseq;struxmlcfg.dwoutbuffersize = 4;char szstatus[1000 ] = { 0 };struxmlcfg.lpstatusbuffer = szstatus;struxmlcfg.dwstatusbuffersize = 1000;//need to convert the string field to Utf-8a2utf8 ((char*) struxmlcfg.lpinbuffer, (char*) Struxmlcfg.lpinbuffer, 1500, &struxmlcfg.dwinbuffersize); struxmlcfg.dwsize = sizeof (Net_ehome_xml_remote_ctrl_param); struXMLCfg.dwRecvTimeOut = 30 * 1000;
C + + to C #