zoukankan      html  css  js  c++  java
  • unicode 转码 ansi

    #include "stdafx.h"
    #include <Windows.h>
    #include <stdio.h>

    HRESULT SomeCOMFunction(BSTR *bstr)
    {
    *bstr = ::SysAllocString(L"你好,软件测试,lenmom");
    return S_OK;
    }

    int _tmain(int argc, _TCHAR* argv[])
    {
    BSTR unicodestr = 0;
    char *ansistr=NULL;
    SomeCOMFunction(&unicodestr);
    int lenW = ::SysStringLen(unicodestr);
    int lenA = ::WideCharToMultiByte(CP_ACP, 0, unicodestr, lenW, 0, 0, NULL, NULL);
    if (lenA > 0)
    {
    ansistr = new char[lenA + 1]; // allocate a final null terminator as well
    ::WideCharToMultiByte(CP_ACP, 0, unicodestr, lenW, ansistr, lenA, NULL, NULL);
    ansistr[lenA] = 0; // Set the null terminator yourself

    FILE *fp;

    if((fp = fopen("d:\111.vbs", "wb+"))==NULL) {
    printf("Cannot open file. ");
    exit(1);
    }
    else
    {
    fputs(ansistr, fp);
    }

    fclose(fp);
    }
    else
    {
    // handle the error
    }

    //...use the strings, then free their memory:
    if(ansistr!=NULL)
    delete[] ansistr;
    ::SysFreeString(unicodestr);

    return 0;
    }

  • 相关阅读:
    php函数总结
    文本框输入限制
    e.keyCode和e.which使用
    transform总结
    wampSever的mysql操作
    linux命令总结
    nginx总结
    微雪的stm32学习资料
    串口+RS485驱动
    cubemx+stm32串口学习汇总资料
  • 原文地址:https://www.cnblogs.com/lenmom/p/3995317.html
Copyright © 2011-2022 走看看