Lim Bio Liong - Professional Profile
|1. A Proxy/Stub DLL is always required under one of the following situations :
1.1 Your COM object resides in an EXE Server.
Further note the following :
1.1.1 This is where the use of marshalling is most natural.
1.1.2 In order for your client (a separate EXE application) to use your COM object, marshalling is required.
1.2 Your COM object resides in a DLL Server.
Further note the following :
1.2.1 A COM object will always be used by a thread in a client application.
1.2.2 A client thread which uses COM will always reside in an apartment.
1.2.3 A COM object will also always reside in an apartment.
1.2.3 If the apartment of a client thread which uses a COM object is not the same the apartment of the COM object, marshalling will be required.
To put things simply, where a COM object is accessed across threads (be it threads of a single process or threads across processes), marshalling may be involved.
2. Even when you are using OLE-automation-compatible types, marshalling will be involved.
2.1 In this case, the standard COM marshaller is used. However, note carefully :
2.1.1 That this is provided that your interface has been assigned the [dual] or the [oleautomation] attribute.
2.1.2 If not, your interface cannot be marshaled using the standard COM marshaler.
2.2 The standard COM marshaler is oleaut32.dll (the standard Proxy/Stub DLL for Ole Automation).
2.2 In this case, you do not have to build any Proxy/Stub DLL in order for your clients to use your interface.
3. If your interface uses non-OLE-automation-compatible types as parameters, or that it uses OLE-automation-compatible parameter types but that it is not marked with the [dual] or [oleautomation] attributes, you would definitely need a Proxy/Stub DLL.
3.1 Note that your Proxy/Stub DLL is meant to be used for interfaces and not implementations.
3.2 For example, if you have an interface IAnInterface, say. And you have two implementations of IAnInterface in two separate DLLs, the two implementations will use the same Proxy/Stub DLL.
3.3 Every interface that is ever defined in a Windows OS will have an entry in the registry (under the HKEY_CLASSES_ROOT\Interface Key). They are registered under their GUIDs.
3.4 You will notice that many of the interface entries have a "ProxyStubClsid32" subkey.
3.5 This subkey contains a GUID which identifies the Proxy/Stub DLL associated with this Interface.
4. If you use the MIDL compiler, the source codes for building a Proxy/Stub DLL for your interface can be generated for you.
4.1 The followig files, generated by the MIDL compiler, are the raw materials for your Proxy/Stub :
where * denotes the name of your COM project.
The *_i.c file contains the actual definitions of the IIDs and CLSIDs defined in your COM project IDL file.
The *_p.c file contains proxy/stub data specific to the interfaces defined in your IDL file.
The dlldata.c file contains macros and code that help to generate basic COM DLL requirements (e.g. DllCanUnloadNow(), DllGetClassObject(), etc).
4.2 Start Visual C++ and create a basic Win32 DLL (non-MFC and non-ATL) project.
4.3 Add the *_i.c, *_p.c and dlldata.c files into this project.
4.4 Create your own .DEF file which should contain the following definitions :
LIBRARY <YOUR MODULE NAME>
4.5 You will need to supply the following pre-processor definitions to your project :
- either _WIN32_WINNT=0x400
- or _WIN32_WINNT=0x500 (if any interfaces has async_uuid attribute)
The REGISTER_PROXY_DLL definition will ensure that two of the basic COM DLL required exported functions DllRegisterServer() and DllUnregisterServer() are generated within dlldata.c.
The "_WIN32_WINNT=0x400" or "_WIN32_WINNT=0x500" is required otherwise you will face several compilation errors.
If any interface has been attributed with "async_uuid" then you will also need to use the correct-versioned "rpcproxy.h" file. If you are not using the correct-versioned one, the compiler will complain of this. The latest MS SDK include directory usually will contain the latest version of "rpcproxy.h". To use this, set $(MSSDK)\include in your "Additional include directories" path (under project settings).
4.6 Your project will also need to link to rpcrt4.lib.
4.7 After building a successful Proxy/Stub DLL project, you must remember to register this DLL.
<div class="ForumMod">modified on Thursday, January 29, 2009 12:31 AM</div>
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.