1

I'm writing a program that automates some tasks that must be done when a removable device is detected. Originally using only file streams. When I realized that not all removable devices can be accessed that way then I started to use SHFileOperation, but now I realized that some devices cannot be accessed even by this method.

I want to use WPD API but my program is compiled using MingW, and the libraries it uses where compiled using MingW too. The only two possibilities I see are to recompile everything for Visual C++ (I want to avoid this if possible) or write a small wrapping library that will compile as a DLL and that only exports functions and can be easily linked from a program compiled with MingW even if the DLL itself was compiled with Visual C++ (so it can use WPD API).

For example if somebody knows a library that already wrapped WPD, that will save me a lot of time.

Hatoru Hansou
  • 317
  • 10
  • 22

1 Answers1

1

I don't think you'll find any generic wrappers for WPD, as the API exposes COM interfaces which can be accessed directly from MinGW. The problem is that there are no MinGW compatible headers declaring the interfaces and related types. There are few possible solutions that don't involve using Microsoft's compiler:

  • Write your own MinGW compatible headers. If you can do this solely from the documentation without referencing Microsoft's headers then you could submit them for addition to the w32api package so others can use them.
  • Copy the Windows SDK version of the headers and remove all junk that prevents them from compiling with GCC. Older versions of the headers from older SDKs will have less junk to remove.
  • Create headers that wrap the SDK headers and use macros to eliminate the junk.
  • Use the OLE Automation interfaces to WPD. All the COM interfaces necessary to do this (mainly IDispatch) are supported by MinGW. The Windows SDK documentation briefly addresses this option.
Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
  • Thinking in the time that each approach may require, I think 1 is the best. I will try it. Will OLE Automation work for XP? Even if it is unsupported now, the person that will use the program won't update to 7 or 8 soon. I see a PortableDeviceGUIDs.lib file in the Windows SDK lib folder. Again which dll should the MinGW compiled program be linked? – Hatoru Hansou Aug 06 '14 at 02:27
  • Theres's no WPD DLL you need to link against. Since WPD uses COM interfaces exclusively you use need to use `CoCreateInstance` with an appropriate WPD class id (eg. `CLSID_PortableDeviceManager`) to obtain create WPD object and obtain an interface to it. From that you should be able to obtain other interfaces and/or create other objects. MinGW supports `CoCreateInstance`, link with `-lole32` for this function. OLE Automation is supported by all versions of Windows back to Windows 95. Note that WPD isn't a part of Windows XP, users will need to install it first. – Ross Ridge Aug 06 '14 at 02:48
  • Understood. I will try 1 or 4 if 1 takes too much time. – Hatoru Hansou Aug 06 '14 at 02:53