Web lists-archives.com

[Mingw-users] Issues with IFileDialog




Been running into issues while trying to get some native dialogs on Windows. I was able to get things to work fine using GetSaveFileName and GetOpenFileName, but the problem is that I also need to be able to select directories sometimes and don't want to use SHBrowseForFolder due to the dialog looking outdated. For this purpose I was switching over to the IFileDialog APIs, but have been getting errors while trying to compile the following.

[[win.cpp]]
#include <windows.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <shobjidl.h>
#include <stdio.h>
int main(int argc, char** argv)
{
  CoInitialize(NULL);
  HRESULT hr = S_OK;
  IFileDialog* pfd = NULL;
  hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,, IID_PPV_ARGS(&pfd));
  if (SUCCEEDED(hr)) {
    hr = pfd->SetTitle(L"Select a File");
    hr = pfd->Show(NULL);
    if (SUCCEEDED(hr)) {
      printf("selected\n");
    } else {
      printf("nothing selected\n");
    }
  }
}

[[compilation output]]
i686-w64-mingw32-g++ -o win win.cpp -Wl,-subsystem,windows
win.cpp: In function 'int main(int, char**)':
win.cpp:19:13: error: invalid use of incomplete type 'IFileDialog {aka struct IFileDialog}'
     hr = pfd->SetTitle(L"Select a File");
             ^
In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/shlobj.h:124:0,
                 from win.cpp:3:
/usr/i686-w64-mingw32/sys-root/mingw/include/shobjidl.h:672:19: note: forward declaration of 'IFileDialog {aka struct IFileDialog}'
 typedef interface IFileDialog IFileDialog;
                   ^
win.cpp:20:13: error: invalid use of incomplete type 'IFileDialog {aka struct IFileDialog}'
     hr = pfd->Show(NULL);
             ^
In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/shlobj.h:124:0,
                 from win.cpp:3:
/usr/i686-w64-mingw32/sys-root/mingw/include/shobjidl.h:672:19: note: forward declaration of 'IFileDialog {aka struct IFileDialog}'
 typedef interface IFileDialog IFileDialog;
                   ^
In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/objbase.h:14:0,
                 from /usr/i686-w64-mingw32/sys-root/mingw/include/ole2.h:17,
                 from /usr/i686-w64-mingw32/sys-root/mingw/include/wtypes.h:12,
                 from /usr/i686-w64-mingw32/sys-root/mingw/include/winscard.h:10,
                 from /usr/i686-w64-mingw32/sys-root/mingw/include/windows.h:97,
                 from win.cpp:1:
/usr/i686-w64-mingw32/sys-root/mingw/include/combaseapi.h: In instantiation of 'void** IID_PPV_ARGS_Helper(T**) [with T = IFileDialog]':
win.cpp:16:75:   required from here
/usr/i686-w64-mingw32/sys-root/mingw/include/combaseapi.h:79:5: error: invalid static_cast from type 'IFileDialog*' to type 'IUnknown*'
     static_cast<IUnknown *> (*pp);


This was compiled using the latest packages on Fedora 23, but I was having similar issues on Windows 10 running MSYS2. I was able to compile and run a larger test program in Visual Studio (also on Windows 10) that used the same APIs, so I'm not sure if there's just something I'm failing to pass into the compiler through the command line or if there's an issue in shlobj.h or shobjidl.h. If somebody could point me in the right direction or confirm/deny that there's an issue using these APIs when compiling with MinGW it would be greatly appreciated.

Thanks
------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe