/
tLuaCOMConnPoints.cpp
1683 lines (1284 loc) · 45.6 KB
/
tLuaCOMConnPoints.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <windows.h>
#include <ole2.h>
#include <olectl.h>
#include <ocidl.h>
#include "tLuaCOM.h"
#include "tLuaCOMConnPoints.h"
#include "tCOMUtil.h"
#include "tLuaCOMException.h"
#include "LuaAux.h"
#include "luacom_internal.h"
extern "C"
{
#include "LuaCompat.h"
}
#define CONNPOINT_NAME "__LUACOM_CONNPOINT"
/*---------------------------------------------------------------------------
tLuaCOMEnumConnPoints's implementation of its main COM object class
including Constructor, Destructor, QueryInterface, AddRef, Release,
Next, Skip, Reset, and Clone.
---------------------------------------------------------------------------*/
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMEnumConnPoints::tLuaCOMEnumConnPoints
Summary: tLuaCOMEnumConnPoints Constructor.
Args: IUnknown* pHostObj
Pointer to the host object whose connection points are
being enumerated.
Modifies: cRefs, pHostObj, iEnumIndex, cConnPts, and paConnPts.
Returns: void
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
tLuaCOMEnumConnPoints::tLuaCOMEnumConnPoints(IUnknown* pHostObj)
{
// Zero the COM object's reference count.
cRefs = 0;
// Assign the Host Object pointer.
this->pHostObj = pHostObj;
// Initialize the Connection Point enumerator variables.
iEnumIndex = 0;
cConnPts = 0;
paConnPts = NULL;
return;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMEnumConnPoints::~tLuaCOMEnumConnPoints
Summary: tLuaCOMEnumConnPoints Destructor.
Args: void
Modifies: paConnPts.
Returns: void
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
tLuaCOMEnumConnPoints::~tLuaCOMEnumConnPoints(void)
{
if (NULL != paConnPts)
{
UINT i;
// Release all the connection point interface pointers.
for (i=0; i<cConnPts; i++)
if (NULL != paConnPts[i])
COM_RELEASE(paConnPts[i]);
// Delete the array of interface pointers.
delete [] paConnPts;
}
return;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMEnumConnPoints::Init
Summary: tLuaCOMEnumConnPoints Initialization method. Create any
necessary arrays, structures, and objects.
Args: ULONG cConnPts,
Number of Connections Points.
IConnPoint** paConnPts,
Pointer to array of connection point interface pointers.
ULONG iEnumIndex
The Enumerator index initial value.
Modifies: cConnPts, paConnPts, iEnumIndex.
Returns: HRESULT
Standard result code. NOERROR for success.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
HRESULT tLuaCOMEnumConnPoints::Init(
ULONG cConnPts,
IConnectionPoint** paConnPts,
ULONG iEnumIndex)
{
HRESULT hr = NOERROR;
UINT i;
// Remember the number of Connection points.
cConnPts = cConnPts;
// Remember the initial enumerator index.
iEnumIndex = iEnumIndex;
// Create a copy of the array of connection points and keep it inside
// this enumerator COM object.
paConnPts = new IConnectionPoint* [(UINT) cConnPts];
// Fill the array copy with the IConnPoint interface pointers from
// the array passed. AddRef for each new Interface pointer copy made.
if (NULL != paConnPts)
{
for (i=0; i<cConnPts; i++)
{
paConnPts[i] = paConnPts[i];
paConnPts[i]->AddRef();
}
}
else
hr = E_OUTOFMEMORY;
return (hr);
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMEnumConnPoints::QueryInterface
Summary: QueryInterface of the tLuaCOMEnumConnPoints non-delegating
IUnknown implementation.
Args: REFIID riid,
[in] GUID of the Interface being requested.
void ** ppv)
[out] Address of the caller's pointer variable that will
receive the requested interface pointer.
Modifies: .
Returns: HRESULT
Standard result code. NOERROR for success.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP tLuaCOMEnumConnPoints::QueryInterface(
REFIID riid,
void ** ppv)
{
HRESULT hr = E_NOINTERFACE;
*ppv = NULL;
// The IEnumConnectionPoints interface is implemented directly in
// this COM object rather than being a nested interface implementation.
if (IID_IUnknown == riid || IID_IEnumConnectionPoints == riid)
*ppv = (LPVOID)this;
if (NULL != *ppv)
{
// We've handed out a pointer to the interface so obey the COM rules
// and AddRef the reference count.
((LPUNKNOWN)*ppv)->AddRef();
hr = NOERROR;
}
return (hr);
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMEnumConnPoints::AddRef
Summary: AddRef of the tLuaCOMEnumConnPoints non-delegating IUnknown
implementation.
Args: void
Modifies: cRefs.
Returns: ULONG
New value of cRefs (COM object's reference count).
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP_(ULONG) tLuaCOMEnumConnPoints::AddRef(void)
{
cRefs = ++cRefs;
// Also AddRef the host object to ensure it stays around as long as
// this enumerator.
pHostObj->AddRef();
return cRefs;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMEnumConnPoints::Release
Summary: Release of the tLuaCOMEnumConnPoints non-delegating IUnknown
implementation.
Args: void
Modifies: cRefs.
Returns: ULONG
New value of cRefs (COM object's reference count).
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP_(ULONG) tLuaCOMEnumConnPoints::Release(void)
{
// Pass this release along to the Host object being enumerated.
pHostObj->Release();
cRefs = --cRefs;
if (0 == cRefs)
{
// We artificially bump the main ref count to prevent reentrancy via
// the main object destructor.
cRefs++;
delete this;
}
return cRefs;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMEnumConnPoints::Next
Summary: The Next member method of this IEnumConnectionPoints interface
implementation. Called by outside clients of a
tLuaCOMEnumConnPoints object to request that a number of next
connection point interface pointers be deposited into an array
supplied by the caller.
Args: ULONG cReq
Number of connection points requested for return (starting at
the current Enumerator index).
IConnPoint** paConnPts,
Pointer to a caller's output array that will receive the
enumerated IConnPoint interface pointers.
ULONG* cEnumerated)
Pointer to a ULONG variable that will contain the number of
connection points actually enumerated by this call.
Modifies: .
Returns: HRESULT
Standard result code. NOERROR for success.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP tLuaCOMEnumConnPoints::Next(
ULONG cReq,
IConnectionPoint** paConnPts,
ULONG* pcEnumerated)
{
HRESULT hr = NOERROR;
ULONG cRet = 0;
// Make sure the argument values passed are valid.
if (NULL != paConnPts)
{
if (NULL != paConnPts)
{
if (NULL != *paConnPts && iEnumIndex < cConnPts)
{
if (NULL != pcEnumerated)
*pcEnumerated = 0L;
else
if (1L != cReq)
hr = E_POINTER;
}
else
hr = S_FALSE;
}
else
hr = E_POINTER;
}
else
hr = S_FALSE;
if (SUCCEEDED(hr))
{
// Starting at the current Enumerator index, loop to assign the
// requested number of output connection point interface pointers.
for (; iEnumIndex < cConnPts && cReq > 0;
paConnPts++, cRet++, cReq--)
{
// Assign from the inside Enumerator array to the specified receiving
// array.
*paConnPts = paConnPts[iEnumIndex++];
// After assigning a copy of an IConnPoint pointer, AddRef it.
if (NULL != *paConnPts)
(*paConnPts)->AddRef();
}
// Assign the output number of connection points enumerated.
if (NULL != pcEnumerated)
*pcEnumerated = cRet;
}
return hr;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMEnumConnPoints::Skip
Summary: The Skip member method of this IEnumConnectionPoints interface
implementation. Starting at the current Enumerator index, skip
the specified number of connection point items.
Args: ULONG cSkip
Number of Connection Point items to skip.
Modifies: .
Returns: HRESULT
Standard result code. NOERROR for success.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP tLuaCOMEnumConnPoints::Skip(
ULONG cSkip)
{
HRESULT hr = NOERROR;
// If there really is a connection point array and the requested
// amount of skip does not exceed the number of connection points,
// then bump the index by the requested skip amount.
if (NULL != paConnPts && (iEnumIndex + cSkip) < cConnPts)
iEnumIndex += cSkip;
else
hr = S_FALSE;
return hr;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMEnumConnPoints::Reset
Summary: The Reset member method of the IEnumConnectionPoints interface
implementation. Resets the Enumeration index to the first
connection point item in the array.
Args: void.
Modifies: .
Returns: HRESULT
Standard result code. NOERROR for success.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP tLuaCOMEnumConnPoints::Reset(
void)
{
// Zero the main Enumerator index.
iEnumIndex = 0;
return NOERROR;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMEnumConnPoints::Clone
Summary: The Clone member method of this IEnumConnectionPoints
interface implementation. Creates a new clone of this entire
Connection Point enumerator COM object.
Args: IEnumConnectionPoints** ppIEnum
Address of the caller's output pointer variable that will
receive the IEnumConnectionPoints interface pointer of the
new enumerator clone.
Modifies: ...
Returns: HRESULT
Standard result code. NOERROR for success.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP tLuaCOMEnumConnPoints::Clone(
IEnumConnectionPoints** ppIEnum)
{
HRESULT hr;
tLuaCOMEnumConnPoints* pCOEnum;
// NULL the output variable first.
*ppIEnum = NULL;
// Create the Clone Enumerator COM object.
pCOEnum = new tLuaCOMEnumConnPoints(pHostObj);
if (NULL != pCOEnum)
{
// Initialize it with same values as in this existing enumerator.
hr = pCOEnum->Init(cConnPts, paConnPts, iEnumIndex);
if (SUCCEEDED(hr))
{
// QueryInterface to return the requested interface pointer.
// An AddRef will be conveniently done by the QI.
if (SUCCEEDED(hr))
hr = pCOEnum->QueryInterface(
IID_IEnumConnectionPoints,
(void **)ppIEnum);
}
}
else
hr = E_OUTOFMEMORY;
return hr;
}
/*---------------------------------------------------------------------------
tLuaCOMConnPoint's implementation of its main COM object class
including Constructor, Destructor, QueryInterface, AddRef, Release,
GetConnectionInterface, GetConnPointContainer, Advise, Unadvise,
and EnumConnections.
---------------------------------------------------------------------------*/
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMConnPoint::tLuaCOMConnPoint
Summary: tLuaCOMConnPoint Constructor.
Args: IUnknown* pHostObj
Pointer to IUnknown of the connectable object offering this
connection point.
Modifies: ...
Returns: void
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
tLuaCOMConnPoint::tLuaCOMConnPoint(lua_State *p_L,
IUnknown* pHostObj)
{
// stores lua state
L = p_L;
// Zero the COM object's reference count.
cRefs = 0;
// Remember an IUnknown pointer to the connectable object that offers
// this connection point. Since this connection point object's lifetime
// is geared to that of the connectable object there is no need to
// AddRef the following copied pointer to the connectable object.
this->pHostObj = pHostObj;
// Initialize the Connection Point variables.
dwNextCookie = COOKIE_START_VALUE;
uiMaxIndex = 0;
cConnections = 0;
// creates a new lua tag associated with this connection point
luaCompat_pushTypeByName(L, MODULENAME, LCOM_CONNPOINT_TYPENAME);
lua_pushcfunction(L, tagmeth_index);
luaCompat_handleNoIndexEvent(L);
lua_pop(L, 1);
for(int i = 0; i < ALLOC_CONNECTIONS; i++)
sinks[i] = NULL;
return;
}
tLuaCOMConnPoint::~tLuaCOMConnPoint(void)
{
UINT i;
if (NULL != paConnections)
{
// Release all the connection sink interface pointers.
for (i=0; i<uiMaxIndex; i++)
{
if (NULL != paConnections[i].pUnk)
paConnections[i].pUnk->Release();
if (NULL != sinks[i])
{
sinks[i]->Unlock();
sinks[i] = NULL;
}
}
}
return;
}
HRESULT tLuaCOMConnPoint::Init(REFIID riid, ITypeInfo *typeinfo)
{
HRESULT hr = NOERROR;
CONNECTDATA* paConns = paConnections;
// Keep a copy of the reference to the IID of the sink interface
// associated with this connection point. Needed for later
// use by the GetConnectionInterface method.
iidSink = riid;
source_typeinfo = typeinfo;
// Build the initial dynamic array for connections.
/* paConns = new CONNECTDATA[ALLOC_CONNECTIONS];
sinks = new tLuaCOM*[ALLOC_CONNECTIONS];*/
if (NULL != paConns)
{
// Zero the array.
memset(paConns, 0, ALLOC_CONNECTIONS * sizeof(CONNECTDATA));
// Rig this connection point object so that it will use the
// new internal array of connections.
uiMaxIndex = ALLOC_CONNECTIONS;
//paConnections = paConns;
}
else
hr = E_OUTOFMEMORY;
return (hr);
}
STDMETHODIMP tLuaCOMConnPoint::QueryInterface(
REFIID riid,
void ** ppv)
{
HRESULT hr = E_NOINTERFACE;
*ppv = NULL;
// The IConnPoint interface is implemented directly in this
// COM object rather than being a nested interface implementation.
if (IID_IUnknown == riid || IID_IConnectionPoint == riid)
*ppv = (LPVOID)this;
if (NULL != *ppv)
{
// We've handed out a pointer to the interface so obey the COM rules
// and AddRef the reference count.
((LPUNKNOWN)*ppv)->AddRef();
hr = NOERROR;
}
return (hr);
}
STDMETHODIMP_(ULONG) tLuaCOMConnPoint::AddRef(void)
{
cRefs = ++cRefs;
return cRefs;
}
STDMETHODIMP_(ULONG) tLuaCOMConnPoint::Release(void)
{
cRefs = --cRefs;
if (0 == cRefs)
{
// We artificially bump the main ref count to prevent reentrancy via
// the main object destructor. We relinquish thread ownership of this
// object prior to deleting it--a good practice.
cRefs++;
delete this;
}
return cRefs;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMConnPoint::GetSlot
Summary: An internal private utility member method to obtain a free
slot in the dynamic connections array. GetSlot will expand the
dynamic array for more entries if needed. To guarantee thread
safety, this private method should always be called within the
protection of a bracketed OwnThis, UnOwnThis pair.
Args: UINT* puiFreeSlot
Address of an output variable to receive the free slot index.
Modifies: uiMaxIndex, paConnections.
Returns: HRESULT
Standard result code. NOERROR for success.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
HRESULT tLuaCOMConnPoint::GetSlot(
UINT* puiFreeSlot)
{
HRESULT hr = NOERROR;
BOOL bOpen = FALSE;
UINT i;
//CONNECTDATA* paConns;
// Zero the output variable.
*puiFreeSlot = 0;
// Loop to find an empty slot.
for (i=0; i<uiMaxIndex; i++)
{
if (paConnections[i].dwCookie == 0)
{
// We found an open empty slot.
*puiFreeSlot = i;
bOpen = TRUE;
break;
}
}
if (!bOpen)
{
hr = E_OUTOFMEMORY;
}
return hr;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMConnPoint::FindSlot
Summary: An internal private utility member method to find an existing
slot (identified by the specified dwCookie value) in the
dynamic connections array.
Args: DWORD dwCookie,
The connection key (cookie) to find.
UINT* puiSlot)
Address of an output variable to receive the slot index.
Modifies: ...
Returns: HRESULT
Standard result code. NOERROR for success.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
HRESULT tLuaCOMConnPoint::FindSlot(
DWORD dwCookie,
UINT* puiSlot)
{
HRESULT hr = CONNECT_E_NOCONNECTION;
UINT i;
// Loop to find the Cookie.
for (i=0; i<uiMaxIndex; i++)
{
if (dwCookie == paConnections[i].dwCookie)
{
// If a cookie match is found, assign the output slot index.
*puiSlot = i;
hr = NOERROR;
break;
}
}
return hr;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMConnPoint::GetConnectionInterface
Summary: The GetConnectionInterface member method of this
IConnPoint interface implementation. Called to get the
IID of the Sink interface associated with this connection
point.
Args: IID* piidSink
Pointer to the IID of the associated sink interface.
Modifies: .
Returns: HRESULT
Standard result code. NOERROR for success.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP tLuaCOMConnPoint::GetConnectionInterface(
IID* piidSink)
{
HRESULT hr = NOERROR;
if (NULL != piidSink)
*piidSink = iidSink;
else
hr = E_POINTER;
return hr;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMConnPoint::GetConnPointContainer
Summary: The GetConnPointContainer member method of this
IConnPoint interface implementation. Called to get the
connection point container that contains this connection
point.
Args: IConnPointContainer** ppConnPtCon
Address of the pointer variable that will recieve the
IConnPointContainer interface pointer.
Modifies: .
Returns: HRESULT
Standard result code. NOERROR for success.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP tLuaCOMConnPoint::GetConnectionPointContainer(
IConnectionPointContainer** ppConnPtCon)
{
HRESULT hr;
// Use QueryInterface to get the interface pointer and to perform the
// needed AddRef on the returned pointer.
hr = pHostObj->QueryInterface(
IID_IConnectionPointContainer,
(void **) ppConnPtCon);
return hr;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMConnPoint::Advise
Summary: The Advise member method of this IConnPoint interface
implementation. Called by clients to establish a connection of
their sink to this connection point. Uses the CThreaded
OwnThis mechanism to provide mutually exclusive access by
multiple threads.
Args: IUnknown* pUnkSink
IUnknown interface pointer of the Sink object in the client.
DWORD* pdwCookie
Pointer to a DWORD in the client that will receive a unique
key used by the client to refer to the connection established
by this Advise call.
Modifies: ...
Returns: HRESULT
Standard result code. NOERROR for success.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP tLuaCOMConnPoint::Advise(
IUnknown* pUnkSink,
DWORD* pdwCookie)
{
HRESULT hr = NOERROR;
UINT uiFreeSlot = 0;
IDispatch* pISink = NULL;
// Zero the output connection key.
*pdwCookie = 0;
// Get the specific associated client Sink interface that this
// connection point expects to use for notifications.
hr = pUnkSink->QueryInterface(IID_IDispatch/*iidSink*/, (void **)&pISink);
if (SUCCEEDED(hr))
{
// Store the specific sink interface in this connection point's
// array of live connections. First find a free slot (expand the
// array if needed).
hr = GetSlot(&uiFreeSlot);
if (SUCCEEDED(hr))
{
// Assign the new slot with the connection entry.
paConnections[uiFreeSlot].pUnk = pISink;
paConnections[uiFreeSlot].dwCookie = dwNextCookie;
try
{
// vb supplies a very weird type info, so we
// stay with ours, as it's where vb will look for the
// DISPID's anyway
sinks[uiFreeSlot] =
tLuaCOM::CreateLuaCOM(L, pISink, IID_NULL, source_typeinfo);
}
catch(class tLuaCOMException& e)
{
UNUSED(e);
return CONNECT_E_CANNOTCONNECT;
}
// Assign the output Cookie value.
*pdwCookie = dwNextCookie;
// Increment the Cookie counter.
dwNextCookie++;
// Increment the number of live connections.
cConnections++;
}
}
else if (hr == E_NOINTERFACE)
{
// The sink does not support iidSink.
hr = CONNECT_E_CANNOTCONNECT;
}
return hr;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMConnPoint::Unadvise
Summary: The Unadvise member method of this IConnPoint interface
implementation. Called by clients to disconnect a connection
of their sink to this connection point. The connection is
identified by the dwCookie argument (obtained by a previous
Advise call). Uses the CThreaded OwnThis mechanism to provide
mutually exclusive access by multiple threads.
Args: DWORD dwCookie
Connection key that was obtained by a previous Advise call.
Modifies: .
Returns: HRESULT
Standard result code. NOERROR for success.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP tLuaCOMConnPoint::Unadvise(
DWORD dwCookie)
{
HRESULT hr = NOERROR;
UINT uiSlot;
if (0 != dwCookie)
{
hr = FindSlot(dwCookie, &uiSlot);
if (SUCCEEDED(hr))
{
// Release the sink interface.
COM_RELEASE(paConnections[uiSlot].pUnk);
sinks[uiSlot]->Unlock();
sinks[uiSlot] = NULL;
// Mark the array entry as empty.
paConnections[uiSlot].dwCookie = 0;
// Decrement the number of live connections.
cConnections--;
}
}
else
hr = E_INVALIDARG;
return hr;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMConnPoint::EnumConnections
Summary: The EnumConnections member method of this IConnPoint
interface implementation. Called to obtain an IEnumConnections
enumerator interface that can be used to enumerate the
connections of this connection point. Uses the CThreaded
OwnThis mechanism to ensure mutually exclusive access by
multiple threads.
Args: IEnumConnections** ppIEnum
Address of the caller's output pointer variable that will
receive the enumerator IEnumConnections interface pointer.
Modifies: ...
Returns: HRESULT
Standard result code. NOERROR for success.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP tLuaCOMConnPoint::EnumConnections(
IEnumConnections** ppIEnum)
{
HRESULT hr = OLE_E_NOCONNECTION;
CONNECTDATA* paConns;
tLuaCOMEnumConnections* pCOEnum;
UINT i,j;
// Zero the output enumerator interface pointer.
*ppIEnum = NULL;
if (0 != cConnections)
{
// Create an array of CONNECTDATA structures.
paConns = new CONNECTDATA[(UINT)cConnections];
if (NULL != paConns)
{
for (i=0, j=0; i<uiMaxIndex && j<cConnections; i++)
{
// Copy non-empty entries only.
if (0 != paConnections[i].dwCookie)
{
// Assign the occupied entry.
paConns[j].pUnk = (IUnknown*)paConnections[i].pUnk;
paConns[j].dwCookie = paConnections[i].dwCookie;
j++;
}
}
// Create a new COM object for enumerating connections. Pass
// 'this' as a pHostObj pointer used later to ensure the host
// connection point object stays alive as long as the enumerator
// that enumerates connections to that connection point.
pCOEnum = new tLuaCOMEnumConnections(this);
if (NULL != pCOEnum)
{
// Use the previously constructed (paConns) array of connections
// to init the new tLuaCOMEnumConnections COM object. The Init will
// build yet another internal copy of this array. Set the
// initial enumerator index to 0.
hr = pCOEnum->Init(cConnections, paConns, 0);
// QueryInterface to return the requested interface pointer.
// An AddRef will be conveniently done by the QI.
if (SUCCEEDED(hr))
hr = pCOEnum->QueryInterface(
IID_IEnumConnections,
(void **)ppIEnum);
}
else
hr = E_OUTOFMEMORY;
// We're done with the locally constructed array copy--delete it.
delete [] paConns;
}
else
hr = E_OUTOFMEMORY;
}
return hr;
}
/*---------------------------------------------------------------------------
tLuaCOMEnumConnections's implementation of its main COM object class
including Constructor, Destructor, QueryInterface, AddRef, Release,
Next, Skip, Reset, and Clone.
---------------------------------------------------------------------------*/
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMEnumConnections::tLuaCOMEnumConnections
Summary: tLuaCOMEnumConnections Constructor.
Args: IUnknown* pHostObj
Pointer to IUnknown interface of the host Connection Point
COM object whose connections are being enumerated.
Modifies: cRefs, pHostObj, iEnumIndex, cConnections,
and paConnections.
Returns: void
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
tLuaCOMEnumConnections::tLuaCOMEnumConnections(
IUnknown* pHostObj)
{
// Zero the COM object's reference count.
cRefs = 0;
// Assign the Host Object pointer.
this->pHostObj = pHostObj;
// Initialize the Connection Point enumerator variables.
iEnumIndex = 0;
cConnections = 0;
paConnections = NULL;
return;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: tLuaCOMEnumConnections::~tLuaCOMEnumConnections
Summary: tLuaCOMEnumConnections Destructor.
Args: void
Modifies: paConnections.
Returns: void
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
tLuaCOMEnumConnections::~tLuaCOMEnumConnections(void)
{
if (NULL != paConnections)