C-Compiler Definitions for Proxy/Stubs

The header file RPCPROXY.H includes the following macro definitions, which you can invoke with the /D (or -D) preprocessor switch at compile time:

MACRO Description
REGISTER_PROXY_DLL Generates DllMain, DllRegisterServer, and DllUnregisterServer functions for automatically registering a proxy DLL.
PROXY_CLSID=<clsid> Specifies a class ID for the server. If this macro is not defined, the default CLSID is the first interface ID that the MIDL compiler encounters in the IDL specification for the Proxy/Stub server.
PROXY_CLSID_IS={0x8hexdigits, 0x4hexdigits,0x4hexdigits,{0x2hexdigits,0x2hexdigits,0x2hexdigits,0x2hexdigits,0x2hexdigits,0x2hexdigits,0x2hexdigits,0x2hexdigits,}} Specifies the value of the server's class ID in binary hex format.
NT35_STRICT Specifies that the target platform is Windows NT 3.5. This switch disables the new functions added after the Windows NT 3.5 release.

By defining the REGISTER_PROXY_DLL macro when compiling DLLDATA.C, your proxy/stub marshalling DLL will automatically include default definitions for the DllMain, DllRegisterServer, and DllUnregisterServer functions.You can use these functions to self-register your proxy DLL in the system registry as described in Building and Registering the Proxy DLL in the COM Programmer's Guide.

This default registration code uses the GUID of the first interface encountered as the CLSID for registering the entire proxy/stub DLL server. COM later uses this CLSID to locate and load the compiled proxy/stub server for the marshaling of any of the interfaces the server is registered to handle. When an application makes an interface method call that crosses thread, process, or machine boundaries, COM uses the interface's IID registry entry to locate the CLSID registry entry for the proxy/stub marshaling server. It then uses this CLSID to load the server (if it isn't already loaded) so the Interface call can then be marshaled.

Use the PROXY_CLSID=<clsid> macro when you want to explicitly specify the proxy/stub server's CLSID rather than rely on the default CLSID. For example, if you are building a standard marshaling DLL as your own in-process COM server, or if you need to define your own DllMain to handle DLL_PROCESS_ATTACH.

Use PROXY_CLSID_IS= macro instead of PROXY_CLSID to define the value of the CLSID in the binary hexadecimal format that the DEFINE_GUID macro uses.

Also note that when the default DllRegisterServer function runs, it registers the server with ThreadingModel=Both.

The following makefile example uses the REGISTER_PROXY_DLL and PROXY_CLSID= macros:

example.h example.tlb example_p.c example_i.c dlldata.c : example.idl
    midl example.idl
dlldata.obj : dlldata.c
    CL /c /DWIN32 /DREGISTER_PROXY_DLL dlldata.c
example.obj : example_p.c
    CL /c /DWIN32 /DREGISTER_PROXY_DLL \
    /DPROXY_CLSID=7a98c250-6808-11cf-b73b-00aa00b677a7
example_p.c
iids.obj : example_i.c
PROXYSTUBOBJS = dlldata.obj example.obj iids.obj
PROXYSTUBLIBS = kernel32.lib rpcndr.lib rpcns4.lib rpcrt4.lib uuid.lib
proxy.dll : $(PROXYSTUBOBJX) example.def
    link /dll /out:proxy.dll /def:example.def
        $(PROXYSTUBOBJS) $(ORIXYSTUBLIBS)
    regsvr32 /s proxy.dll

For more information on the /D preprocessor option, see your C compiler documentation .