(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. Ubuntu Server 16.04下ASP.NET Core Web Api + MySql + Dapper在 Jexus、nginx 下的简单测试

    一.环境及工具 1.服务器 VirtualBox5.1.4 安装 Ubuntu Server 16.04 amd64 MySql Ver 14.14 Distrib 5.6.21 Jexus 5.8. ...

  2. ms sql 2005和2008收缩日志的方法

    步骤1: 2005的sql 语句为:back up log 数据库名称 with no_log 目的:截断数据库日志 2008的sql 语句为:alter database 数据库名称 set rec ...

  3. QTableWidget的美化

      FriendTable->setFrameShape(QFrame::NoFrame);  //设置边框 FriendTable->setHorizontalHeaderLabels( ...

  4. 【C#】第3章学习要点(一)--整体把握

    分类:C#.VS2015 创建日期:2016-06-18 使用教材:(十二五国家级规划教材)<C#程序设计及应用教程>(第3版) 一.使用别人已经设计好的类简化你的代码编写工作量 当让你去 ...

  5. Web Api中的get传值和post传值

    GET 方式 get方式传参 我们一般用于获取数据做条件筛选,也就是 “查” 1.无参 var look = function () { $.ajax({ type: "GET", ...

  6. jquery基本选择器匹配多个元素

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. Firemonkey 移动平台 Form 显示使用 ShowModal 范例

    procedure TForm1.Button1Click(Sender: TObject); begin Form2 := TForm2.Create(Self); Form2.ShowModal( ...

  8. [转]JavaScript程序编码规范

    原文:http://javascript.crockford.com/code.html 作者:Douglas Crockford 译文:http://www.yeeyan.com/articles/ ...

  9. android 网络通讯

    //get方式请求网络数据 String urlPath="http://192.168.98.112:8080/CloudMusicPlayer/fragment1_1_lv2/json/ ...

  10. Visual Studio Code 使用 Typings 实现智能提示功能

    前言 我们知道在IDE中代码的智能提示几乎都是标配,虽然一些文本编辑器也有一些简单的提示,但这是通过代码片段提供的.功能上远不能和IDE相比.不过最近兴起的文本编辑器的新锐 Visual Studio ...