News:

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

Main Menu

What the %*&!^? is COM?

Started by NoCforMe, June 28, 2024, 01:08:27 PM

Previous topic - Next topic

daydreamer

Quote from: _japheth on June 29, 2024, 04:40:47 PM
Quote from: NoCforMe on June 29, 2024, 08:07:12 AMMore questions about COM:
3. Who here has successfully wrestled with COM and gotten it to work with assembly language? (32-bit preference here)

See
https://masm32.com/board/index.php?topic=10807.0

https://masm32.com/board/index.php?topic=8773.0

The latter one may be especially interesting, since it allows to generate include libs from type libs.
[and btw. it also shows how extraordinary good friends Hutch and I were  :bgrin: ]
All asm DX demos/ games are using com interface independent of my old ddraw code, dx8,dx9,dx10,dx11,dx12 asm code uses custom invoke like siekmanski coinvoke first get address in table and call
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

NoCforMe

Quote from: sinsi on June 29, 2024, 09:28:30 PMUuidCreate function
So can that be used as a stand-alone function? No need to do any kind of network initialization? it just reaches out over the Intertubes and grabs a GUID?

If so, kewl! I could easily write my own GUIDGEN.EXE.
Assembly language programming should be fun. That's why I do it.

Vortex

#17
Hi NoCforMe,

QuoteSo can that be used as a stand-alone function?

Exactly. Here is an example :

#include "stdafx.h"
#pragma comment(lib, "rpcrt4.lib")  // UuidCreate - Minimum supported OS Win 2000
#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
    UUID uuid;
    UuidCreate(&uuid);
    char *str;
    UuidToStringA(&uuid, (RPC_CSTR*)&str);
    cout << str << endl;
    RpcStringFreeA((RPC_CSTR*)&str);
    return 0;
}

https://github.com/tillo/UuidCreate/blob/master/ucwrap/ucwrap/ucwrap.cpp

NoCforMe

Quote from: sinsi on June 29, 2024, 09:28:30 PMUuidCreate function
OK, I tried that.
Problems!
1. There's no mention of UuidCreate() in any of the Masm32 stuff (include files). There is, however, reference to ExUuidCreate(), which seems to do the exact same thing.
2. OK, fine. Except that I couldn't link the program because apparently there's no includelib for that function anywhere.
3. OK, fine. I used LoadLibrary() and GetProcAddress() to get a pointer to that function in its DLL (ntoskrnl.exe).
4. OK, fine, I was able to get the proc address. But when I called it, I got an access violation inside the DLL.

(32-bit program here; is the DLL also 32-bit?)

Aaargh! Any suggestions? Vortex said it would be easy ...
Assembly language programming should be fun. That's why I do it.

GoneFishing

#19
Hi NoCforMe,

I remember 10 years ago we played with COM here.
See https://masm32.com/board/index.php?topic=3215.msg33806#msg33806

We found that METHOD macro by qWord  was the best for our purpose.
;METHOD macro by qWord

METHOD  MACRO   name,args:VARARG
        LOCAL   _type1,_type2
        _type1  TYPEDEF PROTO args
        _type2  TYPEDEF PTR _type1
        EXITM   <name _type2 ?>
        ENDM

Interface structures must be defined like this
IDispatch STRUCT
  METHOD(QueryInterface,   _this:LPVOID,riid:LPVOID,ppvObj:LPVOID)
  METHOD(AddRef,           _this:LPVOID)
  METHOD(Release,          _this:LPVOID)
  METHOD(GetTypeInfoCount, _this:LPVOID,pctinfo:UINT)
  METHOD(GetTypeInfo,      _this:LPVOID,iTInfo:UINT,lcid:LCID,ppTInfo:LPVOID)
  METHOD(GetIDsOfNames,    _this:LPVOID,riid:LPVOID,rgszNames:LPOLESTR,cNames:UINT,lcid:LCID,rgDispId:LPVOID)
  METHOD(dInvoke,          _this:LPVOID,dispIdMember:DWORD,riid:LPVOID,lcid:LCID,wFlags:DWORD,pDispParams:LPVOID,pVarResult:LPVOID,pExcepInfo:LPVOID,puArgErr:UINT)
IDispatch ENDS

If you can find Colib pack by Ernest Murphy  ( I don't have a link to  it ) it may help you to understand how to work with COM in assembly. It has docs folder:

QuoteHaving no idea what one may come here seeking, I make no statement as to
what order you should review this material.

However, those who would wish a path to follow may find this order acceptable:

    Accessing COM Objects from Assembly.doc
   
    Standard for COM in MASM32.doc
   
    Adapting Quick Editor for COM.doc
   
    Creating a COM object in ASM.doc
   
    MyCom2 and the CoLib.doc
   
    Inside CoLib.doc
   
    UsingCoLib to Build a Visual Control.doc



Vortex

Hi NoCforMe,

Can you try the code below?

include     \masm32\include\masm32rt.inc
include     \masm32\include\rpcrt4.inc

includelib  \masm32\lib\rpcrt4.lib

.data


.data?

u1      _GUID <?>
buffer  dd ?

.code

start:

    invoke  UuidCreate,ADDR u1
    invoke  UuidToString,ADDR u1,ADDR buffer
    invoke  StdOut,buffer
    invoke  RpcStringFree,ADDR buffer

    invoke  ExitProcess,0

END start

NoCforMe

#21
Thanks; I arrived at the same solution but by a roundabout way, finding UuidCreate() in rpcrt4.dll (using LoadLibrary() and GetProcAddress()), and yes, it works. (I didn't know about those other include files.)

I'm just curious about one thing: every time we call UuidCreate(), that means one less GUID in the world, correct? Any chance they could run out of them eventually? I just wasted 8 or 10 myself.

Lessee: 32 hex digits, so that means there are what, 16^32 possible combos? (Are all combinations valid?) Not even sure what number that is. Pretty big, though.

Found an article on Stack Overflow on this very subject. Apparently there's no danger of us running out of GUIDs any time soon.
Assembly language programming should be fun. That's why I do it.

TimoVJL

Can CoCreateGuid ever return GUID_NULL?  Raymond Chen


...
// create UNICODE string like "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
wchar_t s[50];
StringFromGUID2(&uuid, s, sizeof(s));
printf("%ls\n", s);
...
May the source be with you

NoCforMe

Assembly language programming should be fun. That's why I do it.

TimoVJL

Edgar made a Help 2 Viewer over ten years ago and i used it with poide help system.
Was written with GoAsm.
May the source be with you

NoCforMe

Assembly language programming should be fun. That's why I do it.