| 
					阅读:2321回复:2
				 中间带NULL字符的BSTR怎么处理
					#include "stdafx.h" #include "atlbase.h" #include <stdio.h> int main(int argc, char* argv[]) { OLECHAR temp[5]; temp[0]='A'; temp[1]=0; temp[2]='D'; temp[3]='E'; temp[4]='F'; BSTR bstrText = SysAllocStringLen(temp, 5); int a = SysStringLen(bstrText)+1; char *ansistr = new char[a]; memset(ansistr,0,a); ::WideCharToMultiByte(CP_ACP, 0, bstrText, -1, ansistr, a, NULL, NULL); for(int i=0;i<a;i++) printf("%.2lx ",ansistr); printf("\n"); SysFreeString(bstrText); return 0; } 显示结果是 41 00 00 00 00 00 而不是 41 00 44 45 46 00 要怎么做才能得到后面的结果? | |
| 
 | 
| 沙发#发布于:2008-05-23 13:34 
					printf等函数是通过\0来判断字符串结束的。如果要打印中间带有\0的字符串,需要当作两个字符串来打印				 | |
| 板凳#发布于:2008-05-21 16:36 
					for(int i=0;i<a;i++) printf("%.2lx ",ansistr); 这对了吗? | |
 
							
 
				 
				