Skip to content

Feature dotnet wrapper#176

Open
mortensp wants to merge 18 commits into
dds-bridge:developfrom
mortensp:feature_dotnet_wrapper
Open

Feature dotnet wrapper#176
mortensp wants to merge 18 commits into
dds-bridge:developfrom
mortensp:feature_dotnet_wrapper

Conversation

@mortensp

@mortensp mortensp commented Jun 7, 2026

Copy link
Copy Markdown
Contributor
  1. DDS_Core added as a wrapper for .Net applications.
  2. DDS_Core_Demo contains examples using most of the methods in dll.lib via the new wrapper.
  3. In dds I have added dds_api.h with 'EXTERN_C DLLEXPORT' on the the SolverComtext methods.
  4. In the docs is a new dotnet_interface.md file deskribing the new wrapper and a link is made in the ReadMe.md file.
  5. The build warning on Directory.Build.props has been totally eliminated.
  6. I'm considering a Nuget package for the wrapper, but for that to work on MacOs i'll need a MacOs version of dds_native from someone:-)

Note: I have not been able to build using Bazel, so everything has been done i VS.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new .NET wrapper layer (DDS_Core) over the DDS native engine, adds a demo application, and wires up Visual Studio projects to produce a dds_native DLL intended for P/Invoke consumption. It also updates the public C++ headers to expose additional context-aware entry points and adds documentation for the new .NET interface.

Changes:

  • Add a new native DLL project (dds_native) and a new C-export wrapper header intended for .NET P/Invoke.
  • Add DDS_Core (.NET 8) plus DDS_Core_Demo with typed interop models and example usage.
  • Update solution/VS project output paths and add docs/README links for the .NET interface.

Reviewed changes

