这个在windows下很常见,常用,留个档。

一般用这个函数:

size_t wcstombs(
char *mbstr,
const wchar_t *wcstr,
size_t count
); mbstr

The address of a sequence of multibyte characters.

wcstr

The address of a sequence of wide characters.

count

The maximum number of bytes that can be stored in the multibyte output string.

locale

The locale to use.

下面是我写的一个测试,是根据项目改过来的:

 #include <windows.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <boost/filesystem.hpp> namespace bfs = boost::filesystem; bool get_path(char *file_name,size_t size){ char ownPth[MAX_PATH]; HMODULE hModule = GetModuleHandle(NULL); // Will contain exe path,When passing NULL to GetModuleHandle, it returns handle of exe itself
if (hModule != NULL)
{
GetModuleFileNameA(hModule,ownPth, MAX_PATH); //
}
else
ownPth[]=; bfs::path iic_file(ownPth);
iic_file = iic_file.parent_path() / "dlp_usb.iic" ; //For releaseing if( !bfs::is_regular_file(iic_file))
{
printf("\r\nError,open 68013 iic file fail\r\n");
return false ;
} wcstombs(file_name,iic_file.c_str(),size); //memcpy(file_name,iic_file.c_str(),byte_count); return true; } int main(){ char iic_file[]; if(get_path( iic_file,)){ printf("TRUE\n");
} return ;
}

references:

http://msdn.microsoft.com/en-us/library/5d7tc9zw.aspx

http://blog.163.com/tianshi_17th/blog/static/4856418920085209414977/

windows下wchar_t* 转char*的更多相关文章

  1. C++ WINDOWS下 wchar_t *和char * 相互转化总结篇

    说道wchar_t和char两个类型大家都不会陌生 wchar_t:在windows下是Unicode 16编码,也就是俗称宽字节 char:当然就是指一个字节,在windows下面默认是gbk编码的 ...

  2. windows下wchar_t的问题

    使用vs新建工程或者编译工程的时候默认在编译设置里面讲wchar_t设置为内置类型,如下图: 但是在编译相互依赖的工程的时候,如果有的工程不将wchar_t设置为内置类型的时候,将会出现链接错误,需要 ...

  3. wchar_t是内置还是别名(亲测有效:wchar_t在windows下是16位整数的别名,在linux等平台下是32位整数的别名。MSVC2008开始默认是/Zc:wchar_t)

    接前一篇C++ ABI之名字改编(以Qt为例),继续看看C++名字改编相关的问题. 问题 MSVC 有一对选项/Zc:wchar_t- 与 /Zc:wchar_t控制wchar_t 于是 wchar_ ...

  4. 【404】int main(int argc,char * argv[]) windows 下的使用

    参考:int main(int argc,char * argv[]) windows 下的使用 参考:Theprogram can't start because libgcc_s_dw2-1.dl ...

  5. char 转wchar_t 及wchar_t转char

    利用WideCharToMultiByte函数来转换,该函数映射一个unicode字符串到一个多字节字符串.通常适合于window平台上使用. #include <tchar.h> #in ...

  6. windows下捕获dump

         一般要捕获异常只需要两个函数:SetUnhandledExceptionFilter截获异常:MiniDumpWriteDump写dump文件.但是由于CRT函数可能会在内部调用SetUnh ...

  7. CString向char类型转化 ---“=”: 无法从“wchar_t *”转换为“char *

    此文从网上复制过来,原文出处已丢失,望见谅哈       VC 2005中,这个本来很简单的问题又稍微复杂了一点.    在工程里面,一个必不可少的步骤就是把CString转换为shar*字符串.通过 ...

  8. 二、Windows 下 ShellCode 编写初步

    第二章.Windows 下 ShellCode 编写初步 (一)shellcode 定义:最先的 Shell 指的是人机交互界面,ShellCode 是一组能完成我们想要的功能的机器代码,通常以十六进 ...

  9. windows下 jemalloc编译

    准备 Windows下使用VS2015进行编译,需要使用cmake构建版本.(如果有cygwin,在其中执行VS的vcvarsall.bat后使用"CC=cl ./autogen.sh&qu ...

随机推荐

  1. PowerShell文件系统(一)前言

    PowerShell文件系统(一)前言 3 12 2月, 2014  在 Powershell tagged Powershell教程 / 别名 / 文件系统 by Mooser Lee PowerS ...

  2. Linux CentOS 7 YouCompleteMe相关配置。

    CentOS 6.5上面弄了2天,以失败告终!!!当作练手了.在网上看到一篇CentOS7.0上安装YouCompleteMe插件的文章,就重新在虚拟机上安装了一个CentOS7,按那个文章执行了一下 ...

  3. Android 开机启动通知

    效果图: 学习: 1.静态注册实现开机启动 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLET ...

  4. Linux更换python版本 (转载)

    安装完CentOS6.5(Final)后,执行#Python与#python -V,看到版本号是2.6,而且之前写的都是跑在python3.X上面的,3.X和2.X有很多不同,有兴趣的朋友可以参考下这 ...

  5. struts的ognl.NoConversionPossible错误

    JSP页面便利集合的时候,代码如下 <s:iterator value="storageList" id="stList" status="st ...

  6. Python安装MySQLdb并连接MySQL数据库

    当然了,前提是你已经安装了Python和MySQL.我的Python是2.6版本的. Python2.6的“Set”有点兼容性问题,自己照着改一下: http://sourceforge.net/fo ...

  7. mysql学习之五:sql语句学习3

    好吧,大家认为这样的字体还是比較好看,全部我们就换这样的字体了. INSERT INTO 语句用于向表格中插入新的行. 语法 INSERT INTO 表名称 VALUES (值1, 值2,....) ...

  8. [Redux] Passing the Store Down Explicitly via Props

    n the previous lessons, we used this tool to up level variable to refer to the Redux chore. The comp ...

  9. Leetcode_num3_Same Tree

    题目: Given two binary trees, write a function to check if they are equal or not. Two binary trees are ...

  10. Android Xfermode 实战 实现圆形、圆角图片

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/42094215,本文出自:[张鸿洋的博客] 1.概述 其实这篇本来准备Androi ...