window驱动字符串操作

///////////////////////////////////////////////////////////////////////////////
///
/// Copyright (c) 2014 - <company name here>
///
/// Original filename: strTest.cpp
/// Project          : strTest
/// Date of creation : 2014-06-19
/// Author(s)        : <author name(s)>
///
/// Purpose          : <description>
///
/// Revisions:
///  0000 [2014-06-19] Initial revision.
///
///////////////////////////////////////////////////////////////////////////////

// $Id$

#ifdef __cplusplus
extern "C" {
#endif
#include <ntddk.h>
#include <string.h>
#ifdef __cplusplus
}; // extern "C"
#endif

#include "strTest.h"


VOID DriverUnload(
    IN PDRIVER_OBJECT		DriverObject
    )
{
	KdPrint(("DriverUnload..."));
}

#ifdef __cplusplus
extern "C" {
#endif
NTSTATUS DriverEntry(
    IN OUT PDRIVER_OBJECT   DriverObject,
    IN PUNICODE_STRING      RegistryPath
    )
{
   
	//////////////////////////////////////////////////////////////////////////


	KdPrint(("DriverEntry.....\n"));

	KdPrint(("%d\n",123));
	KdPrint(("%c\n",'a'));
	KdPrint(("%C\n",L'b'));


	LARGE_INTEGER l = RtlConvertLongToLargeInteger((LONG)0x12ab);
	KdPrint(("LARGE_INTEGER::%d\n",l));

	KdPrint(("%s","assiiiii\n"));
	KdPrint(("%S",L"WTCHAR\n"));
	KdPrint(("0x%x\n",0xAcdf));
	KdPrint(("0x%X\n",0xAcdf));


	//ansi 
	ANSI_STRING asInit;
	RtlInitAnsiString(&asInit,"this is a ansi ansi_string...");
	KdPrint(("print:%Z\n",&asInit));
	KdPrint(("print:%s\n",asInit.Buffer));

	//init
	UNICODE_STRING usInit;
	RtlInitUnicodeString(&usInit,L"RtlUnicodeStringInit...");
	KdPrint(("usInist:%wZ\n",&usInit));
	KdPrint(("usInist:%ws\n",usInit.Buffer));

	//alloc mem
	UNICODE_STRING usAllocMem;
	usAllocMem.MaximumLength = 1024;
	usAllocMem.Buffer = (PWSTR)ExAllocatePool(PagedPool,1024);
	WCHAR* wideString = L"wideString...";
	usAllocMem.Length = sizeof(WCHAR)* wcslen(wideString);

	ASSERT(usAllocMem.MaximumLength > usAllocMem.Length);
	RtlCopyMemory(usAllocMem.Buffer,wideString,usAllocMem.Length);
	usAllocMem.Length = sizeof(WCHAR)*wcslen(wideString);

	KdPrint(("usAllocMem:%wZ",&usAllocMem));

	ExFreePool(usAllocMem.Buffer);
	usAllocMem.Buffer = NULL;
	usAllocMem.Length = usAllocMem.MaximumLength = 0;

	//copy
	UNICODE_STRING usSrc;
	RtlInitUnicodeString(&usSrc,L"UnicodeStringScr...");
	UNICODE_STRING usDes;
	usDes.MaximumLength = 1024;
	usDes.Buffer = (PWSTR)ExAllocatePool(PagedPool,1024);
	RtlCopyUnicodeString(&usDes,&usSrc);
	KdPrint(("usSrc:%wZ",&usSrc));
	KdPrint(("usDes:%wZ",&usDes));
	RtlFreeUnicodeString(&usDes);

	//compare
	UNICODE_STRING usCom1,usCom2;
	RtlInitUnicodeString(&usCom1,L"usCom1");
	RtlInitUnicodeString(&usCom2,L"usCom2");
	int nComRes = RtlCompareUnicodeString(&usCom1,&usCom2,TRUE);
	KdPrint(("nComRes:%d\n",nComRes));


	//upper
	UNICODE_STRING usUpper;
	RtlInitUnicodeString(&usUpper,L"abcdef");
	KdPrint(("usUpper:%wZ",&usUpper));
	RtlUpcaseUnicodeString(&usUpper,&usUpper,FALSE);
	KdPrint(("usUpper:%wZ",&usUpper));


	//us 2 ULONG
	UNICODE_STRING us2i;
	RtlInitUnicodeString(&us2i,L"123");
	
	ULONG uValue;
	RtlUnicodeStringToInteger(&us2i,(ULONG)10,&uValue);
	KdPrint(("uValue:%d",uValue));


	// uLONG 2 us
	UNICODE_STRING usI2us;
	usI2us.MaximumLength = 1024;
	usI2us.Buffer = (LPWSTR)ExAllocatePool(PagedPool,1024);
	RtlIntegerToUnicodeString(uValue,(ULONG)10,&usI2us);
	KdPrint(("usI2us:%wZ",&usI2us));
	ExFreePool(usI2us.Buffer);
	usI2us.Length = usI2us.MaximumLength = 0;
	usI2us.Buffer = NULL;


	//ansi 2 us

	WCHAR *wideStr = L"ABCDEF";
	UNICODE_STRING usExc;
	RtlInitUnicodeString(&usExc,wideStr);
	ANSI_STRING asExc;
	RtlUnicodeStringToAnsiString(&asExc,&usExc,TRUE);

	KdPrint(("wdieStr:%ws,usExc:%wZ,asExc:%Z\n",wideStr,&usExc,&asExc));
	wideStr[0] = '1';
	wideStr[1] = '2';

	KdPrint(("wdieStr:%ws,usExc:%wZ,asExc:%Z\n",wideStr,&usExc,&asExc));
	RtlFreeAnsiString(&asExc);

	//us 2 ansi ..

    DriverObject->DriverUnload = DriverUnload;

//////////////////////////////////////////////////////////////////////////

    return STATUS_SUCCESS;
}
#ifdef __cplusplus
}; // extern "C"
#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值