News:

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

Main Menu

ADODB, CoCreateInstance(&CLSID_Recordset...:Strange differences C/Assembly

Started by jj2007, January 08, 2024, 08:55:26 AM

Previous topic - Next topic

jj2007

hr = CoCreateInstance(&CLSID_Recordset, NULL, CLSCTX_ALL, &IID_Recordset15, (void **)&pRecSet); //pointer to RECORDSET15
invoke CoCreateInstance, addr CLSID_Recordset, 0, CLSCTX_INPROC_SERVER, addr IID_Recordset, addr pRecSet
The good news: both versions work like a charm :thumbsup:

Now the bad news: a closer look with Olly reveals that Pelles C pushes 48 bytes on the stack before calling the interface; the Assembly code pushes only 20 bytes.

After the call, the stack is balanced in both cases.

Do I miss something?

P.S.: What is the purpose of the lpVtbl keyword in Pelles C? In Assembly, it's just a dot:
hr = pRecSet->lpVtbl->Open(pRecSet, v1, v2, adOpenKeyset, adLockUnspecified, adCmdText);
CoInvoke pConn, Connection15.Open_, Ole$(dbName$), MbNull$, MbNull$, -1

TimoVJL

typedef struct _RecordsetVtbl {
    /* IUnknown methods */
    HRESULT (STDMETHODCALLTYPE *QueryInterface)(_Recordset *This,GUID*,void**);
    ULONG (STDMETHODCALLTYPE *AddRef)(_Recordset *This);
    ULONG (STDMETHODCALLTYPE *Release)(_Recordset *This);
...
    HRESULT (STDMETHODCALLTYPE *Open)(_Recordset *This,VARIANT,VARIANT,enum CursorTypeEnum,enum LockTypeEnum,LONG);
...
    HRESULT (STDMETHODCALLTYPE *Save)(_Recordset *This,VARIANT,enum PersistFormatEnum);
} _RecordsetVtbl;
interface _Recordset { const _RecordsetVtbl *lpVtbl; };

macro:
#define _Recordset_Open(This,_1,_2,_3,_4,_5)  (This)->lpVtbl->Open(This,_1,_2,_3,_4,_5)
May the source be with you