Copilot reviewed 94 out of 95 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
solution/solve_board.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/solve_board_pbn.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/solve_all_boards.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/Solution.slnx Adds dds_native project and build dependencies.
solution/par.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/migration_example.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/hands.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/dealer_par.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/DDS.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/dds_native.vcxproj.filters Adds VS filter mapping for native DLL project sources/headers.
solution/dds_native.vcxproj Adds native DLL project that compiles DDS sources into dds_native.
solution/calc_par_context_example.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/calc_dd_table.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/calc_all_tables.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/calc_all_tables_pbn.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/analyse_play_pbn.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/analyse_play_bin.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
solution/analyse_all_plays_bin.vcxproj Removes explicit props import; updates OutDir/IntDir paths.
README.md Adds link to the new .NET interface documentation.
library/src/solver_context/solver_context.cpp Minor comment change near includes/ctor initializer list.
library/src/api/dds_api.hpp Adds new C-export wrapper surface intended for .NET interop.
library/src/api/calc_par.hpp Updates context-aware calc_par declaration with export/linkage macros.
library/src/api/calc_dd_table.hpp Updates context-aware calc_dd_table* declarations with export/linkage macros.
library/src/api/BUILD.bazel Adds dds_api.hpp to the API Bazel target headers.
dotnet/Directory.Build.props Adds shared MSBuild properties for .NET projects (output paths, warnings, etc.).
dotnet/DDS_Core/Properties/launchSettings.json Enables mixed managed/native debugging for DDS_Core.
dotnet/DDS_Core/Native/DdsNative.cs Declares P/Invoke signatures for legacy and new context-based entry points.
dotnet/DDS_Core/Helpers/stringArray2xDebugView.cs Debugger proxy helper for 2-row string buffers.
dotnet/DDS_Core/Helpers/stringArray2x16.cs Fixed-size 2x16 ASCII string buffer for interop.
dotnet/DDS_Core/Helpers/stringArray2x128.cs Fixed-size 2x128 ASCII string buffer for interop.
dotnet/DDS_Core/Helpers/stringArray10xDebugView.cs Debugger proxy helper for 10-row string buffers.
dotnet/DDS_Core/Helpers/stringArray10x10.cs Fixed-size 10x10 ASCII string buffer for interop.
dotnet/DDS_Core/Helpers/string80.cs Fixed-size 80-byte ASCII string buffer for interop.
dotnet/DDS_Core/Helpers/string106.cs Fixed-size 106-byte ASCII string buffer for interop.
dotnet/DDS_Core/Helpers/SolverContextHandle.cs SafeHandle wrapper for the native SolverContext pointer lifetime.
dotnet/DDS_Core/Helpers/SolveBoardResultExtensions.cs Adds error-code-to-message helpers for DDS return codes.
dotnet/DDS_Core/Helpers/ResultsTable.cs Adds a fixed 5x4 int buffer helper type for interop.
dotnet/DDS_Core/Helpers/intArray5xDebugView.cs Debugger proxy helper for 5-row numeric buffers.
dotnet/DDS_Core/Helpers/intArray5x4.cs Fixed-size 5x4 int buffer for interop.
dotnet/DDS_Core/Helpers/intArray53.cs InlineArray wrapper for 53 ints (play-analysis tricks).
dotnet/DDS_Core/Helpers/intArray52.cs InlineArray wrapper for 52 ints (play trace arrays).
dotnet/DDS_Core/Helpers/intArray5.cs InlineArray wrapper for 5 ints.
dotnet/DDS_Core/Helpers/intArray3.cs InlineArray wrapper for 3 ints.
dotnet/DDS_Core/Helpers/intArray200.cs InlineArray wrapper for up to 200 ints (batch operations).
dotnet/DDS_Core/Helpers/intArray13.cs InlineArray wrapper for 13 ints (future tricks arrays).
dotnet/DDS_Core/Helpers/IBuffer.cs Interface used by debug-view helpers for row-to-string conversion.
dotnet/DDS_Core/Helpers/Global.cs Small constant tables for contract formatting output.
dotnet/DDS_Core/Helpers/FourHands.cs Fixed 4x4 uint buffer representing hands/suits card bitmasks.
dotnet/DDS_Core/DDS.cs Main .NET wrapper class exposing legacy API calls + helper utilities.
dotnet/DDS_Core/DDS_Core.slnx Adds a dedicated .NET solution including dds_native dependency.
dotnet/DDS_Core/DDS_Core.csproj Adds .NET 8 library project configuration.
dotnet/DDS_Core/DataModel/SolverContext.cs Managed SolverContext wrapper using SafeHandle and P/Invoke.
dotnet/DDS_Core/DataModel/SolverConfig.cs Managed SolverConfig struct for native config interop.
dotnet/DDS_Core/DataModel/SolvedPlays.cs Interop model for multiple solved play traces.
dotnet/DDS_Core/DataModel/SolvedPlay.cs Interop model for a single solved play trace.
dotnet/DDS_Core/DataModel/SolvedBoards.cs Interop model for multiple solved boards.
dotnet/DDS_Core/DataModel/PlayTracesPBN.cs Interop model for multiple PBN play traces.
dotnet/DDS_Core/DataModel/PlayTracesBin.cs Interop model for multiple binary play traces.
dotnet/DDS_Core/DataModel/PlayTracePBN.cs Interop model for a PBN play trace.
dotnet/DDS_Core/DataModel/PlayTraceBin.cs Interop model for a binary play trace.
dotnet/DDS_Core/DataModel/ParTextResults.cs Interop model for par text results.
dotnet/DDS_Core/DataModel/ParResultsMasters.cs Interop model for multi-side par results (master format).
dotnet/DDS_Core/DataModel/ParResultsMaster.cs Interop model for par results master record and contracts.
dotnet/DDS_Core/DataModel/ParResultsDealers.cs Interop model for dealer-oriented par results for both sides.
dotnet/DDS_Core/DataModel/ParResultsDealer.cs Interop model for dealer par results.
dotnet/DDS_Core/DataModel/parResults.cs Interop model for par scores/contracts strings (2-sided).
dotnet/DDS_Core/DataModel/FutureTricks.cs Interop model for future tricks results.
dotnet/DDS_Core/DataModel/Enums and Constants/TTKind.cs Managed enum mirroring native TT kind selection.
dotnet/DDS_Core/DataModel/Enums and Constants/Suit.cs Managed suit enum.
dotnet/DDS_Core/DataModel/Enums and Constants/SolvingMode.cs Managed solving-mode enum.
dotnet/DDS_Core/DataModel/Enums and Constants/SolveBoardResult.cs Managed DDS return-code enum + docs.
dotnet/DDS_Core/DataModel/Enums and Constants/Hand.cs Managed hand enum.
dotnet/DDS_Core/DataModel/Enums and Constants/DdsConstants.cs Managed constants mirroring DDS limits.
dotnet/DDS_Core/DataModel/Enums and Constants/CardRanks.cs Managed card-rank bitmask enum.
dotnet/DDS_Core/DataModel/DealPBN.cs Interop model for PBN deal input.
dotnet/DDS_Core/DataModel/Deal.cs Interop model for binary deal input.
dotnet/DDS_Core/DataModel/DdTablesResult.cs Interop model for multiple DD-table results with indexing helper.
dotnet/DDS_Core/DataModel/ddTableResults.cs Interop model for one DD-table result.
dotnet/DDS_Core/DataModel/DdTableDealsPBN.cs Interop model for batch PBN DD-table deal inputs.
dotnet/DDS_Core/DataModel/DdTableDeals.cs Interop model for batch binary DD-table deal inputs.
dotnet/DDS_Core/DataModel/DdTableDealPBN.cs Interop model for single PBN DD-table deal input.
dotnet/DDS_Core/DataModel/ddTableDeal.cs Interop model for single binary DD-table deal input.
dotnet/DDS_Core/DataModel/DDSInfo.cs Interop model for library info (GetDDSInfo).
dotnet/DDS_Core/DataModel/ContractType.cs Interop model for contract representation and formatting.
dotnet/DDS_Core/DataModel/BoardsPBN.cs Interop model for batch PBN board solving input.
dotnet/DDS_Core/DataModel/Boards.cs Interop model for batch binary board solving input.
dotnet/DDS_Core/DataModel/AllParResults.cs Interop model for par results across multiple tables.
dotnet/DDS_Core/.cr/personal/Navigation/Code Places.xml Adds IDE/user state file (should typically be excluded).
dotnet/DDS_Core_Demo/TestData.cs Adds demo test data and validation helpers.
dotnet/DDS_Core_Demo/Properties/launchSettings.json Enables mixed managed/native debugging for DDS_Core_Demo.
dotnet/DDS_Core_Demo/Program.cs Adds demo program showcasing API usage + a benchmark mode.
dotnet/DDS_Core_Demo/DDS_Core_Demo.csproj Adds .NET 8 console demo project referencing DDS_Core.
docs/dotnet_interface.md Adds documentation describing the new .NET wrapper API.
.gitignore Ignores additional .NET and IDE output/state directories.
Comments suppressed due to low confidence (2)

