内核驱动程序:如何获得结构中每个变量的正确内容?

时间:2017-08-13 23:37:20

标签: c windows visual-studio driver kernel-mode

我有以下代码涉及struct包括指针变量,我无法检索每个变量的正确内容。

有人可以帮我吗?

struct MyData
    {
        ULONG Value[3];
        wchar_t *Str1;
        int Str1Len;
        wchar_t *Str2;
        int Str2Len;
    };

    // In the driver, on method that receives commands i have following:

    struct MyData *pData = (struct MyData*) Irp->AssociatedIrp.SystemBuffer; 

    DbgPrint("0x%x \n 0x%x \n 0x%x \n %s \n %d \n %s \n %d", &pData->Value[0], &pData->Value[1], &pData->Value[2], &pData.Str1, &pData->Str1Len, &pData->Str2, &pData->Str2Len);

1 个答案:

答案 0 :(得分:0)

DbgPrint的调用与调用printf非常相似,因此您应该传递值,而不是值的地址。所以

DbgPrint("0x%x \n 0x%x \n 0x%x \n %s \n %d \n %s \n %d", &pData->Value[0], // etc...

应该是

DbgPrint("0x%x \n 0x%x \n 0x%x \n %s \n %d \n %s \n %d", pData->Value[0],  // etc...