Windows 编程中的字符串(2)
(1)windows写日志系统
void writeDebugEventLog(TCHAR* pszMessage, WORD wType)
{
//#ifdef _DEBUG HANDLE hEventSource = NULL;
const TCHAR* lpszStrings[] = { NULL, NULL }; hEventSource = RegisterEventSourceW(NULL, L"DeviceMonitorService");
if (hEventSource)
{
lpszStrings[] = _T("DeviceMonitorService");
lpszStrings[] = pszMessage; ReportEvent(hEventSource, // Event log handle
wType, // Event type
, // Event category
, // Event identifier
NULL, // No security identifier
, // Size of lpszStrings array
, // No binary data
lpszStrings, // Array of strings
NULL // No binary data
); DeregisterEventSource(hEventSource);
}
//#else
//#endif // DEBUG
}
(2)将字符串写入数组
TCHAR szMessage[];
ZeroMemory(szMessage, ARRAYSIZE(szMessage));
StringCchPrintf(szMessage, ARRAYSIZE(szMessage),
_T("[Win32Project1 ]monitorId %s , attached DisplayDevice.DeviceID : %s IsLocalMonitor %d"), monitorId, aDisplayDevice.DeviceID, IsLocalMonitor);
writeDebugEventLog(szMessage, EVENTLOG_ERROR_TYPE);
注:
StringCchPrintf function (Strsafe.h)
Writes formatted data to the specified string. The size of the destination buffer is provided to the function to ensure that it does not write past the end of this buffer.
StringCchPrintf is a replacement for the following functions:
sprintf (<stdio.h>)
(3)TCHAR与string转换(std::string为char类型的字符集合)
string TCHAR2STRING(TCHAR* STR){
int iLen = WideCharToMultiByte(CP_ACP, , STR, -, NULL, , NULL, NULL);
char* chRtn = new char[iLen*sizeof(char)];
WideCharToMultiByte(CP_ACP, , STR, -, chRtn, iLen, NULL, NULL);
std::string str(chRtn);
return str;
}
注:
string
Header: <string> ——c++ 标准库头文件
Namespace: std
|
A type that describes a specialization of the template class basic_string with elements of type char as a string. |
|
|
A type that describes a specialization of the template class basic_string with elements of type wchar_t as a wstring. |
char字符串转换成Unicode 字符串
LPWSTR pwszOut = NULL;
if (value != NULL)
{
// // Double NULL Termination
int nOutputStrLen = MultiByteToWideChar(CP_ACP, , value, -, NULL, );//获取char字符串的长度,包括空串的长度
pwszOut = new TCHAR[nOutputStrLen]; memset(pwszOut, , nOutputStrLen);
MultiByteToWideChar(CP_ACP, , value, -, pwszOut, nOutputStrLen);
}
(4)各类数据结构
typedef _Null_terminated_ CONST WCHAR *LPCWSTR, *PCWSTR;
typedef LPCWSTR PCTSTR, LPCTSTR; ——winnt.h
(5)各类字符串函数
strrchr, wcsrchr,_tcsrchr——
Header: stdio.h, string.h.
Scan a string for the last occurrence of a character.
example: (_tcsrchr(cmd, _T('\\')))[1] = 0;
lstrcat—— include Windows.h
Appends one string to another.
memset —— #include <memory.h> #include <stdio.h>
Sets buffers to a specified character.
void *memset( void *dest, int c, size_t count );
| Routine | Required Header | Compatibility |
| memset | <memory.h> or <string.h> | ANSI, Win 95, Win NT |
Windows 编程中的字符串(2)的更多相关文章
- Windows编程中UNICODE和_UNICODE定义问题
Windows编程中UNICODE和_UNICODE定义问题 先转一篇文章: 初学Windows SDK编程时碰到过这个问题,相信很多初学Windows编程的人也都碰到过,后来慢慢搞明白些了,但有时别 ...
- Windows 编程中恼人的各种字符以及字符指针类型
在Windows编程中,很容易见到这些数据类型:LPSTR,LPTSTR,LPCTSTR... 像很多童鞋一样,当初在学Windows编程的时候,对着些数据类型真的是丈二和尚,摸不着头脑,长时间不用就 ...
- windows编程中的数据类型
在windows编程中,有许多奇怪的数据类型,初学者不知道这些代表什么,下面就把一些数据类型列出如下: ATOM 原子(原子表中的一个字符串的参考) BOOL 布尔变量 BOOLEAN 布尔变量 BY ...
- Windows编程中char*转LPCWSTR解决的方法总结
Windows编程中常常涉及到的一个问题是字符串之间的转换,开发过程总是遇到编译器提示无法格式转换的问题.于是自己总结了几种解决的方法. 1.通过T2W转换宏 char* szStr = " ...
- 资源在windows编程中的应用----菜单
资源在Windows编程中的应用 资源 加速键.位图.光标.对话框.菜单.字符串.工具条 1.菜单的创建 菜单由以下组成部分: (1)窗口主菜单条 (2)下拉式菜单框 (3)菜单项热键标识 (4)菜单 ...
- Windows编程中的若干难点 - Windows程序设计(SDK)007
Windows编程中的若干难点 让编程改变世界 Change the world by program 一个窗口的生与死 我记得有童鞋会问:如果我的程序需要在关闭前让用户判断是否确定要关闭窗口,我应该 ...
- Windows编程中各种操作文件的方法
windows编程中文件操作有以下几种常见方法:1.C语言中文件操作.2.C++语言中的文件操作.3.Win32 API函数文件操作.4.MFC CFile类文件操作.5.MFC CFileDialo ...
- Windows编程中回调函数的使用心得(MFC篇)
回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用来调用其所指向的函数时,我们就说这是回调函数.回调函数不是由该函数的实现方直接调用,而是在特定 ...
- 第七章 资源在Windows编程中的应用 P157 7-8
资源在基于SDK的程序设计中的应用实验 一.实验目的 1.掌握各种资源的应用及资源应用的程序设计方法. 二.实验内容及步骤 实验任务 1.熟悉菜单资源的创建过程: 2.熟悉位图资源的创建: 3.熟 ...
随机推荐
- 【c#搬砖记】用Docx导出word格式的docx文件
DocX开源网址:http://docx.codeplex.com/ 1.引入DocX.dll 调用ReplaceText()方法替换模板中的字符.只支持docx格式的word文档 using (Do ...
- 浅谈Oracle中物理结构(数据文件等。。。)与逻辑结构(表空间等。。。。。)
初始Oracle时很难理解其中的物理结构和逻辑结构,不明白内存中和硬盘中文件的区别和联系,我也是初学Oracle,这里就简单的谈谈我我看法. 首先,你需要明白的一点是:数据库的物理结构是由数据库的操作 ...
- MVC之前的那点事儿系列(5):Http Pipeline详细分析(下)
文章内容 接上面的章节,我们这篇要讲解的是Pipeline是执行的各种事件,我们知道,在自定义的HttpModule的Init方法里,我们可以添加自己的事件,比如如下代码: public class ...
- Android接收短信
Android收到短信时会广播android.provider.Telephony.SMS_RECEIVED消息,因此只要定义一个Receiver,收听该消息,就能接收短信. <receiver ...
- hdu-4496-D-City
D-City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
- opencart 后台导航菜单添加步骤
1,找到在catalog\language\english\common\header.php // Text$_['text_affiliate'] = 'Affiliates';$_['text_ ...
- 跨平台日志清理工具 Log-Cutter v2.0.1 RC-1 发布
Log-Cutter 是JessMA开源组织开发的一个简单实用的日志切割清理工具.对于服务器的日常维护来说,日志清理是非常重要的事情,如果残留日志过多则严重浪费磁盘空间同时影响服务的性能.如果用手工方 ...
- ubuntu 安装配置ssh
1.安装ssh-server sudo apt-get install openssh-server 2.设置管理员密码访问 sudo vim /etc/ssh/sshd_config 将“Permi ...
- Uploadify 上传插件引起Chrome崩溃解决方法
将Uploadify初始化代码延时加载,可解决Chrome崩溃. setTimeout(initUploadify, 60); function initUploadify() { var $Uplo ...
- js的一些属性
js attribute(): setAttribute():element.setAttribute(name,balue) getAttribute():element.getAttribute( ...