.NET COM Platform Abstraction Layer
A library to support porting C/C++ COM binaries from .NET Framework (Windows only) to a .NET cross-platform environment.
Requirements
The following are required to consume DNCP.
Build
The root of the project contains a dncp.proj
file that should be used to build. Directly using CMake is possible but since it is assume the .NET SDK is installed on the system it is recommended to use the dotnet
command. The common build
, clean
and test
commands are supported. For example, dotnet build
will build the project.
Test
Unit and scenario test the library using dotnet test
.
Usage
The recommended way to use DNCP is via git submodules and CMake.
The dncp.h
header contains consistent definitions of common COM APIs. All data types are identically named to those in official Windows' headers. All functions are prefixed with PAL_
followed by the official Win32 name (for example, SysAllocString
is PAL_SysAllocString
). Ideally, all functions provided by DNCP replace the corresponding Win32 APIs as DNCP will forward to the Windows implementation when running on Windows – see windows.c
.
The following defines are set when referencing the dncp::winhdrs
target:
-
DNCP_TYPEDEFS
– Defines the most common Win32 data types needed for .NET scenarios. If this isn't set, the project should define them or include the official Windows' headers. -
DNCP_WINHDRS
– Includes the minimal mocked out Windows' headers provided by DNCP. This is typically needed if building on non-Windows and/or referencing official .NET headers (for example,cor.h
).
Walkthrough
These steps are the general process. Note that depending on how complex your project is, these may not be sufficient.
-
Add DNCP as a submodule to your repository.
git submodule add https://github.com/AaronRobinsonMSFT/DNCP.git
-
Include in your build with CMake's
FetchContent
module.include(FetchContent) FetchContent_Declare( dncp SOURCE_DIR DNCP ) FetchContent_MakeAvailable(dncp)
-
Reference the
dncp.h
header and link the DNCP static library into the target project.#include <dncp.h>
target_link_libraries(mycomlib dncp::dncp)
-
For non-Windows build or if you are trying to avoid referencing any Windows header files, link to the
dncp::winhdrs
target as well.target_link_libraries(mycomlib dncp::winhdrs)
An example of consumption can be found in the scenario test project.
FAQs
- The implementation of some string functions don't check for
NULL
inputs, this makes the APIs less robust. Why don't they check forNULL
?- DNCP is designed to be a drop in replacement for the APIs on Win32. The intent is to match semantics identically. This is reflected in the unit tests when they run on Windows.