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. JAVA对象的生命周期(二)-对象的创建

    目录 对象创建的几种方式 类加载检查. 内存分配 初始化零值 设置对象头 执行init方法 对象创建的几种方式 new clone newInstance 反序列化 String s = " ...

  2. 【Azure 应用服务】App Service 通过门户配置数据库连接字符串不生效 

    应用设置 Application Setting 在应用服务中,应用设置是作为环境变量传递给应用程序代码的变量. 对于 Linux 应用和自定义容器,应用服务使用 --env 标志将应用设置传递到容器 ...

  3. 树莓派修改根文件系统为f2fs

    目录 前言 操作简述 我的实际操作步骤 1. 准备 2. 查看树莓派分区信息 3. 备份根分区 4. 格式化树莓派TF卡根分区为f2fs文件系统 5.恢复备份 前言 在TF卡.固态硬盘之类的nand存 ...

  4. 图查询语言 nGQL 简明教程 vol.01 快速入门

    本文旨在让新手快速了解 nGQL,掌握方向,之后可以脚踩在地上借助文档写出任何心中的 NebulaGraph 图查询. 视频 本教程的视频版在B站这里. 准备工作 在正式开始 nGQL 实操之前,记得 ...

  5. gitlab推送代码触发jenkins构建

    预期:推送devloop或者master分支的代码, 自动执行jenkins 发布测试环境 首先,jenkins中需要安装如下插件 打开一个任务配置,构建触发器中勾选"Build when ...

  6. Lua中pair和ipair的区别

    Lua中pair和ipair的区别? 二者都是Lua中内置的迭代器,可以对数组或table进行遍历. 在正常的数组或table的遍历中,二者没有区别. tableNormal={"this& ...

  7. gyroflow.xyz - 视频防抖 支持相机 gopro 不支持手机视频 - 软件推荐

    gyroflow.xyz - 视频防抖 支持相机 gopro 不支持手机视频 - 软件推荐 https://gyroflow.xyz/ https://github.com/gyroflow/gyro ...

  8. Rancher 2.5.x 证书过期报错 x509: certificate has expired or is not yet valid 解决方案

    Rancher 的证书过期会出现什么状况?不可以继续通过Rancher UI访问你的集群 查看Rancher Server日志报错:x509: certificate has expired or i ...

  9. B站上传视频时各分辨率最佳的码率及格式参数

    相关链接:表格源文件

  10. python面向对象编程(封装、隐藏)

    一 封装 1.封装介绍封装是面向对象三大特性最核心的一个特性封装<----->整合2.将封装的属性进行隐藏操作1).如何隐藏:在属性名前加__前缀,就会实现一个对外隐藏属性效果该隐藏需要注 ...