char* 转 BSTR

char* s1 = "zhangsan";
CString s2 = CString(s1);
BSTR s3 = s2.AllocSysString();

char* 转 LPCWSTR

char* a = "a.jpg";
WCHAR b[256];
memset(b, 0, sizeof(b));
MultiByteToWideChar(CP_ACP, 0, a, strlen(a) + 1, b, sizeof(b) / sizeof(b[0]));

long 转 char*

// param[0]: long,要转换的数字
// param[1]: char *,转换后指向字符串的指针
// param[2]: 进制
ltoa(age, "age is ", 10);

char* 转 CStringA

char* ch1 = "中文测试123";
CStringA str(ch1);

CStringA 转 char*

CStringA str = L"";
char* ch2 = new char[str.GetLength()+1];
memset(ch2, 0, str.GetLength()+1);
strcpy(ch2, str.GetString());
delete ch2;

CString 转 BSTR

CString a = "abc";
BSTR b = a.AllocSysString();

wchar_t * 转 char *

wchar_t buffer[MAX_PATH];
BOOL result = SHGetSpecialFolderPath(0, buffer, CSIDL_LOCAL_APPDATA, false);
wcscat(buffer, L"\\GPR.log"); int iSize;
char* pszMultiByte; //返回接受字符串所需缓冲区的大小,已经包含字符结尾符'\0'
iSize = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL);
pszMultiByte = (char*)malloc(iSize * sizeof(char));
WideCharToMultiByte(CP_ACP, 0, buffer, -1, pszMultiByte, iSize, NULL, NULL);

string 转 BSTR

#include <string>
#include <comutil.h>
#pragma comment(lib, "comsuppw.lib") std::string a = "hello world";
_bstr_t bstr_t(a.c_str());
BSTR res_bstr = bstr_t.GetBSTR();

BSTR 转 string

#include <string>
#include <comutil.h>
#pragma comment(lib, "comsuppw.lib") BSTR s = L"hello world";
_bstr_t bstr_t(s);
std::string str(bstr_t);

QString 转 BSTR

方法一:

QString qstr;
BSTR bstr = SysAllocString((OLECHAR*)qstr.unicode());

方法二:

BSTR str = (BSTR)(LPCWSTR)qstr.data();

QString 转 char*

// 方法一
QString str;
char* ch;
QByteArray ba = str.toLatin1();
ch = ba.data(); // 方法二
std::string str = QString("zhangsan").toStdString();
const char* ch = str.c_str();

BSTR 转 QString

方法一:

QString Demo::bstrToqstring(BSTR bstr)
{
char buf[260] = { 0 };
int len = WideCharToMultiByte(CP_ACP, 0, bstr, wcslen(bstr), NULL, 0, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, bstr, wcslen(bstr), buf, len, NULL, NULL);
return QString(buf);
}

方法二:

// 获取并显示友好名称
WCHAR *aa = EloamGlobal_GetFriendlyName(1, 0);
QString s = QString::fromWCharArray(aa);

方法三:

BSTR data = EloamGlobal_GetBarcodeData(0x02);
QString str_InvocrNo = QString::fromStdWString(data);

