00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
#include "precomp.h"
00015
#pragma hdrstop
00016
00017 #define INST_GROW_COUNT 4
00018
00019
00020
00021 PHANDLE
aInstance =
NULL;
00022 int cInstAllocated = 0;
00023 int iFirstFreeInst = 0;
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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
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
00079
00080
00081
00082
00083
00084
00085
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
00103
00104
00105
00106
00107
00108
00109
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
00130
00131
00132
00133
00134
00135
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