//constants////////////////////////////////////////////////////////////////////
#define E_NOTIMPL                       0x80004001
#define E_NOINTERFACE                   0x80004002
#define E_FAIL                          0x80004005
#define CLASS_E_NOAGGREGATION           0x80040110
#define CLASS_E_CLASSNOTAVAILABLE       0x80040111
#define SELFREG_E_CLASS                 0x80040201
#define E_OUTOFMEMORY                   0x8007000E
#define S_OK                            0
#define S_FALSE                         1

// constants for ITlbContainer::UpdateButtonInfo
#define UPDATE_SIZE                     0x01
#define UPDATE_REDRAW                   0x02
#define UPDATE_TOOLTIP                  0x04

// constants for BUTTONINFO.dwMask
#define BTNINFO_MASK_MODEFLAG           0x01
#define BTNINFO_MASK_ACTIONS            0x02
#define BTNINFO_MASK_SIZE               0x04
#define BTNINFO_MASK_ICON               0x08
#define BTNINFO_MASK_SELECTEDICON       0x10
#define BTNINFO_MASK_DESCRIPTION        0x20
#define BTNINFO_MASK_TEXT               0x40
#define BTNINFO_MASK_ACTUALSIZE         0x80

// constants for BUTTONINFO.dwModeFlags
#define BTN_FLAG_PLANE          0x00000001
#define BTN_FLAG_STOPDRAG       0x00000002

// constants for BUTTONINFO.dwActions
#define CTMS_PROPERTIES 0x01
#define CTMS_RENAME     0x02
#define CTMS_CHANGEICON 0x04
#define CTMS_HOVERRUN   0x20
//#define CTMS_PASSWORD 0x40

//types////////////////////////////////////////////////////////////////////////
struct BUTTONINFO {
    DWORD dwMask;
    DWORD dwModeFlags;
    DWORD dwActions;
    SIZE  szBtnSize;
    dword hIcon;
    char strData[ 500 ];
};

struct CONTAINER_PARAMS{
    int cbSize;
    int dwViewMode;
    int style;
    dword bkColor;
    dword hItemFont;
    dword dwLCID;
};
//guids////////////////////////////////////////////////////////////////////////
GUID CLSID_StdComponentCategoriesMgr={
  0x0002e005,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 };

GUID IID_ICatRegister={
  0x0002E012,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 };

GUID IID_IUnknown={
  0x00000000,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 };

GUID IID_IClassFactory={
  0x00000001,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 };


GUID CATID_TLBBUTTONS = { /* 49e86696-eaa6-45a2-9480-c78c013b9713 */
  0x49e86696,0xeaa6,0x45a2,0x94,0x80,0xc7,0x8c,0x01,0x3b,0x97,0x13 };

GUID IID_ITlbButton = {
  0xAB1982DF,0x9DA2,0x4FB4,0x96,0x95,0xF2,0x3F,0xB1,0xF6,0xE8,0x5F };

//classes//////////////////////////////////////////////////////////////////////
struct IUnknownVtbl{
  dword (*QueryInterface)();
  dword (*AddRef)();
  dword (*Release)();
};

struct IMallocVtbl{
  dword (*QueryInterface)();
  dword (*AddRef)();
  dword (*Release)();

  dword (*Alloc)(dword cb);
  dword (*Realloc)(dword pv,cb);
  dword Free;//dword (*Free)(dword pv);//+++void
  dword (*GetSize)(dword pv);
  int   (*DidAlloc)(dword pv);
  dword (*HeapMinimize)(void);//+++void
};

struct ICatRegisterVtbl{
  dword (*QueryInterface)(dword riid,dword ppvObject);
  dword (*AddRef)();
  dword (*Release)();
  dword (*RegisterCategories)(dword cCategories,dword rgCategoryInfo);
  dword (*UnRegisterCategories)(dword cCategories,dword rgcatid);
  dword (*RegisterClassImplCategories)(dword rclsid,dword cCategories,dword rgcatid);
  dword (*UnRegisterClassImplCategories)(dword rclsid,dword cCategories,dword rgcatid);
  dword (*RegisterClassReqCategories)(dword rclsid,dword cCategories,dword rgcatid);
  dword (*UnRegisterClassReqCategories)(dword rclsid,dword cCategories,dword rgcatid);
};

struct IClassFactoryVtbl{
   //IUnknown methods
   dword (*QueryInterface)(dword,dword);
   dword (*AddRef)();
   dword (*Release)();

   //IClassFactory methods
   dword (*CreateInstance)(dword,dword,dword);
   dword (*LockServer)(dword);

};

