]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSWindows/Applications/ExplorerPlugin/ClassFactory.cpp
44c9fb2fd2763e421c888d2ef2438b112fefca8b
[apple/mdnsresponder.git] / mDNSWindows / Applications / ExplorerPlugin / ClassFactory.cpp
1 /*
2 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24
25 Change History (most recent first):
26
27 $Log: ClassFactory.cpp,v $
28 Revision 1.1 2004/01/30 03:01:56 bradley
29 Explorer Plugin to browse for Rendezvous-enabled Web and FTP servers from within Internet Explorer.
30
31 */
32
33 #include "StdAfx.h"
34
35 #include "DebugServices.h"
36
37 #include "ExplorerBar.h"
38 #include "ExplorerPlugin.h"
39
40 #include "ClassFactory.h"
41
42 // MFC Debugging
43
44 #ifdef _DEBUG
45 #define new DEBUG_NEW
46 #undef THIS_FILE
47 static char THIS_FILE[] = __FILE__;
48 #endif
49
50 //===========================================================================================================================
51 // ClassFactory
52 //===========================================================================================================================
53
54 ClassFactory::ClassFactory( CLSID inCLSID )
55 {
56 mCLSIDObject = inCLSID;
57 mRefCount = 1;
58 ++gDLLRefCount;
59 }
60
61 //===========================================================================================================================
62 // ~ClassFactory
63 //===========================================================================================================================
64
65 ClassFactory::~ClassFactory( void )
66 {
67 check( gDLLRefCount > 0 );
68
69 --gDLLRefCount;
70 }
71
72 #if 0
73 #pragma mark -
74 #pragma mark == IUnknown methods ==
75 #endif
76
77 //===========================================================================================================================
78 // QueryInterface
79 //===========================================================================================================================
80
81 STDMETHODIMP ClassFactory::QueryInterface( REFIID inID, LPVOID *outResult )
82 {
83 HRESULT err;
84
85 check( outResult );
86
87 if( IsEqualIID( inID, IID_IUnknown ) )
88 {
89 *outResult = this;
90 }
91 else if( IsEqualIID( inID, IID_IClassFactory ) )
92 {
93 *outResult = (IClassFactory *) this;
94 }
95 else
96 {
97 *outResult = NULL;
98 err = E_NOINTERFACE;
99 goto exit;
100 }
101
102 ( *( (LPUNKNOWN *) outResult ) )->AddRef();
103 err = S_OK;
104
105 exit:
106 return( err );
107 }
108
109 //===========================================================================================================================
110 // AddRef
111 //===========================================================================================================================
112
113 STDMETHODIMP_( DWORD ) ClassFactory::AddRef( void )
114 {
115 return( ++mRefCount );
116 }
117
118 //===========================================================================================================================
119 // Release
120 //===========================================================================================================================
121
122 STDMETHODIMP_( DWORD ) ClassFactory::Release( void )
123 {
124 DWORD count;
125
126 count = --mRefCount;
127 if( count == 0 )
128 {
129 delete this;
130 }
131 return( count );
132 }
133
134 #if 0
135 #pragma mark -
136 #pragma mark == IClassFactory methods ==
137 #endif
138
139 //===========================================================================================================================
140 // CreateInstance
141 //===========================================================================================================================
142
143 STDMETHODIMP ClassFactory::CreateInstance( LPUNKNOWN inUnknown, REFIID inID, LPVOID *outObject )
144 {
145 HRESULT err;
146 LPVOID obj;
147
148 check( outObject );
149
150 obj = NULL;
151 *outObject = NULL;
152 require_action( !inUnknown, exit, err = CLASS_E_NOAGGREGATION );
153
154 // Create the object based on the CLSID.
155
156 if( IsEqualCLSID( mCLSIDObject, CLSID_ExplorerBar ) )
157 {
158 try
159 {
160 obj = new ExplorerBar();
161 }
162 catch( ... )
163 {
164 // Don't let exception escape.
165 }
166 require_action( obj, exit, err = E_OUTOFMEMORY );
167 }
168 else
169 {
170 err = E_FAIL;
171 goto exit;
172 }
173
174 // Query for the specified interface. Release the factory since QueryInterface retains it.
175
176 err = ( (LPUNKNOWN ) obj )->QueryInterface( inID, outObject );
177 ( (LPUNKNOWN ) obj )->Release();
178
179 exit:
180 return( err );
181 }
182
183 //===========================================================================================================================
184 // LockServer
185 //===========================================================================================================================
186
187 STDMETHODIMP ClassFactory::LockServer( BOOL inLock )
188 {
189 DEBUG_UNUSED( inLock );
190
191 return( E_NOTIMPL );
192 }