vs2005非托管方式调用webservice

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”)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值