News:

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

Help with COM.

Started by xanatose, August 09, 2010, 07:56:09 PM

Previous topic - Next topic

xanatose

Does anyone knows a good tutorial of using COM (Component Object Model) without using ATL or MFC (or visual basic)?

Preferably in C or assembler.


dancho

yeah,in C

http://www.codeproject.com/KB/COM/com_in_c1.aspx

8 parts tutorial in total,
just use search to find others...

ecube

here's a vbscript regexp example using Minors nice api http://www.masm32.com/board/index.php?topic=14507.0

his site is http://www.bostream.nu/minor28/, I highly recommend you check out his automation tool/examples.

but COM is really easily just find the interface you want say for IPersistantFile(used to make shortcuts) http://msdn.microsoft.com/en-us/library/ms687223%28v=VS.85%29.aspx

see the list of methods(functions) on that page? you have IsDirty,load,save etc...because it uses the iunknown interface(which has 3 entries) too if you combine them it could look like this as a structure

 IPersistFile            STRUCT
      IPersistFile_QueryInterface      dd       ? <-is iunknown
      IPersistFile_AddRef               dd       ? <-is iunknown
      IPersistFile_Release              dd       ?  <-is iunknown
      IPersistFile_IsDirty              dd       ?
      IPersistFile_Load                 dd       ?
      IPersistFile_Save                 dd      ?
      IPersistFile_SaveCompleted   dd       ?
      IPersistFile_GetCurFile           dd       ?
IPersistFile            ENDS

ok so we have our structure to use the methods all you do is cocreateinstance using the  this interface which according to msdn it's IIID is IID_IPersistFile is defined as 0000010b-0000-0000-C000-000000000046

after we use that it'll return the interface ptr in a dword and you just

mov eax,[theptr]
mov eax,[eax]

now we have a memory ptr to the vtable so to access a method just add it from the start if this were goasm id do

invoke [eax+IPersistFile.IPersistFile_Load], [theptr], param1,param2,param3

or if you wanted manually could do
invoke [eax+16], [theptr], param1,param2,param3 ;since IPersistFile_Load is 16 down


just remember that the first parameter is always the the current interface pointer you're currently using, in our case the one we got from cocreateinstance

I have some COM tuts/examples somewhere written by murphy they use to be in masm32 but hutch took em out, i'll try and find for you.

Oh and the methods I believe are always cdecl(c calling convention) so you have to adjust esp after the call.

also you can get other interface pointers using the QueryInterface method above http://msdn.microsoft.com/en-us/library/ms682521%28VS.85%29.aspx

oex

We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

baltoro

The best site I have ever found for COM assembly code is: Japheth's Site.
...It's amazing, Really.
Baltoro

ecube

also all interface methods definitely aren't cdecl.

xanatose

#6
Wow, that was fast. Thanks everyone.

[EDIT]
BTW:
If you only have a dll and not a header, how do you get the interfaces, enums, etc? On Visual C++, you use #import and it will generate a header. But I wonder how this is done via the windows API. (so I can make the project Independent of Visual C++)

Rockoon

Quote from: E^cube on August 10, 2010, 12:39:23 AM
also all interface methods definitely aren't cdecl.

definitely STDCALL.
When C++ compilers can be coerced to emit rcl and rcr, I *might* consider using one.

ecube

Quote from: Rockoon on August 10, 2010, 04:20:37 PM
Quote from: E^cube on August 10, 2010, 12:39:23 AM
also all interface methods definitely aren't cdecl.

definitely STDCALL.

some can be cdecl I messed with one that was last night, directx probably is too


askm

Minor28,

Please inform per your StringFunctions.lib, as it is not error free. ::)