News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

IDL File to Include File Converter

Started by Zen, May 24, 2014, 05:06:57 AM

Previous topic - Next topic

Zen

This is CLEARLY an insane idea,...but, I was wondering,...and, this is probably a question for either VORTEX or JAPHETH,...or, maybe, QWORD,...
Has anyone ever tried to write a converter utility that converts COM Interface Definition Files to MASM Include files ???
Here is MSDN's Microsoft Interface Definition Language Overview for reference.
...Also, here is an MSDN webpage: Anatomy of an IDL File
I suspect this project would be a MAJOR PAIN IN THE ASS to write,...and, of course, no one would ever use it. :dazzled:
...I'm thinking of attempting something like this,...
I know,...you all are horrified. Ha ha,...
...Maybe, I should register as an organ donor before I get started,...

dedndave

i seem to recall something like that someplace
but, you probably have the author listed
well - you certainly have the "usual suspects"   :P
you could add Donkey to that list, and Yves has done a lot of COM/ASM stuff, as well

GoneFishing

Hi ZEN,

It's an interesting idea as usual  :t
I like your creative mind ... and intrepidity   ;)
Maybe I could help you to kill your Goliath
Your  task  might happen to be not that hard as you think
First read MIDL Compiler  :
QuoteThe MIDL compiler processes an IDL file to generate a type library and output filesThe MIDL compiler processes an IDL file to generate a type library and output files. The type of output files generated by the MIDL compiler depends on the attributes specified in the IDL file's interface attribute list.

If the attribute list contains the [object] keyword, the MIDL compiler generates COM interface output files: an interface proxy file, an interface header file, and a globally unique identifier (GUID) file for the interface.

After that read about #import Directive (C++):
QuoteHeader Files Created by Import

#import creates two header files that reconstruct the type library contents in C++ source code. The primary header file is similar to that produced by the Microsoft Interface Definition Language (MIDL) compiler, but with additional compiler-generated code and data. The primary header file has the same base name as the type library, plus a .TLH extension. The secondary header file has the same base name as the type library, with a .TLI extension. It contains the implementations for compiler-generated member functions, and is included (#include) in the primary header file.

Now that you have an interface header file the only thing you're supposed to do is to convert that specific H file to INC
Good luck !


TouEnMasm

The translator downloadable here offer very good results using MIDL first to get
Header files .h before.Method is explain in the readme..
http://masm32.com/board/index.php?topic=576.0
Use of oleview and MIDL is a very good way to use COM interfaces.
The translation give you ALL of the needed informations.

Fa is a musical note to play with CL

Zen

TOUT EN MASM.
:bgrin: :bgrin: :bgrin: Unbelievable !!! It WORKED !!! I was BLOWN AWAY !!! (This is an annoying English slang phrase.)  :dazzled: :dazzled: :dazzled:
I tried the most complex file I could find: The IDL definitions of the IWBEM interfaces,...these are the interfaces you invoke when you are trying to retrieve hardware information about the local computer with WMI.
I have attached a zip directory below with the file that I used as an experiment. It didn't work perfectly (at least, not in the format I was trying to achieve, but, it did translate almost the complete file.) There were some minor errors, so the file didn't save correctly, but the translation was readable in the rich edit box.
You must have a terrific sense of humor,...I loved all the comments in FRENCH. Thoroughly confusing,...but,completely functional,... :dazzled:

Zen

As an example, here is the C language Interface definition from the file, wbemcli.h (which I found on the internet)

;********************************************************************************************************
;    This is the IWbemServices C-style virtual function table struct definition from, wbemcli.h   
;*************************************************************************************************************
;
;    typedef struct IWbemServicesVtbl
;    {
;        BEGIN_INTERFACE
;       
;        HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
;            IWbemServices * This,
;            /* [in] */ REFIID riid,
;            /* [iid_is][out] */ void **ppvObject);
;       
;        ULONG ( STDMETHODCALLTYPE *AddRef )(
;            IWbemServices * This);
;       
;        ULONG ( STDMETHODCALLTYPE *Release )(
;            IWbemServices * This);
;       
;        HRESULT ( STDMETHODCALLTYPE *OpenNamespace )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strNamespace,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [unique][in][out] */ IWbemServices **ppWorkingNamespace,
;            /* [unique][in][out] */ IWbemCallResult **ppResult);
;       
;        HRESULT ( STDMETHODCALLTYPE *CancelAsyncCall )(
;            IWbemServices * This,
;            /* [in] */ IWbemObjectSink *pSink);
;       
;        HRESULT ( STDMETHODCALLTYPE *QueryObjectSink )(
;            IWbemServices * This,
;            /* [in] */ long lFlags,
;            /* [out] */ IWbemObjectSink **ppResponseHandler);
;       
;        HRESULT ( STDMETHODCALLTYPE *GetObject )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strObjectPath,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [unique][in][out] */ IWbemClassObject **ppObject,
;            /* [unique][in][out] */ IWbemCallResult **ppCallResult);
;       
;        HRESULT ( STDMETHODCALLTYPE *GetObjectAsync )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strObjectPath,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [in] */ IWbemObjectSink *pResponseHandler);
;       
;        HRESULT ( STDMETHODCALLTYPE *PutClass )(
;            IWbemServices * This,
;            /* [in] */ IWbemClassObject *pObject,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [unique][in][out] */ IWbemCallResult **ppCallResult);
;       
;        HRESULT ( STDMETHODCALLTYPE *PutClassAsync )(
;            IWbemServices * This,
;            /* [in] */ IWbemClassObject *pObject,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [in] */ IWbemObjectSink *pResponseHandler);
;       
;        HRESULT ( STDMETHODCALLTYPE *DeleteClass )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strClass,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [unique][in][out] */ IWbemCallResult **ppCallResult);
;       
;        HRESULT ( STDMETHODCALLTYPE *DeleteClassAsync )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strClass,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [in] */ IWbemObjectSink *pResponseHandler);
;       
;        HRESULT ( STDMETHODCALLTYPE *CreateClassEnum )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strSuperclass,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [out] */ IEnumWbemClassObject **ppEnum);
;       
;        HRESULT ( STDMETHODCALLTYPE *CreateClassEnumAsync )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strSuperclass,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [in] */ IWbemObjectSink *pResponseHandler);
;       
;        HRESULT ( STDMETHODCALLTYPE *PutInstance )(
;            IWbemServices * This,
;            /* [in] */ IWbemClassObject *pInst,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [unique][in][out] */ IWbemCallResult **ppCallResult);
;       
;        HRESULT ( STDMETHODCALLTYPE *PutInstanceAsync )(
;            IWbemServices * This,
;            /* [in] */ IWbemClassObject *pInst,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [in] */ IWbemObjectSink *pResponseHandler);
;       
;        HRESULT ( STDMETHODCALLTYPE *DeleteInstance )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strObjectPath,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [unique][in][out] */ IWbemCallResult **ppCallResult);
;       
;        HRESULT ( STDMETHODCALLTYPE *DeleteInstanceAsync )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strObjectPath,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [in] */ IWbemObjectSink *pResponseHandler);
;       
;        HRESULT ( STDMETHODCALLTYPE *CreateInstanceEnum )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strFilter,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [out] */ IEnumWbemClassObject **ppEnum);
;       
;        HRESULT ( STDMETHODCALLTYPE *CreateInstanceEnumAsync )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strFilter,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [in] */ IWbemObjectSink *pResponseHandler);
;       
;        HRESULT ( STDMETHODCALLTYPE *ExecQuery )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strQueryLanguage,
;            /* [in] */ const BSTR strQuery,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [out] */ IEnumWbemClassObject **ppEnum);
;       
;        HRESULT ( STDMETHODCALLTYPE *ExecQueryAsync )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strQueryLanguage,
;            /* [in] */ const BSTR strQuery,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [in] */ IWbemObjectSink *pResponseHandler);
;       
;        HRESULT ( STDMETHODCALLTYPE *ExecNotificationQuery )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strQueryLanguage,
;            /* [in] */ const BSTR strQuery,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [out] */ IEnumWbemClassObject **ppEnum);
;       
;        HRESULT ( STDMETHODCALLTYPE *ExecNotificationQueryAsync )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strQueryLanguage,
;            /* [in] */ const BSTR strQuery,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [in] */ IWbemObjectSink *pResponseHandler);
;       
;        HRESULT ( STDMETHODCALLTYPE *ExecMethod )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strObjectPath,
;            /* [in] */ const BSTR strMethodName,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [in] */ IWbemClassObject *pInParams,
;            /* [unique][in][out] */ IWbemClassObject **ppOutParams,
;            /* [unique][in][out] */ IWbemCallResult **ppCallResult);
;       
;        HRESULT ( STDMETHODCALLTYPE *ExecMethodAsync )(
;            IWbemServices * This,
;            /* [in] */ const BSTR strObjectPath,
;            /* [in] */ const BSTR strMethodName,
;            /* [in] */ long lFlags,
;            /* [in] */ IWbemContext *pCtx,
;            /* [in] */ IWbemClassObject *pInParams,
;            /* [in] */ IWbemObjectSink *pResponseHandler);
;       
;        END_INTERFACE
;    } IWbemServicesVtbl;
;
;*************************************************************************************************************


...And, this is the translation of that Interface to a MASM compatible Structure that I did manually, using the METHOD macro,...(I high-jacked this technique from QWORD)

;********************************************************************************************************
;    The following macro is taken from a MASM forum example written by QWORD   
;*************************************************************************************************************

METHOD macro name,args:VARARG
LOCAL _type1,_type2

_type1 TYPEDEF proto args
_type2 TYPEDEF ptr _type1
EXITM <name _type2 ?>
endm
;*************************************************************************************************************

;    This is the IWbemServices virtual function table struct definition imitated from QWORD example, wbemcli.h    This interface has 26 methods   
;*************************************************************************************************************

IWbemServices STRUCT

METHOD(QueryInterface, _this:PVOID, riid:ptr GUID, ppvObj:ptr LPVOID)
METHOD(AddRef, _this:PVOID)
METHOD(Release, _this:PVOID)

;     pCtx is a pointer to IWbemContext, ppWorkingNamespace is a pointer to a pointer to IWbemServices, ppResult is a pointer to a pointer to IWbemCallResult.       
      METHOD(OpenNamespace, _this:PVOID, strNamespace:DWORD, lFlags:LONG, pCtx:DWORD, ppWorkingNamespace:DWORD, ppResult:LPVOID)   
     
;     pSink is a pointer to IWbemObjectSink
      METHOD (CancelAsyncCall, _this:PVOID, pSink:LPVOID)

;     ppResponseHandler is a pointer to a pointer to IWbemObjectSink
      METHOD (QueryObjectSink, _this:PVOID, lFlags:LONG, ppResponseHandler:LPVOID)

;     strObjectPath is a BSTR, pCtx is a pointer to IWbemContext, ppObject is a pointer to a pointer to IWbemClassObject, ppCallResult is a pointer to a pointer to IWbemCallResult.   
      METHOD (GetObject, _this:PVOID, strObjectPath:DWORD, lFlags:LONG, pCtx:DWORD, ppObject:DWORD, ppCallResult:DWORD)

;     strObjectPath is a BSTR, pCtx is a pointer to IWbemContext, pResponseHandler is a pointer to IWbemObjectSink.     
      METHOD(GetObjectAsync, _this:PVOID, strObjectPath:DWORD, lFlags:LONG, pCtx:DWORD, pResponseHandler:DWORD)

;     pObject is a pointer to IWbemClassObject, pCtx is a pointer to IWbemContext, ppCallResult is a pointer to a pointer to IWbemCallResult.   
      METHOD (PutClass, _this:PVOID, pObject:DWORD, lFlags:LONG, pCtx:DWORD, ppCallResult:DWORD)

;     pObject is a pointer to IWbemClassObject, pCtx is a pointer to IWbemContext, pResponseHandler is a pointer to IWbemObjectSink.     
      METHOD(PutClassAsync, _this:PVOID, pObject:DWORD, lFlags:LONG, pCtx:DWORD, pResponseHandler:LPVOID)

;     strClass is a BSTR, pCtx is a pointer to IWbemContext, ppCallResult is a pointer to a pointer to IWbemCallResult.   
      METHOD(DeleteClass, _this:PVOID, strClass:DWORD, lFlags:LONG, pCtx:DWORD, ppCallResult:DWORD)

;     strClass is a BSTR, pCtx is a pointer to IWbemContext, pResponseHandler is a pointer to IWbemObjectSink.     
      METHOD(DeleteClassAsync, _this:PVOID, strClass:DWORD, lFlags:LONG, pCtx:DWORD, pResponseHandler:LPVOID)

;     strSuperclass is a BSTR, pCtx is a pointer to IWbemContext, ppEnum is a pointer to a pointer to IEnumWbemClassObject.     
      METHOD(CreateClassEnum, _this:PVOID, strSuperclass:DWORD, lFlags:LONG, pCtx:DWORD, ppEnum:LPVOID)

;     strSuperclass is a BSTR, pCtx is a pointer to IWbemContext, pResponseHandler is a pointer to IWbemObjectSink.     
      METHOD(CreateClassEnumAsync, _this:PVOID, strSuperclass:DWORD, lFlags:LONG, pCtx:DWORD, pResponseHandler:LPVOID)

;     pInst is a pointer to IWbemClassObject, pCtx is a pointer to IWbemContext, ppCallResult is a pointer to a pointer to IWbemCallResult.   
      METHOD(PutInstance, _this:PVOID, pInst:DWORD, lFlags:LONG, pCtx:DWORD, ppCallResult:DWORD)

;     pInst is a pointer to IWbemClassObject, pCtx is a pointer to IWbemContext, pResponseHandler is a pointer to IWbemObjectSink.     
      METHOD(PutInstanceAsync, _this:PVOID, pInst:DWORD, lFlags:LONG, pCtx:DWORD, pResponseHandler:LPVOID)

;     strObjectPath is a BSTR, pCtx is a pointer to IWbemContext, ppCallResult is a pointer to a pointer to IWbemCallResult.   
      METHOD(DeleteInstance, _this:PVOID, strObjectPath:DWORD, lFlags:LONG, pCtx:DWORD, ppCallResult:DWORD)

;     strObjectPath is a BSTR, pCtx is a pointer to IWbemContext, pResponseHandler is a pointer to IWbemObjectSink.     
      METHOD(DeleteInstanceAsync, _this:PVOID, strObjectPath:DWORD, lFlags:LONG, pCtx:DWORD, pResponseHandler:LPVOID)

;     strFilter is a BSTR, pCtx is a pointer to IWbemContext, ppEnum is a pointer to a pointer to IEnumWbemClassObject.     
      METHOD(CreateInstanceEnum, _this:PVOID, strFilter:DWORD, lFlags:LONG, pCtx:DWORD, ppEnum:LPVOID)

;     strFilter is a BSTR, pCtx is a pointer to IWbemContext, pResponseHandler is a pointer to IWbemObjectSink.     
      METHOD(CreateInstanceEnumAsync, _this:PVOID, strFilter:DWORD, lFlags:LONG, pCtx:DWORD, pResponseHandler:LPVOID)

