Using the Win32 API in QT for Windows

I am switching from .net C # to QT C ++, and I am trying to use this Win32 function to emulate a disk in QT:

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern bool DefineDosDevice(int flags, string devname, string path); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern int QueryDosDevice(string devname, StringBuilder buffer, int bufSize); 

The code above is in C #, but I don’t know how to use them in QT, someone can give me an example, how to do it and how to use any Win32 API in QT?

+4
source share
3 answers

Thanks for any answer! The answer to my question is:

 #include <Windows.h> void MainWindow::on_pushButton_clicked() { QString qstr1 = "Z:"; QString qstr2 = getenv("tmp"); DefineDosDevice(0, (LPCTSTR)qstr1.utf16(), (LPCTSTR)qstr2.utf16()); } void MainWindow::on_pushButton_2_clicked() { QString qstr = "Z:"; DefineDosDevice(2, (LPCTSTR)qstr.utf16(), 0); } 
+1
source

Looking at the documentation for DefineDosDevice and QueryDosDevice , you will see at the bottom of the table that both of them are defined in the library "kernel32.lib" and declared in "Windows.h" (indirectly).

In your code, you must #include <Windows.h> : you can access them directly.

I am not sure about your specific IDE compiler / environment, but if you get errors in time links to "Unresolved links", you may need to add "kernel32.lib" (from the Windows SDK) to your library path.

+3
source

You can use win32 APIs as normal C functions. There is no difference in QT and other C ++ programs.

+2
source

All Articles