MIDL2139 Error

  • Thread starter Thread starter tropictroop
  • Start date Start date
T

tropictroop

Hi, I get the following error when I try to compile my c++ code which
has a segment like:

__interface IObject1 : IDispatch
{
HRESULT COMTry([in]HDEVINFO DeviceInfoSet,[in]MYSTRUCT *ptr,[in]BSTR
*bstr);
};

and its implementation in a derived class as:

HRESULT COMTry(HDEVINFO vptr, MYSTRUCT *ptr,BSTR *bstr)
{
return S_OK;
}

error MIDL2139 : type of the parameter cannot derive from void or void
* : [ Type 'HDEVINFO' ( Parameter 'DeviceInfoSet' ) ]

Actually DeviceInfoSet is a variable of type HDEVINFO(HDEVINFO defined
as PVOID in SetUpAPI.h). Any help would be appreciated.

Thanks in advance.
Kris.
 
tropictroop said:
__interface IObject1 : IDispatch
{
HRESULT COMTry([in]HDEVINFO DeviceInfoSet,[in]MYSTRUCT *ptr,[in]BSTR
*bstr);
};

error MIDL2139 : type of the parameter cannot derive from void or void
* : [ Type 'HDEVINFO' ( Parameter 'DeviceInfoSet' ) ]

Actually DeviceInfoSet is a variable of type HDEVINFO(HDEVINFO defined
as PVOID in SetUpAPI.h). Any help would be appreciated.


According to
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/midl/midl/compiler_errors.asp :

"MIDL2139: type of the parameter cannot derive from void or void*
MIDL is a strongly typed language. All parameters transmitted over the
network must be derived from one of the MIDL base types. MIDL does not
support void as a base type. You must change the declaration to a valid MIDL
type."

In short, you can't pass HDEVINFO objects to an MIDL interface, because
they're not typesafe. Instead, use SetupDiEnumDeviceInfo to get access to
the device's instance ID DevInst, pass this through the MIDL interface, and
use SetupDiOpenDeviceInfo to regain access to it on the other side. I
haven't tried this - you might have to pass other information from
PSP_DEVINFO_DATA as well and/or use other device info functions.

More generally, whenever you have to pass an object which is not
MIDL-compliant, try instead to obtain a unique identifier for that object in
the form of an integer or string that you can use to find it again in the
called function. I hope this helps.
 
Back
Top