0

I am trying to create a file management system for a small business which requires a few pieces of information to save a file. I need to add 3 required text boxes to the common item dialog before allowing save from any application on the computer.

Which direction is recommended to modify the Common Item Dialog system-wide? I am using the Windows Classic Sample CommonFileDialogSDKSample from github to modify the dialog but I don't know how to control the dialog that appears in Word, Excel, Adobe, etc.

------------------ Here are my thoughts and results so far ------------------- From what I understand, the best (only?) way in the past was to use a global hook? But since the new Common Item Dialog is a COM object is this still the right approach?

This makes me think it should be possible to modify the comdlg32.dll: https://www.tenforums.com/tutorials/52655-reset-open-save-common-item-dialog-boxes-windows.html. "Since they're just COM objects with known CLSIDs you might get away with just replacing them by re-registering using their CLSID": https://stackoverflow.com/a/977964/19933151

I have this low level keyboard hook (below) working as a prototype but I'm not sure how to hook the common item dialog. WH_CBT? And then I need to redirect to my custom dialog. Maybe Detours? EasyHook? Am I going to get into trouble with antivirus software if I try to go this route?

#include <Windows.h>
#include <iostream>

LRESULT CALLBACK KBHook(int nCode, WPARAM wParam, LPARAM lParam)
{
    KBDLLHOOKSTRUCT *s = reinterpret_cast<KBDLLHOOKSTRUCT *>(lParam);
    switch (wParam)
    {case WM_KEYDOWN:
        char c = MapVirtualKey(s->vkCode, MAPVK_VK_TO_CHAR);
        std::cout << c << std::endl;
        break;
    }
    return CallNextHookEx(NULL, nCode, wParam, lParam);
}

int main()
{
    std::cout << "Hello, World!" << std::endl;

    HHOOK kbd = SetWindowsHookEx(WH_KEYBOARD_LL, &KBHook, 0, 0);

    MSG message;
    while (GetMessage(&message, NULL, NULL, NULL) > 0)
    {
        TranslateMessage(&message);
        DispatchMessage(&message);
    }

    UnhookWindowsHookEx(kbd);

    return 0;
}

My background is data science via python so windows development is a new world to me and any links or hints are appreciated. Thank you.

Okapi
  • 3
  • 1
  • 1
    First of all, not all applications use the Common Dialogs (for example, major Autodesk apps don't). Then, replacing this behavior globally (don't forget, for x86 and x64 apps) is not supported in any way and will probably lead to instability. And last of all, it's far from being easy if you're new to Windows development. For example, modifying commdlg32 is somehow impossible. Prepare for severe crashes ahead. – Simon Mourier Sep 09 '22 at 16:47
  • Yes, technically you could make your own implementation and overwrite the CLSID in the registry. – Anders Sep 10 '22 at 01:03
  • @Anders thank you, I believe this is the right approach. Can you point me to any examples or suggest more references besides the Microsoft Docs? I continue to study the Documentation but it helps a lot to see examples of implementation. – Okapi Sep 12 '22 at 12:50
  • @SimonMourier I should have clarified, I realize not all apps use the CID but for those that do, I would like to implement my custom version. I don't need for it to be easy, I am just looking for help in finding the correct path. – Okapi Sep 12 '22 at 12:55
  • You just implement the COM interfaces, no different than say if you were implementing a IExtractIcon or IContextMenu handler. – Anders Sep 12 '22 at 12:59
  • You will have to implement IFileDialog, IFileDialogEvents, IFileDialogCustomize, etc. (and lots of other interfaces, some are undocumented but may be needed https://i.imgur.com/LWS9zsR.png). I don't think this is supported, the doc clearly states that they are [already] implemented. Good luck with that. https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ifiledialog#when-to-implement – Simon Mourier Sep 12 '22 at 14:27
  • @SimonMourier do you think this will work instead? https://web.archive.org/web/20191227153456/http://blogs.microsoft.co.il/pavely/2017/08/07/hooking-com-classes/ – Okapi Sep 12 '22 at 17:21
  • Wrapping the existing implementation (delegating QueryInterface and most methods, etc. to the real implementation) has certainly more chances to work than reimplementing everything. It's not guaranteed (must be tested), and is not necessary an easy work. – Simon Mourier Sep 12 '22 at 17:26
  • Thank you. We may just use Sharepoint instead of creating a custom system. – Okapi Sep 13 '22 at 17:31

0 Answers0