//+---------------------------------------------------------------------------
//
//  Microsoft Windows
//  Copyright (C) Microsoft Corporation, 1992-1999.
//
//  File:       objbase.h
//
//  Contents:   Component object model defintions.
//
//----------------------------------------------------------------------------

#include "wtypes.h--"

#ifndef _OBJBASE_H_
#define _OBJBASE_H_ TRUE

#define CLSCTX_INPROC           CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER

// With DCOM, CLSCTX_REMOTE_SERVER should be included
#define CLSCTX_ALL              CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER|CLSCTX_LOCAL_SERVER|CLSCTX_REMOTE_SERVER
#define CLSCTX_SERVER           CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER|CLSCTX_REMOTE_SERVER
// class registration flags; passed to CoRegisterClassObject
enum{
    REGCLS_SINGLEUSE = 0,       // class object only generates one instance
    REGCLS_MULTIPLEUSE = 1,     // same class object genereates multiple inst.
                                // and local automatically goes into inproc tbl.
    REGCLS_MULTI_SEPARATE = 2,  // multiple use, but separate control over each
                                // context.
    REGCLS_SUSPENDED      = 4,  // register is as suspended, will be activated
                                // when app calls CoResumeClassObjects
    REGCLS_SURROGATE      = 8   // must be used when a surrogate process
                                // is registering a class object that will be
                                // loaded in the surrogate
};

// interface marshaling definitions
#define MARSHALINTERFACE_MIN 500 // minimum number of bytes for interface marshl


//
// Common typedefs for paramaters used in Storage API's, gleamed from storage.h
// Also contains Storage error codes, which should be moved into the storage
// idl files.
//


#define CWCSTORAGENAME 32

/* Storage instantiation modes */
#define STGM_DIRECT             0x00000000L
#define STGM_TRANSACTED         0x00010000L
#define STGM_SIMPLE             0x08000000L

#define STGM_READ               0x00000000L
#define STGM_WRITE              0x00000001L
#define STGM_READWRITE          0x00000002L

#define STGM_SHARE_DENY_NONE    0x00000040L
#define STGM_SHARE_DENY_READ    0x00000030L
#define STGM_SHARE_DENY_WRITE   0x00000020L
#define STGM_SHARE_EXCLUSIVE    0x00000010L

#define STGM_PRIORITY           0x00040000L
#define STGM_DELETEONRELEASE    0x04000000L
#define STGM_NOSCRATCH          0x00100000L

#define STGM_CREATE             0x00001000L
#define STGM_CONVERT            0x00020000L
#define STGM_FAILIFTHERE        0x00000000L

#define STGM_NOSNAPSHOT         0x00200000L
#define STGM_DIRECT_SWMR        0x00400000L

/*  flags for internet asyncronous and layout docfile */
#define ASYNC_MODE_COMPATIBILITY    0x00000001L
#define ASYNC_MODE_DEFAULT          0x00000000L

#define STGTY_REPEAT                0x00000100L
#define STG_TOEND                   0xFFFFFFFFL

#define STG_LAYOUT_SEQUENTIAL       0x00000000L
#define STG_LAYOUT_INTERLEAVED      0x00000001L

#define STGFMT_STORAGE          0
#define STGFMT_NATIVE           1
#define STGFMT_FILE             3
#define STGFMT_ANY              4
#define STGFMT_DOCFILE          5

// This is a legacy define to allow old component to builds
#define STGFMT_DOCUMENT         0

enum// tagCOINIT
{
  COINIT_APARTMENTTHREADED  = 0x2,      // Apartment model

  // These constants are only valid on Windows NT 4.0
  COINIT_MULTITHREADED      = 0x0,      // OLE calls objects on any thread.
  COINIT_DISABLE_OLE1DDE    = 0x4,      // Don't use DDE for Ole1 support.
  COINIT_SPEED_OVER_MEMORY  = 0x8,      // Trade memory for speed.
};

/****** STD Object API Prototypes *****************************************/

