none
When i am adding Windows.h and Wdm.h, coming redefinition errors due to Wdm.h and Winnt.h RRS feed

  • Question

  • In my program i am including

     #include <WINDOWS.h>
    #include <initguid.h>
    #include <devguid.h>
    #include <devpkey.h>
    #include <diskguid.h>
    #include <stdio.h>
    #include <cfgmgr32.h>
    #include <Wdm.h>

    I am using windows 7-64 Bit, VS2010. I am trying to find EFI partition using CM_Get_DevNode_PropertyW(), ZwDeviceIoControlFile(). I have provided Include directories path as:

     F:\Programs\WINDDK\7600.16385.1\inc;F:\Programs\WINDDK\7600.16385.1\inc\api;F:\Programs\WINDDK\7600.16385.1\inc\crt;F:\Programs\WINDDK\7600.16385.1\inc\ddk;

    Please help me on this.

    Errors coming like:

    f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(128): warning C4005: 'MAX_NATURAL_ALIGNMENT' : macro redefinition
    1>          f:\programs\winddk\7600.16385.1\inc\api\winnt.h(109) : see previous definition of 'MAX_NATURAL_ALIGNMENT'
    1>f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(161): warning C4005: 'PROBE_ALIGNMENT' : macro redefinition
    1>          f:\programs\winddk\7600.16385.1\inc\api\winnt.h(142) : see previous definition of 'PROBE_ALIGNMENT'
    1>f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(614): error C2011: '_PROCESSOR_NUMBER' : 'struct' type redefinition
    1>          f:\programs\winddk\7600.16385.1\inc\api\winnt.h(493) : see declaration of '_PROCESSOR_NUMBER'
    1>f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(625): error C2011: '_GROUP_AFFINITY' : 'struct' type redefinition
    1>          f:\programs\winddk\7600.16385.1\inc\api\winnt.h(504) : see declaration of '_GROUP_AFFINITY'
    1>f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(882): error C2011: '_FLOAT128' : 'struct' type redefinition
    1>          f:\programs\winddk\7600.16385.1\inc\api\winnt.h(630) : see declaration of '_FLOAT128'
    1>f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(933): error C2011: '_LARGE_INTEGER' : 'union' type redefinition
    1>          f:\programs\winddk\7600.16385.1\inc\api\winnt.h(677) : see declaration of '_LARGE_INTEGER'
    1>f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(951): error C2011: '_ULARGE_INTEGER' : 'union' type redefinition
    1>          f:\programs\winddk\7600.16385.1\inc\api\winnt.h(695) : see declaration of '_ULARGE_INTEGER'
    1>f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(973): error C2011: '_LUID' : 'struct' type redefinition
    1>          f:\programs\winddk\7600.16385.1\inc\api\winnt.h(717) : see declaration of '_LUID'
    1>f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1070): error C2084: function 'ULONGLONG Int64ShllMod32(ULONGLONG,DWORD)' already has a body
    1>          f:\programs\winddk\7600.16385.1\inc\api\winnt.h(771) : see previous definition of 'Int64ShllMod32'
    1>f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1086): error C2084: function 'LONGLONG Int64ShraMod32(LONGLONG,DWORD)' already has a body
    1>          f:\programs\winddk\7600.16385.1\inc\api\winnt.h(778) : see previous definition of 'Int64ShraMod32'
    1>f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1102): error C2084: function 'ULONGLONG Int64ShrlMod32(ULONGLONG,DWORD)' already has a body
    1>          f:\programs\winddk\7600.16385.1\inc\api\winnt.h(785) : see previous definition of 'Int64ShrlMod32'
    1>f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1318): warning C4005: 'UNICODE_STRING_MAX_BYTES' : macro redefinition
    1>          f:\programs\winddk\7600.16385.1\inc\api\winnt.h(957) : see previous definition of 'UNICODE_STRING_MAX_BYTES'
    1>f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1358): error C2011: '_LIST_ENTRY' : 'struct' type redefinition
    1>          f:\programs\winddk\7600.16385.1\inc\api\winnt.h(966) : see declaration of '_LIST_ENTRY'

    Monday, August 21, 2017 1:30 PM