char * 、BSTR、long、wchar_t *、LPCWSTR、string、QString、CStringA类型转换的更多相关文章

  1. 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换 [转]

    本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下. #ifndef USE_H_ #define USE_H_ # ...

  2. 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换

    本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下-复制代码 代码如下:    #ifndef USE_H_     ...

  3. CString char BSTR 转换

     关于字符集不一的历史原因,可以参考: UNICODE与ANSI的区别 以下是网上转载的资料.我将辅以自己的实例,说明并总结关系. 一.CString, int, string, char*之间的转换 ...

  4. wchar_t*转换string

    场景 wchar[]转换string 实现代码 #include "stdafx.h" #include <iostream> #include <windows ...

  5. char[]转换成wchar_t的转换方法(GNU Libc规定wchar_t为32位)

    wchar_t是C/C++的字符数据类型,是一种扩展的字符存储方式,wchar_t类型主要用在国际化程序的实现中,但它不等同于unicode编码.unicode编码的字符一般以wchar_t类型存储. ...

  6. int与string之间的类型转换--示例

    package demo; public class IntDemo { public static void main(String[] args) { // String-->int 类型转 ...

  7. Date、String和Timestamp类型转换

    1.String与Date类型转换: 1.获取当前系统时间: Date date1 = new Date();   //获取系统当前时间 Calendar cal = Calendar.getInst ...

  8. Java,mysql String与date类型转换

    String 与 date类型转换 字符串转换成日期类型: SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");//小写 ...

  9. TCHAR和CHAR类型的互转,string 转lpcwstr

    https://www.cnblogs.com/yuguangyuan/p/5955959.html 没有定义UNICODE,所以它里面的字符串就是简单用" "就行了,创建工程的时 ...

  10. System::String *,char*,string 等的类型转换 [转]

    在VC 的编程中,经常会用到各种类型的转换,在MFC中textbox等控件得到的返回类型是System::String *,而写入的文件要求是 const char *类型的,下面介绍一些转换的方法: ...

随机推荐

  1. 【Application Insights】使用CURL命令向Application Insgihts发送测试数据

    问题描述 在使用App Service或者Kubernetes等服务时,需要收集一些日志数据并且发送到Application Insights中,当使用SDK或者是服务自带的Application I ...

  2. 【Azure K8S | AKS】在中国区AKS上遇见ImagePullBackOff时的替代方案

    问题描述 在AKS集群中部署calico时候,遇见 ImagePullBackOff 问题. 在创建POD calico-typha-horizontal-autoscale 时候遇见拉取镜像失败问题 ...

  3. 【Azure 环境】Windows中安装Python azure-eventhub-checkpointstoreblob-aio模块时出错 ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory:

    问题描述 在使用Python代码接受EventHub的消息时,根据文档要求安装azure-eventhub-checkpointstoreblob-aio模块时,出现了如下错误: ERROR: Cou ...

  4. 【Azure 应用服务】Azure Function HTTP Trigger 遇见奇妙的500 Internal Server Error: Failed to forward request to http://169.254.130.x

    问题描述 使用 Azure Funciton App,在本地运行完全成功的Python代码,发布到Azure Function就出现了500  Internal Server Error. 而且错误消 ...

  5. 二: sql模式(sql_mode)

    # sql_mode 1 介绍 sql_mode 会影响 MySQL支持的SQL语法以及它执行的数据验证检查.通过设置sql_mode,可以完成不同严格程度 的数据校验,有效地保障数据准确性. MyS ...

  6. Java 属性赋值的先后顺序

    1 package com.bytezero.circle; 2 /** 3 * 4 * @Description 5 * @author Bytezero·zhenglei! Email:42049 ...

  7. SPFA最短路

    目录 从Bellman-Ford开始 核心思想 模拟算法执行过程 时间复杂度 模板 spfa spfa优化的思想 模板 从Bellman-Ford开始 对于所有边权都大于等于0的图,任意两个顶点之间的 ...

  8. Server-side template injection 模板注入问题总结

    概念: 服务器模板注入(Server-side template injection) 攻击者能够使用本地的模板语法去注入一个恶意的payload,然后在服务器端执行该攻击,当与欧股直接输入数据到模板 ...

  9. Nginx的负载均衡策略(4+2)

    Nginx的负载均衡策略主要包括以下几种: 轮询(Round Robin):每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除.这是Nginx的默认策略,适合服务器配置 ...

  10. 手把手的使用Toolkit插件在诗情画意中完成AI诗朗诵

    本文分享自华为云社区<[云驻共创]手把手的使用Toolkit插件在诗情画意中完成AI诗朗诵>,作者: 红目香薰. 云原生时代,开发者们的编程方式.编程习惯都发生了天翻地覆的变化,大家逐渐地 ...