msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.31k stars 1.23k forks source link

[headers] Win32 include file wia.h missing declaration for IWiaDevMgr2. #17451

Open mayd opened 1 year ago

mayd commented 1 year ago

Description / Steps to reproduce the issue

When I attempted to compile code from several C++ examples on the Microsoft Windows Image Acquisition (WIA) tutorial Web pages https://learn.microsoft.com/en-us/windows/win32/wia/-wia-wia-tutorial, the MINGW compiler returned errors due to missing declarations.

E.g. the following code (based on https://learn.microsoft.com/en-us/windows/win32/wia/-wia-creating-a-wia-device-manager):

#include <windows.h>
#include <wia.h>

HRESULT CreateWiaDeviceManager( IWiaDevMgr2 **ppWiaDevMgr ) // Vista or later
{
  //
  // Validate arguments
  //
  if (NULL == ppWiaDevMgr)
  {
    return E_INVALIDARG;
  }

  //
  // Initialize out variables
  //
  *ppWiaDevMgr = NULL;

  //
  // Create an instance of the device manager
  //

  //Vista or later:
  HRESULT hr = CoCreateInstance( CLSID_WiaDevMgr2, NULL, CLSCTX_LOCAL_SERVER, IID_IWiaDevMgr2, (void**)ppWiaDevMgr ); 

  //
  // Return the result of creating the device manager
  //
  return hr;
}

Expected behavior

The command c++ -c wia-create-dev-mgr.cpp should compile the source to to an object file.

Actual behavior

The above code failed to compile and the following error message was displayed:

wia-create-dev-mgr.cpp:6:33: error: 'IWiaDevMgr2' was not declared in this scope; did you mean 'IWiaDevMgr'?
    6 | HRESULT CreateWiaDeviceManager( IWiaDevMgr2 **ppWiaDevMgr ) { //Vista or later
      |                                 ^~~~~~~~~~~
      |                                 IWiaDevMgr
wia-create-dev-mgr.cpp:6:47: error: 'ppWiaDevMgr' was not declared in this scope; did you mean 'WiaDevMgr'?
    6 | HRESULT CreateWiaDeviceManager( IWiaDevMgr2 **ppWiaDevMgr ) { //Vista or later
      |                                               ^~~~~~~~~~~
      |                                               WiaDevMgr

The above code and other examples did compile using include files copied from a recent version of the Microsoft Windows SDK.

Verification

Windows Version

MINGW64_NT-10.0-22631

MINGW environments affected

Are you willing to submit a PR?

Yes

Biswa96 commented 1 year ago

Header files are manually added in mingw-w64 repository. If you would like to wait I can try to work on this. IWiaDevMgr2 interface needs so many other interface declaration. Adding IDL file in mingw-w64 would be better option. It may need some time.

Biswa96 commented 1 year ago

Patch sent

mayd commented 1 year ago

I had started looking into fixing this bug myself.

First I looked at the current Microsoft SDK version 10 include files, I notice there are three main ones: Wia.h, Wia_xp.h, Wia_lh.h.

Unlike the MINGW wia.h, the Microsoft SDK Wia.h is merely a stub containing an #ifdef macro to select either the WIA 1.0 include file Wia_xp.h, or the WIA 2.0 include file Wia_lh.h, depending on the target platform. (WIA 1.0 is not supported on Windows versions after Windows XP.)

Next, I looked at the WineHQ website. They appear to have reverse engineered the unpublished Microsoft COM IDL file for WIA 1.0. They wrote two IDL files: wia_xp.idl and wia_lh.idl. They regenerated the corresponding include files wia_xp.h and wia_lh.h from the IDL files with the WIDL tool, and they also copied the Microsoft SDK stub wia.h.

However, crucially, the WineHQ version of wia_lh.idl is merely a duplicate of their wia_xp.idl and, therefore, is obviously useless, as it contains no WIA 2.0 definitions.

(I also checked the ReactOS website; it has identical files to those at WineHQ for WIA support.)

The problem to be solved is the complete absence of WIA 2.0 support. I intended follow the WinHQ approach to ensure compatibility with WinHQ and the Microsoft SDK. I would write the missing (correct) wia_lh.idl and update any additional include files such as wiadefs.h, wiadevd.h, wiavideo.h, if needed.

I was pleased, and surprised, to learn you have already submitted a patch as reverse engineering the WIA 2.0 IDL file and additional files seemed to be a lot of work!

I would be interested in testing your patch.

Biswa96 commented 1 year ago

mingw-w64 maintainers asked to upstream the IDL files to wine project first. I am working on that.