(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. ASP.NET MVC PartialView用法

    子页面AreaSelect.cshtml页面的Controller代码: public ActionResult AreaSelect() { return PartialView(); } 父页面前 ...

  2. ASP.NET MVC 网站开发总结(七)——C#操作图片:多张图的拼接(旋转)

    其实用C#来操作图片的拼接就是在用Graphic画图.个人感觉还是挺有趣的,各种类库提供了丰富多彩的功能. 源代码(移植到一个简单的C#程序中,并没有放在ASP.NET项目中): using Syst ...

  3. SSH服务器与Android通信(2)--Android客户端接收数据

    基本原理是Android客户端通过HttpClient向服务器发出请求,服务器向Android客户端返回JSON字符串,Android客户端解析JSON字符串获得数据. 1. 新建一个Android项 ...

  4. 基于TCP和多线程实现无线鼠标键盘-Robot

    Windows端收到Android端传递来的键盘或鼠标操作信息以后,需要根据这些信息操作鼠标或键盘,这就需要用到java.awt.Robot类,该类用于控制鼠标或键盘. 在Java主窗体中定义: pu ...

  5. android FragmentActivity+FragmentTabHost+Fragment框架布局

    这周比较闲,计划系统的学习一下android开发,我本是一名IOS程序员,对手机开发还是有自己的一套思路的, 固这套思路用到我当前学android上了,先选择从Main页面的tabbar部分代码入手, ...

  6. Java面试题汇总(一)

    1.谈谈你对http中post和get访问的理解. http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认 为: ...

  7. 编译安装rabbitmq服务端

    有一种方式是:下载rabbitmq-server-generic-unix压缩包,是不用编译的.是已经编译好的源码了 下面介绍编译源码安装   总括: 需要以下步骤:   1.安装erlange.因为 ...

  8. 2014年物联网Internet of Things应用简介

    body{ font: 16px/1.5em 微软雅黑,arial,verdana,helvetica,sans-serif; }         物联网(Internet of Things,缩写I ...

  9. Java final自变量

    Java 1.1 允许我们将自变量设成final 属性,方法是在自变量列表中对它们进行适当的声明.这意味着在一个方法的内部,我们不能改变自变量句柄指向的东西.如下所示: /** * Created b ...

  10. 第二章 部署war包到tomcat

    以turbine为例. 一.部署 1.下载或者生成war包(从maven上下载war包,并改名字为turbine.war) 2.将turbine.war拷贝到$TOMCAT_HOME/webapps中 ...