This project provides a managed C# wrapper around the native CwAPI3D C++ API, allowing .NET applications to interact with the CwAPI3D library.
The C# bridge uses C++/CLI to create a wrapper layer that translates between the managed .NET world and the unmanaged C++ API. This allows C# applications to use the CwAPI3D functionality through a clean, type-safe interface.
- Visual Studio 2019 or newer with:
- Desktop development with C++ workload
- .NET desktop development workload
- C++/CLI support component
- CwAPI3D (ensure you have the headers)
-
Clone the repository
git clone <repository-url> cd csharp_bridge -
Configure include and library paths
- Open the solution in Visual Studio
- Right-click on the
csharp_bridgeproject and select "Properties" - Navigate to C/C++ > General > Additional Include Directories
- Add the path to the CwAPI3D headers
- Navigate to Linker > General > Additional Library Directories
- Add the path to the CwAPI3D libraries
-
Set the correct runtime library
- In project properties, go to C/C++ > Code Generation > Runtime Library
- Select the appropriate option (e.g., Multi-threaded DLL (/MD))
-
Build the solution
- Select the appropriate configuration (Debug/Release) and platform
- Build the solution (F7 or Ctrl+Shift+B)
- Watch for memory leaks: Since you're bridging between managed and unmanaged code, carefully monitor memory management.
- Use the Locals and Watch windows: These help track the state of variables as you step through the code.
- Use the Call Stack window: Helpful for understanding the flow of execution between managed and native code.
- Check Output window: Look for any runtime errors or messages.
To use the CwAPI3D bridge in your C# project:
- Add a reference to the
csharp_bridge.dll - Initialize the API:
using CwAPI3D.Net.Bridge;
public class Initializer
{
public static bool Run(IntPtr nativeFactory)
{
// ....
// Initialize API
var wrapper = new CwApi3DFactory(nativeFactory);
var text = wrapper.GetSomething();
Console.WriteLine(@"Received from native factory: " + text);
// Get specific controller
var elementController = wrapper.GetElementController();
// Use the controller
var allElements = elementController.GetAllIdentifiableElementIDs();
}
}CwAPI3DFactory: Main entry point for creating an API instanceElementController: Wrapper for element management functions- Additional controllers for other API functionality
- DllNotFoundException: Ensure all native DLLs are in the path or in the same directory as your executable
- AccessViolationException: Often indicates a memory issue, check pointer handling
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request