Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

instance.c

Go to the documentation of this file.
00001 /****************************** Module Header ******************************\ 00002 * Module Name: instance.c 00003 * 00004 * Copyright (c) 1985 - 1999, Microsoft Corporation 00005 * 00006 * This module handles conversion of instance handles (server side handles) 00007 * to instance indecies used by the handle manager for associating a handle 00008 * with a particular instance. 00009 * 00010 * History: 00011 * 11-5-91 Sanfords Created 00012 \***************************************************************************/ 00013 00014 #include "precomp.h" 00015 #pragma hdrstop 00016 00017 #define INST_GROW_COUNT 4 00018 00019 // globals 00020 00021 PHANDLE aInstance = NULL; 00022 int cInstAllocated = 0; 00023 int iFirstFreeInst = 0; 00024 00025 00026 /***************************************************************************\ 00027 * AddInstance 00028 * 00029 * Description: 00030 * Adds a server side instance handle to the instance handle array. 00031 * The array index becomes the client-side unique instance index used for 00032 * identifying other client side handles. 00033 * 00034 * Returns: 00035 * client side instance handle or 0 on error. 00036 * 00037 * History: 00038 * 11-1-91 sanfords Created. 00039 \***************************************************************************/ 00040 HANDLE AddInstance( 00041 HANDLE hInstServer) 00042 { 00043 int i, iNextFree; 00044 PHANDLE ph; 00045 00046 if (iFirstFreeInst >= cInstAllocated) { 00047 if (cInstAllocated == 0) { 00048 aInstance = (PHANDLE)DDEMLAlloc(sizeof(HANDLE) * INST_GROW_COUNT); 00049 } else { 00050 aInstance = (PHANDLE)DDEMLReAlloc((PVOID)aInstance, 00051 sizeof(HANDLE) * (cInstAllocated + INST_GROW_COUNT)); 00052 } 00053 if (aInstance == 0) { 00054 return (0); 00055 } 00056 ph = &aInstance[cInstAllocated]; 00057 i = cInstAllocated + 1; 00058 while (i <= cInstAllocated + INST_GROW_COUNT) { 00059 *ph++ = (HANDLE)(UINT_PTR)(UINT)i++; 00060 } 00061 cInstAllocated += INST_GROW_COUNT; 00062 } 00063 iNextFree = HandleToUlong(aInstance[iFirstFreeInst]); 00064 if (iNextFree > MAX_INST) { 00065 /* 00066 * Instance limit for this process exceeded! 00067 */ 00068 return(0); 00069 } 00070 aInstance[iFirstFreeInst] = hInstServer; 00071 i = iFirstFreeInst; 00072 iFirstFreeInst = iNextFree; 00073 return (CreateHandle(0, HTYPE_INSTANCE, i)); 00074 } 00075 00076 00077 /***************************************************************************\ 00078 * DestroyInstance 00079 * 00080 * Description: 00081 * Removes an instance from the aInstance table. This does nothing for 00082 * the server side instance info. 00083 * 00084 * History: 00085 * 11-19-91 sanfords Created. 00086 \***************************************************************************/ 00087 HANDLE DestroyInstance( 00088 HANDLE hInstClient) 00089 { 00090 register HANDLE hInstServerRet = 0; 00091 00092 DestroyHandle(hInstClient); 00093 hInstServerRet = aInstance[InstFromHandle(hInstClient)]; 00094 aInstance[InstFromHandle(hInstClient)] = (HANDLE)UIntToPtr( iFirstFreeInst ); 00095 iFirstFreeInst = InstFromHandle(hInstClient); 00096 00097 return (hInstServerRet); 00098 } 00099 00100 00101 /***************************************************************************\ 00102 * ValidateInstance 00103 * 00104 * Description: 00105 * Verifies the current validity of an instance handle - which is a server 00106 * side handle that also references a client side data structure (pcii). 00107 * 00108 * History: 00109 * 11-19-91 sanfords Created. 00110 \***************************************************************************/ 00111 PCL_INSTANCE_INFO ValidateInstance( 00112 HANDLE hInstClient) 00113 { 00114 PCL_INSTANCE_INFO pcii; 00115 00116 pcii = (PCL_INSTANCE_INFO)ValidateCHandle(hInstClient, HTYPE_INSTANCE, HINST_ANY); 00117 00118 if (pcii != NULL) { 00119 if (pcii->tid != GetCurrentThreadId() || 00120 pcii->hInstClient != hInstClient) { 00121 return (NULL); 00122 } 00123 } 00124 return (pcii); 00125 } 00126 00127 00128 /***************************************************************************\ 00129 * SetLastDDEMLError 00130 * 00131 * Description: 00132 * Sets last error value and generates monitor events if monitoring. 00133 * 00134 * History: 00135 * 11-19-91 sanfords Created. 00136 \***************************************************************************/ 00137 VOID SetLastDDEMLError( 00138 PCL_INSTANCE_INFO pcii, 00139 DWORD error) 00140 { 00141 PEVENT_PACKET pep; 00142 00143 if (pcii->MonitorFlags & MF_ERRORS && !(pcii->afCmd & APPCLASS_MONITOR)) { 00144 pep = (PEVENT_PACKET)DDEMLAlloc(sizeof(EVENT_PACKET) - sizeof(DWORD) + 00145 sizeof(MONERRSTRUCT)); 00146 if (pep != NULL) { 00147 pep->EventType = MF_ERRORS; 00148 pep->fSense = TRUE; 00149 pep->cbEventData = sizeof(MONERRSTRUCT); 00150 #define perrs ((MONERRSTRUCT *)&pep->Data) 00151 perrs->cb = sizeof(MONERRSTRUCT); 00152 perrs->wLastError = (WORD)error; 00153 perrs->dwTime = NtGetTickCount(); 00154 perrs->hTask = (HANDLE)LongToHandle( pcii->tid ); 00155 #undef perrs 00156 LeaveDDECrit; 00157 Event(pep); 00158 EnterDDECrit; 00159 } 00160 } 00161 #if DBG 00162 if (error != 0 && error != DMLERR_NO_CONV_ESTABLISHED) { 00163 RIPMSG3(RIP_WARNING, 00164 "DDEML Error set=%x, Client Instance=%x, Process=%x.", 00165 error, pcii, GetCurrentProcessId()); 00166 } 00167 #endif 00168 pcii->LastError = error; 00169 } 00170 00171

Generated on Sat May 15 19:40:24 2004 for test by doxygen 1.3.7