How to: Build an MI Provider Using Visual Studio

Once you've created an empty Microsoft Visual Studio project to house your MI provider and generated the source code files from your MOF file, you can insert the generated source code files into the Visual Studio project. This topic provides step-by-step instructions detailing how to accomplish that task.

  1. Start Visual Studio and open the provider project you created.

  2. Open the Solution Explorer by clicking <Ctrl><Alt>L.

  3. Right-click the Header Files folder and, when the context menu displays, select the Add and then Existing item... menu options.

  4. When the Add Existing Item dialog displays, browse to the folder containing the generated provider source code files, select all of the header files (.h), and click Add.

  5. Right-click the Source Files folder and, when the context menu displays, select the Add and then Existing item... menu options.

  6. When the Add Existing Item dialog displays, browse to the folder containing the generated provider source code files, select all of the C source code files (.c), and click Add.

  7. [Optional] If you did not specify the SkipLocalize parameter when you ran the Convert-MofToProvider tool, you will have a resource file (.rc) generated on your behalf called strings.rc. To add it to the project, right-click the Resources Files folder and, when the context menu displays, select the Add and then Existing item... menu options. When the Add Existing Item dialog displays, browse to the folder containing the generated provider source code files, select the strings.rc file, and click Add.

  8. Right-click the project name and, when the context menu displays, select the Add and then Existing item... menu options.

  9. When the Add Existing Item dialog displays, browse to the folder containing the generated provider source code files, select the MOF file (process.mof) and DEF file (provider.def), and click Add. (Holding down the <Ctrl> key will enable you to select multiple files.)

  10. In the Solution Explorer, locate the provider.def file and double-click it to open it in the editor.

  11. When the DEF file is open, change %ProviderName% to the name of your Visual Studio project's output, which is typically the same name as your project. In the following example, the project name is ProcessProvider and produces a DLL called ProcessProvider.DLL. Therefore, the LIBRARY record indicates this.

    LIBRARY         ProcessProvider.DLL
    
    EXPORTS
        DllMain             = DllMain             PRIVATE
        GetProviderClassID  = GetProviderClassID  PRIVATE
        DllGetClassObject   = DllGetClassObject   PRIVATE
        DllCanUnloadNow     = DllCanUnloadNow     PRIVATE
        DllRegisterServer   = DllRegisterServer   PRIVATE
        DllUnregisterServer = DllUnregisterServer PRIVATE
    
  12. Right-click the project name and, when the context menu displays, select the Properties menu option to display the project's Property Pages dialog.

  13. In the Configuration combo box, select the All Configurations item.

  14. On the left side of the dialog, expand Configuration Properties, then expand Linker, and click Input.

  15. For the Module Definition File, enter provider.def and click OK.

  16. Now that you have a skeleton MI provider, you can code your own business logic into the provider. If you're new to MI provider development, download the MI API Samples and look at the Provider sample (under the Process directory). For that sample, the key files of note are the following.

    File(s) Notes
    MSFT_WindowsProcess.c
    MSFT_WindowsProcess.h
    WindowsProcess.c
    WindowsProcess.h
    The MSFT_WindowsProcess.c and MSFT_WindowsProcess.h files were generated using the sample's MOF file and make calls to functions defined and implemented in the WindowsProcess.c and WindowsProcess.h files.
    MSFT_WindowsServiceProcess.c
    MSFT_WindowsServiceProcess.h
    WindowsServiceProcess.c
    WindowsServiceProcess.h
    The MSFT_WindowsServiceProcess.c and MSFT_WindowsServiceProcess.h files were generated using the sample's MOF file and make calls to functions defined and implemented in the WindowsServiceProcess.c and WindowsServiceProcess.h files.
    helper.c
    helper.h
    The helper.c and helper.h files define a handy function - ResultFromWin32Error - for converting Win32 error codes to MI_Result values.
  17. Build the project by clicking <Ctrl><Shift>B. The Output window will show you the build's progress and should display a success message when the build has completed.

  18. Once the provider builds successfully, you can register and test it.