(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

string

A type that describes a specialization of the template class basic_string with elements of type char as a string.

wstring

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.

  Warning  Do not use. Consider using StringCchCat instead. See Security Considerations.
 
      lstrcat(cmd, _T("***.exe"));
 
 
     lstrcpy(id, buff);
 
(6)其它函数
    ZeroMemory macro—— (include Windows.h)

memset  —— #include <memory.h> #include <stdio.h>

Visual Studio 6.0

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)的更多相关文章

  1. Windows编程中UNICODE和_UNICODE定义问题

    Windows编程中UNICODE和_UNICODE定义问题 先转一篇文章: 初学Windows SDK编程时碰到过这个问题,相信很多初学Windows编程的人也都碰到过,后来慢慢搞明白些了,但有时别 ...

  2. Windows 编程中恼人的各种字符以及字符指针类型

    在Windows编程中,很容易见到这些数据类型:LPSTR,LPTSTR,LPCTSTR... 像很多童鞋一样,当初在学Windows编程的时候,对着些数据类型真的是丈二和尚,摸不着头脑,长时间不用就 ...

  3. windows编程中的数据类型

    在windows编程中,有许多奇怪的数据类型,初学者不知道这些代表什么,下面就把一些数据类型列出如下: ATOM 原子(原子表中的一个字符串的参考) BOOL 布尔变量 BOOLEAN 布尔变量 BY ...

  4. Windows编程中char*转LPCWSTR解决的方法总结

    Windows编程中常常涉及到的一个问题是字符串之间的转换,开发过程总是遇到编译器提示无法格式转换的问题.于是自己总结了几种解决的方法. 1.通过T2W转换宏 char* szStr = " ...

  5. 资源在windows编程中的应用----菜单

    资源在Windows编程中的应用 资源 加速键.位图.光标.对话框.菜单.字符串.工具条 1.菜单的创建 菜单由以下组成部分: (1)窗口主菜单条 (2)下拉式菜单框 (3)菜单项热键标识 (4)菜单 ...

  6. Windows编程中的若干难点 - Windows程序设计(SDK)007

    Windows编程中的若干难点 让编程改变世界 Change the world by program 一个窗口的生与死 我记得有童鞋会问:如果我的程序需要在关闭前让用户判断是否确定要关闭窗口,我应该 ...

  7. Windows编程中各种操作文件的方法

    windows编程中文件操作有以下几种常见方法:1.C语言中文件操作.2.C++语言中的文件操作.3.Win32 API函数文件操作.4.MFC CFile类文件操作.5.MFC CFileDialo ...

  8. Windows编程中回调函数的使用心得(MFC篇)

    回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用来调用其所指向的函数时,我们就说这是回调函数.回调函数不是由该函数的实现方直接调用,而是在特定 ...

  9. 第七章 资源在Windows编程中的应用 P157 7-8

    资源在基于SDK的程序设计中的应用实验 一.实验目的 1.掌握各种资源的应用及资源应用的程序设计方法.   二.实验内容及步骤 实验任务 1.熟悉菜单资源的创建过程: 2.熟悉位图资源的创建: 3.熟 ...

随机推荐

  1. Gson操作json

    github:https://github.com/google/gson API:http://google.github.io/gson/apidocs/ 示例对象 package present ...

  2. 记一次串口通信调试,慎用SerialPort.Close

    做项目是遇到了串口通信,真是遇到了一个大坑,不知道是微软的坑还是我的坑. 让我慢慢道来完整的经历. 项目中以前是vb 写的,是vb与vb 之间进行串口通信,现在改成C#和之前的vb程序进行串口通信. ...

  3. 损失函数(Loss Function) -1

    http://www.ics.uci.edu/~dramanan/teaching/ics273a_winter08/lectures/lecture14.pdf Loss Function 损失函数 ...

  4. 修复 XE7 update1 发布 iOS 8.x 实机问题

      1. 开启工程目录下面的 Entitlement.TemplateiOS.xml 档案. 2. 加入二行: <key>application-identifier</key> ...

  5. 解决 com.sun.*包导入错误

    解决 com.sun.*包导入错误 com.sun.image.codec.jpeg.*导入错误如何解决: com.sun.*是受限制访问的API,Eclipse 默认把受访问限制的API设成了ERR ...

  6. 2015暑假多校联合---Cake(深搜)

    题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...

  7. Scalaz(37)- Free :实践-DB Transaction free style

    我一直在不断的提示大家:FP就是Monadic Programming,是一种特殊的编程风格.在我们熟悉的数据库编程领域能不能实现FP风格呢?我们先设计一些示范例子来分析一下惯用的数据库编程过程: i ...

  8. MAC使用CocoaPods

    前言,還是那句話,按照濤叔下面畫黃色的步驟順序執行就好了 使用CocoaPods兩種方式:使用之前安裝的插件&命令行. 一.利用插件 1.創建項目后添加CocoaPods 2.在文本框中輸入如 ...

  9. 「轉」Java的内存机制

    0.参考资料: http://www.j2megame.org/index.php/content/view/2246/125.html 1.Java的内存机制 Java 把内存划分成两种:一种是栈内 ...

  10. 【视频处理】YV12ToARGB

    前面提到了YV12转RGB的各种实现方法和优化方法,主要是CPU上的实现.本文主要介绍基于GPU的YV12转RGB的实现. 1. 基于OpenGL的实现 利用OpenGL shader实现将YV12转 ...