You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* updates for 2017
* added new file for 3rd party libs and updated toc
* updates to tocs and to overview pages
* updates in the porting section
* additional updates to porting content
* changed token to literal VS 2017
* changed token to literal VS2017
* changed token to literal VS2017
* changed token to literal VS 2015 (not 2017)
* fixed link
* fixed links
* fixed link
* fixed links
* fixed token
* fixed token
* fixed another token
Copy file name to clipboardExpand all lines: docs/porting/how-to-use-existing-cpp-code-in-a-universal-windows-platform-app.md
+23-21Lines changed: 23 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,9 @@ translation.priority.ht:
31
31
- "zh-tw"
32
32
---
33
33
# How to: Use Existing C++ Code in a Universal Windows Platform App
34
-
This topic contains a discussion and procedures for porting C++ libraries (DLLs and static libraries) to the Universal Windows Platform (UWP), which is a necessary part of creating a Windows 10 UI layer that works with your existing classic Win32 C++ code or standard, cross-platform C++ code. There are several ways to use existing C++ code in a Universal Windows App.
34
+
Perhaps the easiest way to get your desktop program running in the UWP environment is to use the Desktop Bridge technologies. These include the Desktop App Converter, which will package your existing application as a UWP app with no code changes required. For more information, see [Bring your desktop app to the Universal Windows Platform (UWP) with the Desktop Bridge](https://msdn.microsoft.com/windows/uwp/porting/desktop-to-uwp-root).
35
+
36
+
The rest of this topic discusses how to port C++ libraries (DLLs and static libraries) to the Universal Windows Platform (UWP). You might want to do this so that your core C++ logic can be used with multiple UWP apps.
35
37
36
38
UWP Apps run in a protected environment, and as a result, many Win32, COM, and CRT API calls that might compromise the security of the platform are not allowed. The compiler can detect such calls and generate an error, if the /ZW option is used. You can use the App Certification Kit on your application to detect code that calls forbidden APIs. See [Using the App Certification Kit](https://msdn.microsoft.com/library/windows/apps/hh694081.aspx).
37
39
@@ -41,7 +43,7 @@ This topic contains a discussion and procedures for porting C++ libraries (DLLs
41
43
42
44
If you have source code for the DLL or static library, you can recompile with /ZW as a UWP project. If you do that, you can add a reference using the Solution Explorer, and use it in C++ UWP apps. In the case of a DLL, you link with the export library.
43
45
44
-
To expose functionality to callers in other languages, you can convert the library into a Windows Runtime Component. Windows Runtime Components differ from ordinary DLLs in that they include metadata in the form of .winmd files which describe the contents in a way that .NET and JavaScript consumers require. To expose API elements to other languages, you can add C++/CX constructs, such as ref classes, and make them public, or use the [Windows Runtime C++ Template Library (WRL)](../windows/windows-runtime-cpp-template-library-wrl.md).
46
+
To expose functionality to callers in other languages, you can convert the library into a Windows Runtime Component. Windows Runtime Components differ from ordinary DLLs in that they include metadata in the form of .winmd files which describe the contents in a way that .NET and JavaScript consumers require. To expose API elements to other languages, you can add C++/CX constructs, such as ref classes, and make them public, or use the [Windows Runtime C++ Template Library (WRL)](../windows/windows-runtime-cpp-template-library-wrl.md). In Windows 10 and later, you can use the [C++/WinRT library](https://github.com/microsoft/cppwinrt) instead of C++/CX.
45
47
46
48
The preceding discussion doesn't apply to the case of COM components, which must be handled differently. If you have a COM server in an EXE or DLL, you can use it in a Universal Windows Project as long as you package it as a [registration-free COM component](https://msdn.microsoft.com/library/dd408052.aspx), add it to your project as a Content file, and instantiate it using [CoCreateInstanceFromApp](https://msdn.microsoft.com/library/windows/apps/hh404137.aspx). See [Using Free-COM DLL in Windows Store C++ Project](http://blogs.msdn.com/b/win8devsupport/archive/2013/05/20/using-free-com-dll-in-windows-store-c-project.aspx).
47
49
@@ -91,23 +93,23 @@ This topic contains a discussion and procedures for porting C++ libraries (DLLs
91
93
92
94
class Giraffe
93
95
{
94
-
int id;
95
-
Giraffe(int id_in);
96
-
friend class GiraffeFactory;
96
+
int id;
97
+
Giraffe(int id_in);
98
+
friend class GiraffeFactory;
97
99
98
100
public:
99
-
GIRAFFE_API int GetID();
101
+
GIRAFFE_API int GetID();
100
102
};
101
103
102
104
class GiraffeFactory
103
105
{
104
-
static int nextID;
105
-
106
+
static int nextID;
107
+
106
108
public:
107
-
GIRAFFE_API GiraffeFactory();
108
-
GIRAFFE_API static int GetNextID();
109
-
GIRAFFE_API static Giraffe* Create();
110
-
};
109
+
GIRAFFE_API GiraffeFactory();
110
+
GIRAFFE_API static int GetNextID();
111
+
GIRAFFE_API static Giraffe* Create();
112
+
};
111
113
```
112
114
113
115
And the following code file:
@@ -123,24 +125,24 @@ This topic contains a discussion and procedures for porting C++ libraries (DLLs
123
125
124
126
int Giraffe::GetID()
125
127
{
126
-
return id;
128
+
return id;
127
129
}
128
130
129
131
int GiraffeFactory::nextID = 0;
130
132
131
133
GiraffeFactory::GiraffeFactory()
132
134
{
133
-
nextID = 0;
135
+
nextID = 0;
134
136
}
135
137
136
138
int GiraffeFactory::GetNextID()
137
139
{
138
-
return nextID;
140
+
return nextID;
139
141
}
140
142
141
143
Giraffe* GiraffeFactory::Create()
142
144
{
143
-
return new Giraffe(nextID++);
145
+
return new Giraffe(nextID++);
144
146
}
145
147
146
148
int giraffeFunction();
@@ -195,10 +197,10 @@ This topic contains a discussion and procedures for porting C++ libraries (DLLs
195
197
```
196
198
MainPage::MainPage()
197
199
{
198
-
InitializeComponent();
199
-
GiraffeFactory gf;
200
-
Giraffe* g = gf.Create();
201
-
int id = g->GetID();
200
+
InitializeComponent();
201
+
GiraffeFactory gf;
202
+
Giraffe* g = gf.Create();
203
+
int id = g->GetID();
202
204
}
203
205
204
206
```
@@ -233,7 +235,7 @@ LNK4264: archiving object file compiled with /ZW into a static library; note tha
233
235
234
236
2. Close the project.
235
237
236
-
3. In the Windows File Explorer, locate the project. By default, Visual Studio uses the Visual Studio 2015\Projects folder in your Documents folder. Locate the C++ library project that contains the code you want to port. Copy the source files (header files, code files, and any other resources, including in subdirectories) from your C++ library project, and paste them into the project folder, making sure to preserve the same folder structure.
238
+
3. In the Windows File Explorer, locate the project. By default, Visual Studio uses the Visual Studio 2017\Projects folder in your Documents folder. Locate the C++ library project that contains the code you want to port. Copy the source files (header files, code files, and any other resources, including in subdirectories) from your C++ library project, and paste them into the project folder, making sure to preserve the same folder structure.
237
239
238
240
4. Reopen the Windows Runtime Component project, and open the shortcut menu for the project node in **Solution Explorer**, and choose **Add, Existing Item**.
Copy file name to clipboardExpand all lines: docs/porting/modifying-winver-and-win32-winnt.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,7 +66,7 @@ Visual C++ no longer supports targeting Windows 95, Windows 98, Windows ME, Wind
66
66
#define _WIN32_WINNT_WIN10 0x0A00 // Windows 10
67
67
```
68
68
69
-
If you don't see all of these versions of Windows listed in a copy of SDKDDKVer.h that you're looking at, you probably are using an older version of the Windows SDK. By default, Win32 projects in [!INCLUDE[vs_dev14](../ide/includes/vs_dev14_md.md)] use the Windows 8.1 SDK. To use the Windows 10 SDK, see [How to: Use the Windows 10 SDK in a Windows Desktop Application](../windows/how-to-use-the-windows-10-sdk-in-a-windows-desktop-application.md).
69
+
If you don't see all of these versions of Windows listed in a copy of SDKDDKVer.h that you're looking at, you probably are using an older version of the Windows SDK. By default, Win32 projects in Visual Studio 2017 use the Windows 10 SDK.
70
70
71
71
> [!NOTE]
72
72
> Values are not guaranteed to work if you include internal MFC headers in your application.
@@ -76,4 +76,4 @@ Visual C++ no longer supports targeting Windows 95, Windows 98, Windows ME, Wind
76
76
For more information about the meanings of these macros, see [Using the Windows Headers](http://msdn.microsoft.com/library/windows/desktop/aa383745).
0 commit comments