windows下wchar_t* 转char*
Windows char
2023-09-11 14:19:35 时间
这个在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.
下面是我写的一个测试,是根据项目改过来的:
1 #include <windows.h> 2 #include <string.h> 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <boost/filesystem.hpp> 6 7 namespace bfs = boost::filesystem; 8 9 10 bool get_path(char *file_name,size_t size){ 11 12 13 char ownPth[MAX_PATH]; 14 15 HMODULE hModule = GetModuleHandle(NULL); // Will contain exe path,When passing NULL to GetModuleHandle, it returns handle of exe itself 16 if (hModule != NULL) 17 { 18 GetModuleFileNameA(hModule,ownPth, MAX_PATH); // 19 } 20 else 21 ownPth[0]=0; 22 23 bfs::path iic_file(ownPth); 24 iic_file = iic_file.parent_path() / "dlp_usb.iic" ; //For releaseing 25 26 if( !bfs::is_regular_file(iic_file)) 27 { 28 printf("\r\nError,open 68013 iic file fail\r\n"); 29 return false ; 30 } 31 32 33 wcstombs(file_name,iic_file.c_str(),size); 34 35 //memcpy(file_name,iic_file.c_str(),byte_count); 36 37 return true; 38 39 } 40 41 int main(){ 42 43 char iic_file[512]; 44 45 if(get_path( iic_file,512)){ 46 47 printf("TRUE\n"); 48 } 49 50 return 0; 51 }
references:
http://msdn.microsoft.com/en-us/library/5d7tc9zw.aspx
http://blog.163.com/tianshi_17th/blog/static/4856418920085209414977/
相关文章
- Windows下Nginx的启动、停止等命令&Nginx 配置多域名&windows下设置Nginx开机自动启动
- Windows CMD输出文本到文件,不加换行符
- 使用FFmpeg进行屏幕录像和录音(Windows,Linux,MacOS)
- Unity3D开发Windows Store应用程序 注意事项
- 华为超聚变2288H V5 服务器安装Windows系统后 PCI数据捕获和信号处理控制器 出现感叹号
- EasyDSS RTMP流媒体解决方案之Windows服务安装方案
- 路径分隔符不一致,导致windows下不能开发
- Error -27492: "HttpSendRequest" failed, Windows error code=12152 (invalid server response) and retry。。。
- C++ 调用windows系统DOS命令的函数 system(char* command)
- MFC Windows 程序设计[八]之判断九宫格内
- 使用pscp命令将windows系统里的文件传送到远程服务器
- Windows 映射模式
- Windows和linux双系统——改动默认启动顺序
- WINDOWS.H already included. MFC apps must not #include <Windows.h>
- 开源ext2read代码走读之-在windows下怎样推断有几个硬盘设备?
- docker cobbler批量部署Linux/windows系统(一)——筑梦之路
- Windows关机/重启命令
- 我的学习笔记_Windows_HOOK编程 2009-12-03 11:19
- Windows命令行使用FTP——windows下自带ftp命令