extern WINAPI "ole32.dll"
{
DWORD CoBuildVersion( VOID );
/* init/uninit */
CoInitialize(dword pvReserved);
void CoUninitialize(void);
CoGetMalloc(DWORD dwMemContext,dword ppMalloc);
DWORD CoGetCurrentProcess(void);
CoRegisterMallocSpy(dword pMallocSpy);
CoRevokeMallocSpy(void);
CoCreateStandardMalloc(DWORD memctx,dword ppMalloc);
CoInitializeEx(dword pvReserved,DWORD dwCoInit);
ULONG DebugCoGetRpcFault( void );
void DebugCoSetRpcFault( ULONG );
CoGetObjectContext(dword riid, dword ppv);
/* register/revoke/get class objects */
CoGetClassObject(dword rclsid,DWORD dwClsContext,dword pvReserved,dword riid,dword ppv);
CoRegisterClassObject(dword rclsid,dword pUnk,DWORD dwClsContext,DWORD flags,DWORD lpdwRegister);
CoRevokeClassObject(DWORD dwRegister);
CoResumeClassObjects(void);
CoSuspendClassObjects(void);
ULONG CoAddRefServerProcess(void);
ULONG CoReleaseServerProcess(void);
CoGetPSClsid(dword riid,dword *pClsid);
CoRegisterPSClsid(dword riid, rclsid);
// Registering surrogate processes
CoRegisterSurrogate(dword pSurrogate);
/* marshaling interface pointers */
CoGetMarshalSizeMax(ULONG *pulSize,dword riid,dword pUnk,DWORD dwDestContext,dword pvDestContext,DWORD mshlflags);
CoMarshalInterface(dword pStm,dword riid,dword pUnk,DWORD dwDestContext,dword pvDestContext,DWORD mshlflags);
CoUnmarshalInterface(dword pStm,dword riid,dword ppv);
CoMarshalHresult(dword pstm,dword hresult);
CoUnmarshalHresult(dword pstm,dword phresult);
CoReleaseMarshalData(dword pStm);
CoDisconnectObject(dword pUnk,DWORD dwReserved);
CoLockObjectExternal(dword pUnk,BOOL fLock,BOOL fLastUnlockReleases);
CoGetStandardMarshal(dword riid,dword pUnk,DWORD dwDestContext,dword pvDestContext,DWORD mshlflags,dword ppMarshal);
CoGetStdMarshalEx(dword pUnkOuter,DWORD smexflags,dword ppUnkInner);
}
/* flags for CoGetStdMarshalEx */
enum //tagSTDMSHLFLAGS
{
    SMEXF_SERVER     = 0x01,       // server side aggregated std marshaler
    SMEXF_HANDLER    = 0x02        // client side (handler) agg std marshaler
};

extern WINAPI "ole32.dll"
{
BOOL CoIsHandlerConnected(dword pUnk);
// Apartment model inter-thread interface passing helpers
CoMarshalInterThreadInterfaceInStream(dword riid,dword pUnk,dword ppStm);
CoGetInterfaceAndReleaseStream(dword pStm,dword iid,ppv);
CoCreateFreeThreadedMarshaler(dword punkOuter,ppunkMarshal);
/* dll loading helpers; keeps track of ref counts and unloads all on exit */
HINSTANCE CoLoadLibrary(dword lpszLibName,BOOL bAutoFree);
void CoFreeLibrary(dword hInst);
void CoFreeAllLibraries(void);
void CoFreeUnusedLibraries(void);
/* Call Security. */
CoInitializeSecurity(dword pSecDesc,LONG cAuthSvc,dword asAuthSvc,pReserved1,dwAuthnLevel,DWORD dwImpLevel,pAuthList,DWORD dwCapabilities,pReserved3);
CoGetCallContext(dword riid,ppInterface );
CoQueryProxyBlanket(dword pProxy,pwAuthnSvc,pAuthzSvc,pServerPrincName,pAuthnLevel,pImpLevel,pAuthInfo,pCapabilites);
CoSetProxyBlanket(dword pProxy,dwAuthnSvc,dwAuthzSvc,pServerPrincName,dwAuthnLevel,dwImpLevel,pAuthInfo,dwCapabilities );
CoCopyProxy(dword pProxy,ppCopy );
CoQueryClientBlanket(dword pAuthnSvc,pAuthzSvc,pServerPrincName,pAuthnLevel,pImpLevel,pPrivs,pCapabilities );
CoImpersonateClient();
CoRevertToSelf();
CoQueryAuthenticationServices(DWORD pcAuthSvc,asAuthSvc );
CoSwitchCallContext(dword pNewObject,ppOldObject );
}
#define COM_RIGHTS_EXECUTE 1
#define COM_RIGHTS_SAFE_FOR_SCRIPTING 2

/* helper for creating instances */

extern WINAPI "ole32.dll"
{
CoCreateInstance(dword rclsid,pUnkOuter,DWORD dwClsContext,riid,ppv);
CoGetInstanceFromFile(dword pServerInfo,pClsid,punkOuter,dwClsCtx,grfMode,pwszName,dwCount,pResults );
CoGetInstanceFromIStorage(dword pServerInfo,pClsid,punkOuter,dwClsCtx,pstg,dwCount,pResults );
CoCreateInstanceEx(dword Clsid,punkOuter,dwClsCtx,pServerInfo,dwCount,pResults );
CoGetCancelObject(DWORD dwThreadId,iid,ppUnk);
CoSetCancelObject(dword pUnk);
CoCancelCall(DWORD dwThreadId,ULONG ulTimeout);
CoTestCancel();
CoEnableCallCancellation(dword pReserved);
CoDisableCallCancellation(dword pReserved);
StringFromCLSID(dword rclsid,lplpsz);
CLSIDFromString(dword lpsz,pclsid);
StringFromIID(dword rclsid,lplpsz);
IIDFromString(dword lpsz,lpiid);
BOOL CoIsOle1Class(dword rclsid);
ProgIDFromCLSID (dword clsid,lplpszProgID);
CLSIDFromProgID (dword lpszProgID,lpclsid);
CLSIDFromProgIDEx (dword lpszProgID,lpclsid);
int StringFromGUID2(dword rguid,lpsz,int cchMax);
CoCreateGuid(dword pguid);
BOOL CoFileTimeToDosDateTime(dword lpFileTime,lpDosDate,lpDosTime);
BOOL CoDosDateTimeToFileTime(WORD nDosDate,nDosTime,dword lpFileTime);
CoFileTimeNow(dword lpFileTime );
CoRegisterMessageFilter(dword lpMessageFilter,lplpMessageFilter );
CoRegisterChannelHook(dword ExtensionUuid,pChannelHook );
/* Synchronization API */
CoWaitForMultipleHandles (DWORD dwFlags,DWORD dwTimeout,ULONG cHandles,dword pHandles,DWORD  lpdwindex);
}
/* Flags for Synchronization API and Classes */
enum //tagCOWAIT_FLAGS
{
  COWAIT_WAITALL = 1,
  COWAIT_ALERTABLE = 2
};

