2

I am trying to build this code with qtcreator, my point is to create a new device using RtlInitUnicodeString and IoCreateDevice

#define _WIN32_WINNT 0x0501

#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <tchar.h>
#include <stdio.h>
#include <qdebug.h>

#include <wdm.h>
#include <Ntifs.h>
#include <windows.h>

#define BUFSIZE MAX_PATH

int main(  )
{
    BOOL bFlag;
    TCHAR Buf[BUFSIZE];     // temporary buffer for volume name


    //create a new device

    NTSTATUS    ntStatus = STATUS_SUCCESS;
    UNICODE_STRING      deviceNameUnicodeString;
    UNICODE_STRING      deviceLINKNameUnicodeString;
    int i;

    RtlInitUnicodeString(&deviceNameUnicodeString, L"\\Device\\Harddisk0\\Partition3");
    RtlInitUnicodeString(&deviceLINKNameUnicodeString, L"\\DosDevices\\I:");


    ntStatus = IoCreateDevice ( theDriverObject,
                                0, // For driver extension
                                &deviceNameUnicodeString,
                                FILE_DEVICE_UNKNOWN,
                                FILE_DEVICE_SECURE_OPEN,
                                FALSE,
                                &g_MyDeviceI);


    IoCreateSymbolicLink (&deviceLINKNameUnicodeString, &deviceNameUnicodeString);

I get this error:

erreur : C1083: Cannot open include file: 'wdm.h': No such file or directory

and here is my .pro file

SOURCES += \
    main.cpp \
    VolumeCreationWind.cpp \
    ChangePassWd.cpp \
    PasswordMountWind.cpp \
    MainWindow.cpp \
    DeviceInfos.cpp

HEADERS += \
    VolumeCreationWind.h \
    PasswordMountWind.h \
    ChangePassWd.h \
    MainWindow.h \
    DeviceInfos.h \


FORMS +=
CONFIG += release
INCLUDEPATH += C:\WinDDK\7600.16385.1\inc\ddk
INCLUDEPATH += C:\WinDDK\7600.16385.1\inc\wdf\kmdf\1.9

1) How can I fix the error of include path

2) can any one explain for me the use of IoCreateDevice and how create theDriverObject

Any help please!!!! Thanks in advance.

Jonas
  • 6,915
  • 8
  • 35
  • 53
Oumaya
  • 655
  • 4
  • 18
  • 43
  • `wdm.h` is in `inc\ddk` which appears to be in your INCLUDEPATH are you sure that's getting passed to the compiler properly? – Benj Sep 28 '12 at 09:36
  • yes both `wdm.h` and `Ntifs.h` in `\inc\ddk` so how can I be sure that " that's getting passed to the compiler properly" ? PS: when I put full path in .h file it accept it but it didn't local other included file in the `wdm.h` so I need to a global setting for the path. – Oumaya Sep 28 '12 at 09:41
  • I fix the include issue of `wdm.h` with `INCLUDEPATH +=C:\WinDDK\7600.16385.1\inc\ddk INCLUDEPATH += C:\WinDDK\7600.16385.1\inc\api` but it shows 102 error with `crtdefs.h` and `math.h` in `C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include` !!!!!!!! – Oumaya Sep 28 '12 at 11:36
  • Windows drivers have to be built within the build environment of the WDK. Do not use QT creator, or any other compiler. Nevertheless, the entry point of a driver is DriverEntry and not main. Please look at the samples included in the WDK. You have to build a real driver to use IOCreateDevice, – Christopher Sep 28 '12 at 12:04
  • thank you @Christopher , it is clearer now, I will check `DriverEntry` code and see what I can do. – Oumaya Sep 28 '12 at 12:11
  • is it possible to create a project to create my driver in Visual Studio (since WDK was integrated with it) and convert it later with my main project with QT Creator? let me know if I am telling foolish. – Oumaya Sep 28 '12 at 15:33
  • @oumaya it's possible starting from VS2012. Your code above has standard libraries included that do not belong to kernel, such as windows.h. Do not do that - you'll get compilation errors or worth. – SomeWittyUsername Oct 22 '12 at 21:00
  • @icepack thank you but, I need to include "windows.h" so what should I do is there an alternative? and how to know it fits my kernel? what are the risks? – Oumaya Oct 23 '12 at 08:04
  • @oumaya Kernel headers are those included with the WDK, anything else isn't compatible unless explicitly stated (there are 3rd-party headers that are kernel-compatible). If you're using `windows.h` you're compiling code that isn't compatible with kernel. It might work (or appear to work) but that's a very bad practice and will get back to you sooner or later. You should search for kernel equivalent API to the functionality you require either in WDK or in 3rd-part package. If you're out of luck, you might need to implement the missing logic by yourself. – SomeWittyUsername Oct 23 '12 at 08:15
  • OMG 50% of my functions use windows.h, in fact am working on Qt application and I need winapi to work with, is that mean am in trouble and my work is not safe and risky? – Oumaya Oct 23 '12 at 09:20
  • Try to match the needed APIs in WDK headers, they are pretty extensive. Keeping the user mode headers is risky indeed. – SomeWittyUsername Oct 23 '12 at 11:07
  • I am trying the same thing but not able to include the file wdm.h in my project of visual studio can anyone please tell me how to include it – Digvijay Rathore Nov 22 '16 at 09:42

0 Answers0