vc 如何char数组转换DWORD
_T宏是定义字符串常量用的,char型字符串转换为WCHAR型字符串是用MultiByteToWideChar,MSDN中有例子,如果用MFC,可以用A2T宏来实现char型字符串向TCHAR型字符串转换。
最好程序中都使用TCHAR,这样通常不需要做转换。
http://hi.baidu.com/ybear2008/blog/item/5d529cdb95da1361d0164eac.html
字符串和DWORD类型之间如何相互转换
再把 dword转为字符串的也发出来void HashToString(char *strHash,SHA1 hash,int iSize) //hash转成字符串{uchar *p=(uchar *)&hash;char tmp[3]={0};for (int j=0;j{sprintf(tmp,"%02X",(uchar)p[j]);//OutputDebugString(tmp);strcat(strHash,tmp);}//OutputDebugString(strHash);}
不能将参数 1 从“DWORD *
看下边这个吧,刚才那个似乎不对,先声明一个_variant_t类型的对象,然后条用如下函数。
就是这样:_variant a; a.SetString("source string"); 这是函数的说明 _variant_t::SetString Microsoft Specific void SetString( const char* pSrc ) throw( _com_error ); Parameter pSrc pointer to the character string Remarks Converts an ANSI character string to a Unicode BSTR string and assigns it to this _variant_t object._variant_t Microsoft Specific A _variant_t object encapsulates theVARIANT data type. The class manages resource allocation and deallocation, and makes function calls to VariantInit and VariantClear as appropriate.#include Compiler COM Support Class Overview Construction _variant_t Constructs a _variant_t object. Operations Attach Attaches a VARIANT object into the _variant_t object. Clear Clears the encapsulated VARIANT object. ChangeType Changes the type of the _variant_t object to the indicated VARTYPE. Detach Detaches the encapsulated VARIANT object from this _variant_t object. SetString Assigns a string to this _variant_t object. Operators operator = Assigns a new value to an existing _variant_t object. operator ==, != Compare two _variant_t objects for equality or inequality. Extractors Extract data from the encapsulated VARIANT object. 不要用哪个空间了,直接用下边的代码进行串口操作吧。
你要是非得用,我可以给你发过去,需要找下具体是怎么写的。
** 打开端口名称 ** */ string it_comm("\\\\.\\"); try { it_comm.append("COM1"); hCom = CreateFile(it_comm.c_str() , GENERIC_READ | GENERIC_WRITE , 0 , NULL , OPEN_EXISTING , 0 , NULL ); if (hCom == INVALID_HANDLE_VALUE) { throw bad_exception((it_comm + ":打开串口失败").c_str()); } //设置波特率、校验位等 commcfg.dcb.BaudRate = uiBaudRate; commcfg.dcb.ByteSize = 8; commcfg.dcb.Parity = NOPARITY; commcfg.dcb.StopBits = ONESTOPBIT; commcfg.dcb.fBinary = TRUE; commcfg.dcb.fDtrControl = DTR_CONTROL_DISABLE; commcfg.dcb.fRtsControl = DTR_CONTROL_DISABLE; //CommConfigDialog(it_comm->c_str(), NULL, &commcfg); /* * * 应用新的串口配置 */ fSucc = SetCommConfig(hCom, &commcfg, (DWORD)sizeof(commcfg));/* * * 发送数据 */ fSucc = WriteFile(hCom , buf , (DWORD)buf_length , &lenw , NULL ); if (!fSucc) { throw bad_exception((szCommPortName + ":发送失败").c_str()); }/* * * 读取数据 */ fSucc = ReadFile(hCom , buf , (DWORD)buf_length , &lenr , NULL ); if (!fSucc) { throw bad_exception((szCommPortName + ":读取失败").c_str()); }
字符串和DWORD类型之间如何相互转换
展开全部 再把 dword转为字符串的也发出来void HashToString(char *strHash,SHA1 hash,int iSize) //hash转成字符串{uchar *p=(uchar *)&hash;char tmp[3]={0};for (int j=0;j<iSize;j++){sprintf(tmp,"%02X",(uchar)p[j]);//OutputDebugString(tmp);strcat(strHash,tmp);}//OutputDebugString(strHash);}...
VC DWORD类型能不能转换成LPCTSTR型
//将CString 型IP地址在IPAddressCtrl中显示 CString strIP="192.168.1.1"; DWORD dwIP; dwIP = inet_addr(strIP); unsigned char *pIP = (unsigned char*)&dwIP; m_ipAddr.SetAddress(*pIP, *(pIP+1), *(pIP+2), *(pIP+3)); //将IPAddressCtrl中的IP地址获得并转换成CString型 unsigned char *pIP; CString strIP; DWORD dwIP; m_ipAddr.GetAddress(dwIP); pIP = (unsigned char*)&dwIP; strIP.Format("%u.%u.%u.%u",*(pIP+3), *(pIP+2), *(pIP+1), *pIP); 参考别人的,可以借鉴下。
转载请注明出处51数据库 » dword转换char