library/src/api/calc_par.hpp:67

  • The SolverContext& overload is now declared with EXTERN_C, which changes it to C linkage and breaks the C++ ABI (symbol name changes) for existing consumers. Since this overload is not callable from C anyway (C++ reference parameter), keep it as normal C++ linkage and expose a separate C wrapper for P/Invoke instead.
    dotnet/DDS_Core/Helpers/ResultsTable.cs:59
  • This file is missing the final closing } for the ResultsTable struct, which makes it syntactically invalid C#. Even if the file is currently excluded from compilation, leaving broken source in-repo is risky/confusing.

Comment thread library/src/api/dds_api.hpp
Comment thread library/src/api/calc_dd_table.hpp
Comment thread dotnet/DDS_Core/Native/DdsNative.cs Outdated
Comment thread dotnet/DDS_Core/DDS.cs Outdated
Comment thread dotnet/DDS_Core_Demo/Program.cs
Comment thread dotnet/DDS_Core_Demo/Program.cs
Comment thread dotnet/DDS_Core/DDS_Core.csproj Outdated
Comment thread dotnet/DDS_Core/DDS_Core.csproj Outdated
Comment thread dotnet/DDS_Core/.cr/personal/Navigation/Code Places.xml Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 93 out of 94 changed files in this pull request and generated 10 comments.

Comments suppressed due to low confidence (1)

library/src/api/calc_par.hpp:67

  • calc_par(SolverContext&, ...) is now marked DLLEXPORT, but it still has normal C++ linkage (mangled symbol). This doesn’t produce a stable entry point for P/Invoke and also changes the DLL export surface in a way that may not be intended. If the goal is .NET interop, prefer a separate extern "C" wrapper that takes an opaque SolverContext* (as in dds_api.hpp) rather than exporting the C++ overload directly.

Comment on lines +63 to +65
for (int c = 0; c < 16; c++)
buf.data[c] = src[c];

Comment on lines +75 to +77
for (int r = 0; r < 4; r++)
for (int c = 0; c < 4; c++)
buf.data[k++] = src[r][c];
Comment on lines +222 to +226
#region ====== Par Text Conversion ======
[DllImport("dds_native", CharSet = CharSet.Ansi)]
public static extern int ConvertToDealerTextFormat( in ParResultsMaster pres
, StringBuilder resp);

Comment on lines +238 to +243

[DllImport("dds_native", CharSet = CharSet.Ansi)]
public static extern int AnalysePlayPBN( in DealPBN dlPBN
, in PlayTracePBN playPBN
, out SolvedPlay solved
, int thrId);
Comment on lines +261 to +265

[DllImport("dds_native", CharSet = CharSet.Ansi)]
public static extern void ErrorMessage( int code
, StringBuilder line);
#endregion
Comment on lines +53 to 56
EXTERN_C DLLEXPORT auto calc_dd_table(
SolverContext& ctx,
const DdTableDeal& table_deal,
DdTableResults* table_results) -> int;
Comment on lines +83 to 86
EXTERN_C DLLEXPORT auto calc_dd_table_pbn(
SolverContext& ctx,
const DdTableDealPBN& table_deal_pbn,
DdTableResults* table_results) -> int;
Comment on lines +61 to +65
EXTERN_C DLLEXPORT void dds_log_append(DDS_SOLVER_CTX ctx,
const char* msg)
{
ctx->utilities().log_append(std::string(msg));
}
Comment on lines +11 to +16
// Creation
EXTERN_C DLLEXPORT DDS_SOLVER_CTX dds_create_solvercontext_default()
{
SolverConfig cfg{};
return new SolverContext(cfg);
}
Comment on lines +84 to +90
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int calc_par( SolverContextHandle ctx
, in DdTableDeal table_deal
, int vulnerable
, out DdTableResults table_results
, out ParResults par_results);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants