News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Macro to call object's functions

Started by TNick, November 29, 2006, 10:24:52 AM

Previous topic - Next topic

TNick

Hi!

Here is yet another macro to call COM functions. I posted it so you can tell me your opinion on how it written, maybe some suggestions, ...
This is how it works:


- first, you need to declare a structure with that object's content, using the MAKE_COMVOKE_PROTO macro:
It is defined like this:
MAKE_COMVOKE_PROTO    MACRO  ObjName:REQ,FunctionName:REQ,Arguments:VARARG
ObjName - for all members of a structure this will be the same: name of that structure
FunctionName - name of that function; this name will be inserted as a declaration at macro location
FunctionName  DWORD   ?
Arguments - list of arguments, comma separated; those can be named or unnamed arguments
Arg1:DWORD,ARG2:RECT,:RECT,:BYTE
this will be inserted as a TEXTEQU at macro location, in the form:
ObjName___FunctionName TEXTEQU <:BYTE,:RECT,ARG2:RECT,Arg1:DWORD
Here is an example for IShellFolder object

IShellFolder    STRUCT
    MAKE_COMVOKE_PROTO    IShellFolder,QueryInterface,:DWORD,:DWORD
    MAKE_COMVOKE_PROTO    IShellFolder,AddRef
    MAKE_COMVOKE_PROTO    IShellFolder,Release
   
    MAKE_COMVOKE_PROTO    IShellFolder,ParseDisplayName,hwndOwner:DWORD,pbcReserved:DWORD,lpszDisplayName:DWORD,pchEaten:DWORD,ppidl:DWORD,pdwAttributes:DWORD
    MAKE_COMVOKE_PROTO    IShellFolder,EnumObjects,hwndOwner:DWORD,grfFlags:DWORD,ppenumIDList:DWORD
    MAKE_COMVOKE_PROTO    IShellFolder,BindToObject,pidl:DWORD,pbcReserved:DWORD,riid:DWORD,ppvOut:DWORD
    MAKE_COMVOKE_PROTO    IShellFolder,BindToStorage
    MAKE_COMVOKE_PROTO    IShellFolder,CompareIDs,lParam:DWORD,pidl1:DWORD,pidl2:DWORD
    MAKE_COMVOKE_PROTO    IShellFolder,CreateViewObject,hwndOwner:DWORD,riid:DWORD,ppvOut:DWORD
    MAKE_COMVOKE_PROTO    IShellFolder,GetAttributesOf,cidl:DWORD,apidl:DWORD,rgfInOut:DWORD
    MAKE_COMVOKE_PROTO   IShellFolder,GetUIObjectOf,hwndOwner:DWORD,cidl:DWORD,apidl:DWORD,riid:DWORD,prgfInOut:DWORD,ppvOut:DWORD
    MAKE_COMVOKE_PROTO    IShellFolder,GetDisplayNameOf,pidl:DWORD,uFlags:DWORD,lpName:DWORD
    MAKE_COMVOKE_PROTO    IShellFolder,SetNameOf,hwndOwner:DWORD,pidl:DWORD,lpszName:DWORD,uFlags:DWORD,ppidlOut:DWORD
IShellFolder     ENDS



- (This is optional) second, you may want to associate a specific variable in your .DATA, .DATA?, .CONST section as a object, using SET_OBJECT_TYPE macro, defined like this.:
SET_OBJECT_TYPE   MACRO    ObjName:REQ,ObjectType:REQ
ObjName - name of your variable
ObjectType - name of that object (a structure)
The only thing that it does is to generate a TEXTEQU:
ObjName_TYPE   TEXTEQU <ObjectType>
Here is an example:
ShF_Desktop        DWORD      ?
SET_OBJECT_TYPE    ShF_Desktop,IShellFolder



- now, you are ready to use COMVOKE macro in your code. It is defined like this:
COMVOKE      MACRO     Object_Proc:REQ,Arguments:VARARG
If you didn't use SET_OBJECT_TYPE macro, or if Object_Proc is a register, you must use this form for Object_Proc:
MyVarName.ObjectType.FunctionName
If you use it, there is no need for .ObjectType:
MyVarName.FunctionName
Arguments - arguments for that function, just like INVOKE
Example in attached project.



The project is very simple. It uses TreeView control to show folders in your computer, using Shell objects. It was written to show COMVOKE functionality, in a big rush, so don't be too hard on it. :)
I did't post this in <User contributed code> because I am shure it can be improved. I am thinking about handling immediate REAL constants, but I don't know the algo to convert in a DWORD that REAL4, so the macro can push it on the stack.
I am waiting for your suggestions.

[EDIT]
Note that you can't use a pointer to a object stored in a structure
This will not work.
COMVOKE  SomeStruct.Object.IShellFolder.Release
Maybe a notation like this:
MyVarName::ObjectType::FunctionName
or like this:
MyVarName::ObjectType->FunctionName
would be more appropriate...
[/EDIT]

[EDIT]
It looks like there is a problem with immediates.
1 doesn't work, but dword ptr 1 works as an argument.
Back to debug ...
[/EDIT]

Regards,
Nick




[attachment deleted by admin]

xandaz

   Hey TNick.... Isn't there a simpler way to call IShellFolder functions... I don't really like macros. Thanks