May 1996

Microsoft Systems Journal Homepage

Using MIDL with Visual C++

While MIDL.exe ships with Visual C++ 4.0, IDL files are not directly supported by the environment. To use MIDL in a Visual C++ project, you must perform the following steps.
First, insert your IDL file into the project. This adds the file to your project, but Visual C++ does not yet know how to compile it. If you are generating a proxy/stub for an interface, be sure that the generated project type is Dynamic Link Library.
Next, select Settings from the Build menu to inform Visual C++ that this file must run MIDL.exe to compile this file. Once the Build Settings dialog is displayed, you will need to select your IDL file from the hierarchical display of your project.
With your IDL file selected, choose the Custom Build property page. Add

 midl.exe /c_ext /ms_ext /app_config $(InputPath)
to the Build Command(s) list. Assuming that your IDL file is named xxx.idl, add these four files to the Output File(s) list: xxx.h, xxx_p.c, xxx_i.c, and dlldata.c. Then compile the IDL file to create the four generated files. You then must add the three C files to your project to compile and link your DLL.
Since you want the generated proxy/stub DLL to export the standard self-registration entry points, be sure to define the symbol REGISTER_PROXY_DLL in the C/C++options for the dlldata.c file. Modifying the dlldata.c file directly is a really bad idea, since the next time you run MIDL.exe, the file will be completely overwritten.
Add the RPC run-time import library (rpcrt4.lib) to the list of libraries used in the Link options. Then, create and add a simple DEF file that exports the standard four COM entry points: DllGetClassObject, DllCanUnloadNow, DllRegisterServer, and DllUnregisterServer. MIDL generated DLLs also need to export the entry-point GetProxyDllInfo. Finally, install using RegSvr32.

© 1997 Microsoft Corporation. All rights reserved.
Terms of Use