我有一个具有强制参数 as 的方法,char*
我想转换为PCSZ
beforeRtlInitiAnsiString()
和uName
after的结果RtlAnsiStringToUnicodeString()
是正确的值。
我怎样才能做到这一点?
NTSTATUS myMethod(char *myName)
{
ANSI_STRING aName;
UNICODE_STRING uName;
OBJECT_ATTRIBUTES ObjAttr;
RtlInitAnsiString(&aName, myName);
status = RtlAnsiStringToUnicodeString(&uName, &aName, TRUE);
if(!NT_SUCCESS(status))
{
DbgPrint("RtlAnsiStringToUnicodeString Error");
return status;
}
InitializeObjectAttributes(&ObjAttr, &uName, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL);
// some code here
//...
RtlFreeUnicodeString(&uName);
return status;
}
第 1 版:
为了更好地理解这里是如何MyMethod()
在我的内核驱动程序中使用:
struct MyData
{
ULONG Value[3];
char *Str1;
char *Str2;
};
NTSTATUS Function_IRP_DEVICE_CONTROL(PDEVICE_OBJECT pDeviceObject, PIRP Irp)
{
PIO_STACK_LOCATION pIoStackLocation;
struct MyData *pData = (struct MyData*) Irp->AssociatedIrp.SystemBuffer;
pIoStackLocation = IoGetCurrentIrpStackLocation(Irp);
switch (pIoStackLocation->Parameters.DeviceIoControl.IoControlCode)
{
case IOCTL_DATA :
DbgPrint("IOCTL DATA");
DbgPrint("%lu \n %lu \n %lu \n %s \n %s", pData->Value[0], pData->Value[1], pData->Value[2], pData->Str1, pData->Str2);
...
break;
}
...
//////////// Calling MyMethod() //////////////
myMethod(pData->Str1);