DLLs (C++/CX)

You can use Visual Studio 2012 to create either a standard Win32 DLL or a Windows Runtime component DLL that can be consumed by Windows Store apps. A standard DLL that was created by using an earlier version of Visual Studio or an earlier version of the Visual C++ compiler may not load correctly in a Windows Store app and may not pass the app verification test in the Windows Store.

In almost all cases, when you want to create a DLL for use in a Windows Store app, create it as a Windows Runtime component by using the project template of that name. You can create a Windows Runtime component project for DLLs that have public or private Windows Runtime types. A Windows Runtime component can be accessed from apps that are written in any Windows Runtime-compatible language. By default, the compiler settings for a Windows Runtime component project use the /ZW switch. For more information, see Creating Windows Runtime Components in C++.

To reference a third-party Windows Runtime component binary in your project

  1. Open the shortcut menu for the project that will use the DLL and then choose Properties. On the Common Properties page, choose the Add New Reference button.

  2. A Windows Runtime component consists of a DLL file and a .winmd file that contains the metadata. Typically, these files are located in the same folder. In the left pane of the Add Reference dialog box, choose the Browse button and then navigate to the location of the DLL and its .winmd file. For more information, see Tutorial: Creating and using extension SDKs.

You can create a standard DLL for C++ code that doesn’t consume or produce public Windows Runtime types.

To create a standard DLL in Visual Studio

  1. On the menu bar, choose File, New, Project, and then select the Windows Store DLL template.

  2. Enter a name for the project, and then choose the OK button.

  3. Add the code. Be sure to use __declspec(dllexport) for functions that you intend to export—for example, __declspec(dllexport) Add(int I, in j);

  4. Add #include winapifamily.h to include that header file from the Windows SDK for Windows Store apps and set the macro WINAPI_FAMILY=WINAPI_PARTITION_APP.

To reference a standard DLL project from the same solution

  1. Open the shortcut menu for the project that will use the DLL and then choose Properties. On the Common Properties page, choose the Add New Reference button.

  2. In the left pane, select Solution, and then select the appropriate check box in the right pane.

  3. In your source code files, add a #include statement for the DLL header file, as needed.

To reference a standard DLL binary

  1. Copy the DLL file, the .lib file, and the header file, and paste them in a known location—for example, in your current project folder.

  2. Open the shortcut menu for the project that will use the DLL and then choose Properties. On the Configuration Properties, Linker, Input page, add the .lib file as a dependency.

  3. In your source code files, add a #include statement for the DLL header file, as needed.

To migrate an existing Win32 DLL for Windows Store app compatibility

  1. Create a project of the Windows Store DLL type and add your existing source code to it.

  2. Add #include winapifamily.h to include that header file from the Windows SDK for Windows Store apps and set the macro WINAPI_FAMILY=WINAPI_PARTITION_APP.

  3. In your source code files, add a #include statement for the DLL header file, as needed.

Other Resources

Advanced Topics
Show:
© 2014 Microsoft