soapkit3.0,中的列子用vs2005非托管方式调用的例子,注意BSTR和char之间的转换例子代码 // console2.cpp : 定义控制台应用程序的入口点。// #include "stdafx.h" #include comutil.h #pragma comment(lib, "comsup
soapkit3.0,中的列子用vs2005非托管方式调用的例子,注意BSTR和char之间的转换例子代码
// console2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <comutil.h>
#pragma comment(lib, "comsuppw.lib")
#pragma comment(lib, "kernel32.lib")
#include <Locale.h>
using namespace MyMath;
int _tmain(int argc, _TCHAR* argv[])
{
::CoInitialize(NULL);
//CMyMathT<> a;
CMyMath a;
double b;
a.AddNumbers(3,6,&b);
CString str;
BSTR bstrA=::SysAllocString(L"tan谭");
BSTR bstrB=NULL;
a.EchoString(bstrA,&bstrB);
// printf("return message is:%s",()bstrB);
setlocale(LC_ALL,"chs");
wprintf_s(L"return message is %s\n",bstrB);
char * lpszText=_com_util::ConvertBSTRToString(bstrB);
printf(lpszText);
delete lpszText;
::SysFreeString(bstrA);
if(bstrB!=NULL){
printf("release message.\n");
::SysFreeString(bstrB);
printf("谭ddd");
}
//a.EchoString(
printf("%f",b);
printf("\t-?\t\t\t\tFor Help\n");
printf("中文测试\n");
//setlocale(LC_ALL,"zh_CN.UTF-8");
setlocale(LC_ALL,"chs");
wprintf(L"中文测试\n");
printf("w0:%ls\n",L"中文测试");
wprintf(L"w1:%s\n",L"1中文测试 宽字符");
wprintf(L"w2:%ls\n",L"2中文测试 宽字符");
wprintf(L"w3:%ls\n",L"3tDirectory 中文测试 宽字符 end");
wprintf(L"w4:%S\n",L"4 中文测试 宽字符 end");
printf("w5:%S\n",L"中文测试\n");
getchar();
::CoUninitialize();
return 0;
}
下边为常用的关于字符的处理方法
vc6一般为多字节编码,如果想要unicode,要改:工程>设置>c/c++>预处理程序定义>去掉_MBCS,加入
:_UNICODE,UNICODE;工程>设置>link>output>Entry point加入wWinMainCRTStartup
为了兼容ansi,unicode常用函数改为 strcpy,strlen,strcat-> _tcscpy,_tcslen,_tcscat或lstrcpy,lstrlen,lstrcat printf,sprintf->_tprintf,_tsprintf “xxxx”-> _T(“xxxx”)