🛠️ .NET Framework 4.5 Integration Example
This example shows how to use the ATS CodeCheck native shared library from a .NET Framework 4.5 application using P/Invoke to call native functions like ATS_Init, ATS_Activate, ATS_CheckCode, and ATS_GetVersion.
🧱 Native Function Signatures
Make sure to use the correct function signatures defined in the native library:
extern int ATS_Init(const char* uid, const char* workingDir, char* jsonResponseBuffer, int bufferSize);
extern int ATS_CheckCode(const char* jsonRequest, char* jsonResponseBuffer, int bufferSize);
extern int ATS_GetVersion(char* versionBuffer, int bufferSize);
extern int ATS_Activate(const char* uid, const char* workingDir, char* jsonResponseBuffer, int bufferSize);
📄 C# Declaration
using System;
using System.Runtime.InteropServices;
using System.Text;
class Program
{
[DllImport("atscodecheck.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int ATS_Init(string uid, string workingDir, StringBuilder jsonResponseBuffer, int bufferSize);
[DllImport("atscodecheck.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int ATS_GetVersion(StringBuilder versionBuffer, int bufferSize);
[DllImport("atscodecheck.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int ATS_CheckCode(string jsonRequest, StringBuilder jsonResponseBuffer, int bufferSize);
[DllImport("atscodecheck.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int ATS_Activate(string uid, string workingDir, StringBuilder jsonResponseBuffer, int bufferSize);
static void Main()
{
string uid = "test-uid";
string workingDir = ".";
StringBuilder initResponse = new StringBuilder(2048);
if (ATS_Init(uid, workingDir, initResponse, initResponse.Capacity) != 0)
{
Console.WriteLine("❌ Initialization failed");
return;
}
else
{
Console.WriteLine("✅ Initialization successful: " + initResponse.ToString());
}
// Get library version
StringBuilder version = new StringBuilder(256);
if (ATS_GetVersion(version, version.Capacity) == 0)
{
Console.WriteLine("📦 Library Version: " + version.ToString());
}
// Activate license
StringBuilder activationResponse = new StringBuilder(2048);
int activationResult = ATS_Activate(uid, workingDir, activationResponse, activationResponse.Capacity);
if (activationResult == 0)
{
Console.WriteLine("🔓 Activation successful: " + activationResponse.ToString());
}
else
{
Console.WriteLine("❌ ATS_Activate failed with code: " + activationResult);
}
// Create request
string base64Barcode = "REPLACE_WITH_VALID_BASE64";
string json = $"{{}}";
StringBuilder response = new StringBuilder(2048);
int result = ATS_CheckCode(json, response, response.Capacity);
if (result == 0)
{
Console.WriteLine("✅ Response: " + response.ToString());
}
else
{
Console.WriteLine("❌ ATS_CheckCode failed with code: " + result);
}
}
}
⚠️ Note:
- Ensure
atscodecheck.dllandlibatscodecheck.hare placed in your build output directory.
📬 Questions?
Contact support@atscodecheck.dev for help.