If you chose proxy/stub marshaling for your application, the .c and .h files that MIDL generated must be compiled and linked to create a proxy DLL, and that DLL must be entered into the system registry so that clients can locate your interfaces. The MIDL-generated file Dlldata.c contains the necessary routines and other information to build and register a proxy/stub DLL.
The first step in building the DLL is to write a module definition file for the linker, as shown in this example:
LIBRARY example.dll
DESCRIPTION 'generic proxy/stub DLL'
EXPORTS DllGetClassObject @1 PRIVATE
DllCanUnloadNow @2 PRIVATE
DllRegisterServer @4 PRIVATE
DllUnregisterServer @5 PRIVATE
Alternatively, you can specify these exported functions on the LINK command line of your makefile.
The exported functions are declared in Rpcproxy.h, which Dlldata.c includes, and default implementations are part of the RPC run-time library. COM uses these functions to create a class factory, unload DLLs (after making sure that no objects or locks exist), retrieve information about the proxy DLL, and to self-register and unregister the proxy DLL. To take advantage of these predefined functions, you need to invoke the Cpreprocessor /D (or -D) option when you compile the Dlldata.c and Example_p.c files, as shown in the following makefile:
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 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
If you do not specify these preprocessor definitions at compile time, these functions are not automatically defined (that is, the macros in Rpcproxy.c expand to nothing). You would have to have defined them explicitly in another source file, whose module would also be included in the final linking and compilation on the C compiler command line.
When REGISTER_PROXY_DLL is defined, Rpcproxy.h provides for additional conditional compilation control with PROXY_CLSID=<guid>, PROXY_CLSID_IS=<explicit value of guid>, and ENTRY_PREFIX=<prefix string>. These macro definitions are described in greater detail in C-Compiler Definitions for Proxy/Stubs in the MIDL Programmer's Guide. Also, the sample programs Marshal and Marshal2, in the COM Tutorial section of the Platform SDK use these macros to register the Proxy DLL.
If, for some reason, you cannot use the default proxy stub registration routines, you can manually register the DLL by adding the following entries to the system registry, using Regedit.exe (for Windows® 95) or Regedt32.exe (for Windows NT®).
\HKEY_CLASSES_ROOT\Interface\{<iid>}
=ICustomInterfaceName
\HKEY_CLASSES_ROOT\Interface\{<iid>}\ProxyStubClsid32
={<clsid>}
\HKEY_CLASSES_ROOT\CLSID\{<clsid>}
=ICustomInterfaceName_PSFactory
\HKEY_CLASSES_ROOT\CLSID\{<clsid>}\InprocServer32
=proxstub.dll
Registering COM Servers, Self-Registration, C-Compiler Definitions for Proxy/Stubs