All replies

  • Windows.h is a user space include file, WDM.h is a kernel space include file, they are not designed to be installed together.   What call do you think you need out of wdm.h that has made you include it?


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Monday, August 21, 2017 2:43 PM
  • i am using ZwClose(),ZwOpenFile() routine to get handle..Thanks!!
    Tuesday, August 22, 2017 5:58 AM
  • For reference, i am trying to compile this code, please have a look:

    #include <initguid.h>
    #include <cfgmgr32.h>
    #include <devguid.h>
    #include <devpkey.h>
    #include <diskguid.h>

    #define FILE_SHARE_VALID_FLAGS          0x00000007

    void DumpVolume(HANDLE hFile);
    void VolEnum();
    void main()
    {

    printf("Sample Applicatio");
    VolEnum();
    }

    void VolEnum()
    {
       // STATIC_WSTRING(DEVCLASS_VOLUME, "{71a27cdd-812a-11d0-bec7-08002be2092f}");
    PCWSTR  DEVCLASS_VOLUME = L"{71a27cdd-812a-11d0-bec7-08002be2092f}";
        enum { flags = CM_GETIDLIST_FILTER_CLASS|CM_GETIDLIST_FILTER_PRESENT };

        ULONG len;
        ULONG cb = 0, rcb = 64;

        HANDLE hFile;
        IO_STATUS_BLOCK iosb;
        UNICODE_STRING ObjectName;
        OBJECT_ATTRIBUTES oa = { sizeof(oa), 0, &ObjectName, 0 };

        if (!CM_Get_Device_ID_List_SizeW(&len, DEVCLASS_VOLUME, flags))
        {
            PWSTR buf = (PWSTR)alloca(len << 1);
            if (!CM_Get_Device_ID_ListW(DEVCLASS_VOLUME, buf, len, flags))
            {
                PVOID stack = buf;
                while (*buf)
                {
                    printf("%S\n", buf);
                    DEVINST dnDevInst;
                    if (!CM_Locate_DevNodeW(&dnDevInst, buf, CM_LOCATE_DEVNODE_NORMAL))
                    {
                        DEVPROPTYPE PropertyType;
                        int err;

                        union {
                            PVOID pv;
                            PWSTR sz;
                            PBYTE pb;
                        };

                        do 
                        {
                            if (cb < rcb)
                            {
                                rcb = cb = RtlPointerToOffset(pv = alloca(rcb - cb), stack);
                            }

                            if (!(err = CM_Get_DevNode_PropertyW(dnDevInst, &DEVPKEY_Device_PDOName, &PropertyType, pb, &rcb, 0)))
                            {
                                if (PropertyType == DEVPROP_TYPE_STRING)
                                {
                                    printf("%S\n", sz);

                                    RtlInitUnicodeString(&ObjectName, sz);
                                    if (0 <= ZwOpenFile(&hFile, FILE_GENERIC_READ, &oa, &iosb, FILE_SHARE_VALID_FLAGS, 0))
                                    {
                                        DumpVolume(hFile);
                                        ZwClose(hFile);
                                    }
                                }
                            }

                        } while (err == CR_BUFFER_SMALL);

                    }
                    buf += 1 + wcslen(buf);
                }
            }
        }
    }

    void DumpVolume(HANDLE hFile)
    {
        NTSTATUS status;
        PARTITION_INFORMATION_EX pi;
        IO_STATUS_BLOCK iosb;

        if (0 <= (status = ZwDeviceIoControlFile(hFile, 0, 0, 0, &iosb, IOCTL_DISK_GET_PARTITION_INFO_EX, 0, 0, &pi, sizeof(pi))))
        {
            CHAR PartitionName[40], *szPartitionName;

            PCSTR szps = "??";
            switch (pi.PartitionStyle)
            {
            case PARTITION_STYLE_MBR: szps = "MBR";
                break;
            case PARTITION_STYLE_GPT: szps = "GPT";
                break;
            }

            printf("%u %s %I64u(%I64x) %I64u ", 
                pi.PartitionNumber, 
                szps, 
                pi.StartingOffset.QuadPart, pi.StartingOffset.QuadPart, 
                pi.PartitionLength.QuadPart);

            switch (pi.PartitionStyle)
            {

            case PARTITION_STYLE_MBR: 
                printf("type=%x boot=%x", pi.Mbr.PartitionType, pi.Mbr.BootIndicator);
                break;

            case PARTITION_STYLE_GPT:

                if (IsEqualGUID(pi.Gpt.PartitionType, PARTITION_ENTRY_UNUSED_GUID))
                {
                    szPartitionName = "UNUSED";
                }
                else if (IsEqualGUID(pi.Gpt.PartitionType, PARTITION_SYSTEM_GUID))
                {
                    szPartitionName = "SYSTEM";
                }
                else
                {
                    sprintf(szPartitionName = PartitionName, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", 
                        pi.Gpt.PartitionType.Data1,
                        pi.Gpt.PartitionType.Data2,
                        pi.Gpt.PartitionType.Data3,
                        pi.Gpt.PartitionType.Data4[0],
                        pi.Gpt.PartitionType.Data4[1],
                        pi.Gpt.PartitionType.Data4[2],
                        pi.Gpt.PartitionType.Data4[3],
                        pi.Gpt.PartitionType.Data4[4],
                        pi.Gpt.PartitionType.Data4[5],
                        pi.Gpt.PartitionType.Data4[6],
                        pi.Gpt.PartitionType.Data4[7]);
                }
                printf("[%s] %I64x \"%S\"", 
                    szPartitionName,
                    pi.Gpt.Attributes,
                    pi.Gpt.Name);
                break;
            }

            ULONG cb = FIELD_OFFSET(FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName[32]);
            PFILE_FS_ATTRIBUTE_INFORMATION pffai = (PFILE_FS_ATTRIBUTE_INFORMATION)alloca(cb);

            switch (ZwQueryVolumeInformationFile(hFile, &iosb, pffai, cb, FileFsAttributeInformation ))
            {
            case STATUS_SUCCESS:
            case STATUS_BUFFER_nbsp;           printf(" \"%.*S\"", pffai->FileSystemNameLength >> 1 , pffai->FileSystemName);
                break;
            }

            printf("\n");
        }
        else
        {
            printf("status=%x\n", status);
        }
    }

     
    Tuesday, August 22, 2017 6:12 AM
  • Take a look at https://msdn.microsoft.com/en-us/library/bb432200(v=vs.85).aspx   Basically you want Winternl.h instead of WDM.h


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com


    Tuesday, August 22, 2017 10:52 AM