struct IStreamVtbl{
   dword (*QueryInterface)(dword,dword);
   dword (*AddRef )();
   dword (*Release)();
   dword (*Read)(dword pv,cb,pcbRead);
   dword (*Write)(dword pv,cb,pcbWritten);
   dword (*Seek)(dword dlibMove,dwOrigin,plibNewPosition);
   dword (*SetSize)(dword libNewSize);
   dword (*CopyTo)(dword pstm,cb,pcbRead,pcbWritten);
   dword (*Commit)(dword grfCommitFlags);
   dword (*Revert)();
   dword (*LockRegion)(dword libOffset,dword cb,dword dwLockType);
   dword (*UnlockRegion)(dword libOffset,dword cb,dwLockType);
   dword (*Stat)(dword pstatstg,grfStatFlag);
   dword (*Clone)(dword ppstm);
};

struct ITlbButtonVtbl{
    dword   stdcall (*QueryInterface)(dword riid,dword ppvObject);
    ULONG   stdcall (*AddRef)();
    ULONG   stdcall (*Release)();
    dword   stdcall (*Load)(dword data);
    dword   stdcall (*Save)(dword data);
    dword   stdcall (*SetRect)(dword rcItem);
    dword   stdcall (*SetContainer)(dword cont);
    dword   stdcall (*SetID)(int btnID);
    dword   stdcall (*Draw)(dword hDC,dword rcItem);
    dword   stdcall (*OnMouseOver)(long keys,int x,int y);
    dword   stdcall (*OnMouseLeave)(long keys);
    dword   stdcall (*OnMouseEnter)(long keys,int x,int y);
    dword   stdcall (*Create)(dword data);
    dword   stdcall (*StateChanged)(int state,dword needRedraw);
    dword   stdcall (*OnLButtonDown)(long key,int x,int y);
    dword   stdcall (*OnLButtonUp)(long key,int x,int y);
    dword   stdcall (*Run)();
    dword   stdcall (*DoAction)(int action);
    dword   stdcall (*SetName)(dword szName);
    int     stdcall (*QueryContextMenu)(dword hMenu,int index,int cmdFirst,int cmdLast);
    dword   stdcall (*InvokeCommand)(int ID);
    dword   stdcall (*SetLCID)(dword dwLCID,dword hResModule);
    dword   stdcall (*GetIconLocation)(dword szLocation);
    dword   stdcall (*SetIconLocation)(dword szLocation);
    dword   stdcall (*GetButtonInfo)(dword btninfo);
    dword   stdcall (*Invoke)(dword id,dword wParam,dword lParam);
};// ITlbButtonVtbl;

struct ITlbContainerVtbl{
    dword   stdcall (*QueryInterface)(dword riid,dword ppvObject);
    dword   stdcall (*AddRef)();
    dword   stdcall (*Release)();
    dword   stdcall (*GetParams)(dword retVal);//#CONTAINER_PARAMS
    dword   stdcall (*GetBandWND)();
    dword   stdcall (*SaveButton)();
    dword   stdcall (*GetLCID)();
    dword   stdcall (*GetIconPoint)(dword ptIcon);//#POINT
    dword   stdcall (*DrawItemText)(dword dc,dword rc,dword text);
    dword   stdcall (*GetTextProps)(dword rcMargins, dword color);//#RECT,#COLORREF
    dword   stdcall (*UpdateButtonInfo)(int flags);
    dword   stdcall (*Invoke)(dword id,dword wParam,dword lParam);
};

//functions////////////////////////////////////////////////////////////////////
:int IsEqualCLSID(dword p1,p2){
  $pushad
  EDI=p1;ESI=p2;
  $cld;ECX=4;$rep;$cmpsd;
  $popad
  IF(ZEROFLAG)RETURN 1;
  return 0;
}
#define IsEqualIID IsEqualCLSID

:dword COMETHODRETADDR;
:stdcall COMETHOD()inline{
  $pop COMETHODRETADDR
  $pop ECX
  $pop EAX
  $push ECX;$push COMETHODRETADDR;EAX+=DSDWORD[ECX];goto DSDWORD[EAX];
}

extern WINAPI "ole32.dll"{
  StringFromIID(dword rclsid,lplpsz);
  CoGetMalloc(DWORD dwMemContext,dword ppMalloc);
  stdcall CoInitialize(int);
  stdcall CoUninitialize(void);
  stdcall OleInitialize(int);
  stdcall OleUninitialize(void);
  stdcall CoCreateInstance(dword,dword,dword,dword,dword);
  stdcall CoFreeUnusedLibraries(void);
}
extern WINAPI "shlwapi.dll"{
  dword SHDeleteKey(dword,dword);
}
