Important: Please read the Qt Code of Conduct -

Can i hook native win32 api code into Qt code?

  • Hi
    im looking for away to disable the windows key , i didnt find any problematically way in Qt but did found some code in native win32 code
    my question is can i hook this code into Qt somehow
    here is the link to the code:

  • Should be no problem. I do it all the time.

    You can use QLibrary to dynamically load Win32 functions that may be missing from older Win32 versions:

    @typedef HRESULT (WINAPI *SHGetKnownFolderPathFun)(__in const GUID &rfid, __in DWORD dwFlags, __in HANDLE hToken, __out PWSTR *ppszPath);
    typedef HRESULT (WINAPI *SHGetFolderPathFun)(__in HWND hwndOwner, __in int nFolder, __in HANDLE hToken, __in DWORD dwFlags, __out LPWSTR pszPath);

    static SHGetKnownFolderPathFun SHGetKnownFolderPathPtr = NULL;
    static SHGetFolderPathFun SHGetFolderPathPtr = NULL;

    if((!SHGetKnownFolderPathPtr) && (!SHGetFolderPathPtr))
    QLibrary kernel32Lib("shell32.dll");
    SHGetKnownFolderPathPtr = (SHGetKnownFolderPathFun) kernel32Lib.resolve("SHGetKnownFolderPath");
    SHGetFolderPathPtr = (SHGetFolderPathFun) kernel32Lib.resolve("SHGetFolderPathW");

    WCHAR path = NULL;
    if(SHGetKnownFolderPathPtr(folderGUID, 0x00008000, NULL, &path) == S_OK)
    ... */

  • wow thanks for the response but your example to messy i can't understand any thing

  • Messy? It's just a small code excerpt showing the basic idea ;)

    The typedef's define the required function pointer types for the functions we want to call.

    If you are not familiar with function pointers, please see:

    Next we will use QLibrary to load the DLL that contains the functions, "shell32.dll" in this example.

    Once the library is loaded, we resolve() the desired entry point (e.g. ""SHGetKnownFolderPath") and assign the result to our function pointer variable. If the result is non-NULL, i.e. the entry point was found, we call it...

Log in to reply