/* TreatAs APIS */

extern WINAPI "ole32.dll"
{
CoGetTreatAsClass(dword clsidOld,pClsidNew);
CoTreatAsClass(dword clsidOld,clsidNew);
/* the server dlls must define their DllGetClassObject and DllCanUnloadNow
 * to match these; the typedefs are located here to ensure all are changed at
 * the same time.
 */
DllGetClassObject(dword rclsid,riid,ppv);
DllCanUnloadNow(void);
/****** Default Memory Allocation ******************************************/
dword CoTaskMemAlloc(dword cb);
dword CoTaskMemRealloc(dword pv,cb);
void CoTaskMemFree(dword pv);
/****** DV APIs ***********************************************************/
CreateDataAdviseHolder(dword ppDAHolder);
CreateDataCache(dword pUnkOuter,rclsid,iid,ppv);
/****** Storage API Prototypes ********************************************/
StgCreateDocfile(dword pwcsName,DWORD grfMode,DWORD reserved,ppstgOpen);
StgCreateDocfileOnILockBytes(dword plkbyt,DWORD grfMode,DWORD reserved,ppstgOpen);
StgOpenStorage(dword pwcsName,pstgPriority,DWORD grfMode,snbExclude,reserved,ppstgOpen);
StgOpenStorageOnILockBytes(dword plkbyt,pstgPriority,DWORD grfMode,snbExclude,DWORD reserved,ppstgOpen);
StgIsStorageFile(dword pwcsName);
StgIsStorageILockBytes(dword plkbyt);
StgSetTimes(dword lpszName,pctime,patime,pmtime);
StgOpenAsyncDocfileOnIFillLockBytes(dword pflb,DWORD grfMode,DWORD asyncFlags,dword ppstgOpen);
StgGetIFillLockBytesOnILockBytes(dword pilb,ppflb);
StgGetIFillLockBytesOnFile(dword pwcsName,ppflb);
StgOpenLayoutDocfile(dword pwcsDfName,DWORD grfMode,DWORD reserved,ppstgOpen);
}

// STG initialization options for StgCreateStorageEx and StgOpenStorageEx
#define STGOPTIONS_VERSION 1

struct STGOPTIONS
{
    USHORT usVersion;            // Version 1
    USHORT reserved;             // must be 0 for padding
    ULONG ulSectorSize;          // docfile header sector size (512)
};

extern WINAPI "ole32.dll"
{
StgCreateStorageEx (dword pwcsName,DWORD grfMode,DWORD stgfmt,DWORD grfAttrs,dword pStgOptions,dword reserved,riid,ppObjectOpen);

StgOpenStorageEx (dword pwcsName,DWORD grfMode,DWORD stgfmt,DWORD grfAttrs,pStgOptions,reserved,riid,ppObjectOpen);
//
//  Moniker APIs
//
BindMoniker(dword pmk,DWORD grfOpt,iidResult,ppvResult);
CoInstall(dword pbc,DWORD dwFlags,pClassSpec,pQuery,pszCodeBase);
CoGetObject(dword pszName,pBindOptions,riid,ppv);
MkParseDisplayName(dword pbc,szUserName,pchEaten,ppmk);
MonikerRelativePathTo(dword pmkSrc,pmkDest,ppmkRelPath,BOOL dwReserved);
MonikerCommonPrefixWith(dword pmkThis,pmkOther,ppmkCommon);
CreateBindCtx(DWORD reserved,ppbc);
CreateGenericComposite(dword pmkFirst,pmkRest,ppmkComposite);
GetClassFile (dword szFilename,pclsid);
CreateClassMoniker(dword rclsid,ppmk);
CreateFileMoniker(dword lpszPathName,ppmk);
CreateItemMoniker(dword lpszDelim,lpszItem,ppmk);
CreateAntiMoniker(dword ppmk);
CreatePointerMoniker(dword punk,ppmk);
CreateObjrefMoniker(dword punk,ppmk);
GetRunningObjectTable(DWORD reserved,pprot);
//
// Standard Progress Indicator impolementation
//
CreateStdProgressIndicator(dword hwndParent,pszTitle,pIbscCaller,ppIbsc);
}

#endif     // __OBJBASE_H__