;     strQueryLanguage is a BSTR, strQuery is a BSTR, pCtx is a pointer to IWbemContext, ppEnum is a pointer to a pointer to IEnumWbemClassObject.   
      METHOD (ExecQuery, _this:PVOID, strQueryLanguage:DWORD, strQuery:DWORD, lFlags:LONG, pCtx:DWORD, ppEnum:LPVOID)

;     strQueryLanguage is a BSTR, strQuery is a BSTR, pCtx is a pointer to IWbemContext, pResponseHandler is a pointer to IWbemObjectSink.     
      METHOD(ExecQueryAsync, _this:PVOID, strQueryLanguage:DWORD, strQuery:DWORD, lFlags:LONG, pCtx:DWORD, pResponseHandler:LPVOID)

;     strQueryLanguage is a BSTR, strQuery is a BSTR, pCtx is a pointer to IWbemContext, ppEnum is a pointer to a pointer to IEnumWbemClassObject.   
      METHOD(ExecNotificationQuery, _this:PVOID, strQueryLanguage:DWORD, strQuery:DWORD, lFlags:LONG, pCtx:DWORD, ppEnum:LPVOID)

;     strQueryLanguage is a BSTR, strQuery is a BSTR, pCtx is a pointer to IWbemContext, pResponseHandler is a pointer to IWbemObjectSink.     
      METHOD(ExecNotificationQueryAsync, _this:PVOID, strQueryLanguage:DWORD, strQuery:DWORD, lFlags:LONG, pCtx:DWORD, pResponseHandler:LPVOID)

;     strObjectPath is a BSTR, strMethodName is a BSTR, pCtx is a pointer to IWbemContext, pInParams is a pointer to IWbemClassObject, ppCallResult is a pointer to a pointer to IWbemCallResult.   
      METHOD(ExecMethod, _this:PVOID, strObjectPath:DWORD, strMethodName:DWORD, lFlags:LONG, pCtx:DWORD, pInParams:DWORD, ppOutParams:LPVOID, ppCallResult:LPVOID)

;     strObjectPath is a BSTR, strMethodName is a BSTR, pCtx is a pointer to IWbemContext, pInParams is a pointer to IWbemClassObject, pResponseHandler is a pointer to IWbemObjectSink.     
      METHOD(ExecMethodAsync, _this:PVOID, strObjectPath:DWORD, strMethodName:DWORD, lFlags:LONG, pCtx:DWORD, pInParams:DWORD, pResponseHandler:LPVOID)

IWbemServices ENDS

;*************************************************************************************************************


I like this technique better than using the CoInvoke macro, because it is almost foolproof. And, it works great !!!
You call the Interface method like this:

mov esi, ptrIWbemServices    ;    valid pointer returned from IWbemLocator.ConnectServer
mov esi,[esi] ; ptr IWbemServices virtual function table   

invoke [esi].IWbemServices.ExecQuery, ptrIWbemServices, ADDR bstrWQL, ADDR bstrQryNetwrkAdptr, lFlgsNetwrkAdptr, NULL, ADDR ptrIEnumWbemClassObj   

Zen

If you want to play around with the concept, and you don't have Visual Studio, I downloaded the MIDL Compiler from some mysterious source on the Internet. The attached zip directory contains the executable.
MODERATOR ALERT !!! (I suspect that this might be an unauthorized copy.)

Here is MSDN's: Microsoft Interface Definition Language Reference, with Guide to Using the MIDL Compiler

TouEnMasm

The wbemcli.h and other WMI header's file are part of the windows sdk 7.1 and already translated  in
the ready to use windows sdk:
http://masm32.com/board/index.php?topic=563.msg4563#msg4563
The version of midl you have got is an old version 5.00.1802.1
The windows sdk 7.1 had the 6.1.7600.16385 version.

Fa is a musical note to play with CL

Zen

TOUT EN MASM.   
Thanks for everything. That translated SDK cab collection is an immense amount of work.

dedndave

it is - and a great reference, too   :t