Windows内核代码片段
+ -

字符串UNICODDE_STRING与整型数字相互转换

2022-09-13 13 0
/************************************************************************

  * 函数名称:RtlUnicodeStringToInteger

  * 功能描述:UNICODE_STRING字符串转化成整型数字

  * 参数列表:

  String:需要转化的字符串

  Base:转换的数的进制(2,8,10,16)

  Value:需要转换的数字

  * 返回 值:指明是否转换成功

  *************************************************************************/

  NTSTATUS RtlUnicodeStringToInteger(

  IN PUNICODE_STRING String,

  IN ULONG Base OPTIONAL,

  OUT PULONG Value);

  /************************************************************************

  * 函数名称:RtlIntegerToUnicodeString

  * 功能描述:UNICODE_STRING字符串转化成整型数字

  * 参数列表:

  Value:需要转化的数字

  Base:转换的数的进制(2,8,10,16)

  String:需要转换的字符串

  * 返回 值:指明是否转换成功

  *************************************************************************/

  NTSTATUS RtlIntegerToUnicodeString(

  IN ULONG Value,

  IN ULONG Base OPTIONAL,

  OUT PUNICODE_STRING String);

  字符串与整型数字相互转换的实例

  //(1)字符串转换成数字

  //初始化UnicodeString1

  UNICODE_STRING UnicodeString1;

  RtlInitUnicodeString(&UnicodeString1, L“-100”);

  ULONG lNumber;

  NTSTATUS nStatus = RtlUnicodeStringToInteger(&UnicodeString1, 10, &lNumber);

  if( NT_SUCCESS(nStatus) )

  {

  KdPrint((“Conver To Integer successfullu!\n”));

  KdPrint((“Result:%d\n”, lNumber));

  }

  else

  {

  KdPrint((“Conver to integer unsuccessfully!\n”));

  }

  //(2)数字转换成字符串

  //初始化UnicodeString2

  UNICODE_STRING UnicodeString2;

  UnicodeString2.Buffer = (PWSTR)ExAllocatePool(PagedPool, BUFFER_SIZE);

  UnicodeString2.MaximumLength = BUFFER_SIZE;

  nStatus = RtlIntegerToUnicodeString(200, 10, &UnicodeString2);

  if( NT_SUCCESS(nStatus) )

  {

  KdPrint((“Conver to string successfuall!\n”));

  KdPrint((“Result:%wZ\n”, &UnicodeString2));

  }

  else

  {

  KdPrint((“Conver to string unsuccessfully!\n”));

  }

  //注销UniocdeString2

  //注意:UnicodeString1不用销毁

  RtlFreeUnicodeString(&UniocdeString2);

0 篇笔记 写笔记

不同编码之间的转换(UTF-8,UNICODE,多字节,宽字节)
BOOL CUtils::CharToWchar(std::string src, std::wstring& dest){ int dwMinSize = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src.c_str(), -1, ......
SetupAPI函数实现设备分类GUID和类名之间的转换SetupDiClassNameFromGuidEx和SetupDiClassGuidsFromNameEx
类名与其GUID之间的切换 GUID guid; ULONG rtn = 0; if (SetupDiClassGuidsFromNameEx(TEXT("USB"), &guid, 1, &rtn, NULL, N......
Windows内核STRING转UNICODE
VOIDConvertToUnicodeString( IN CHAR * Buffer, IN ULONG ResultBufferLength, IN ULONG ResultBufferOffset, OUT LPWSTR ResultBuffer, ......
ANSI_STRING字符串与UNICODE_STRING字符串相互转换 - Windows内核模式下的字符串操作
函数名称:RtlUnicodeStringToAnsiString功能描述:将UNICODE_STRING字符串转化成ANSI_STRING字符串参数列表:DestinationString:需要转化的字符串SourceString:需要转换的原字符串AllocateDesctinationSt......
字符串UNICODDE_STRING与整型数字相互转换
/************************************************************************  * 函数名称:RtlUnicodeStringToInteger  * 功能描述:UNICODE_STRING字符串转化成整型数字  * ......
作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!