char*
我想转换成
PCSZ
之前
RtlInitiAnsiString()
uName
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;
}
第01版:
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);