Help us understand the problem. What is going on with this article?

【Windows Kernel Mode】【WDM】 UNICODE_STRING への変換

前置き

Windows Kernelにおけるプログラミング(WDM)では、
多くのNT関数呼び出しの文字列の扱いとしてUNICODE_STRINGが使われます。
当記事ではUNICODE_STRINGへの変換例をいくつか紹介します。

変換例

char*

const char* hoge = "abc";
ANSI_STRING ansi_string;
UNICODE_STRING unicode_string;

//char* -> ANSI_STRING
RtlInitAnsiString(&ansi_string, hoge);

//ANSI_STRING -> UNICODE_STRING
//第三引数はバッファを割り当てるか。
if(!NT_SUCCESS(RtlAnsiStringToUnicodeString(&unicode_string, &ansi_string, FALSE))
{
    //失敗.
    //TRUEならば RtlFreeUnicodeString(&unicode_string); して開放してあげる.
}

wchar*

const WCHAR* hoge = L"abc";
ANSI_STRING ansi_string;
UNICODE_STRING unicode_string;

//wchar* -> UNICODE_STRING
RtlInitUnicodeString(&unicode_string, hoge);

おまけ

DbgPrintKdPrintUNICODE_STRINGを出力する.

DbgPrint("UNICODE_STRING: %wZ\n", unicode_string);
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした