2026-03-28 16:54:11 +11:00
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include "ANSLicense.h"
#include "Utility.h"
2026-05-09 16:47:46 +10:00
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <locale>
2026-03-28 16:54:11 +11:00
BOOL APIENTRY DllMain ( HMODULE hModule ,
DWORD ul_reason_for_call ,
LPVOID lpReserved
)
{
switch ( ul_reason_for_call )
{
case DLL_PROCESS_ATTACH :
case DLL_THREAD_ATTACH :
case DLL_THREAD_DETACH :
case DLL_PROCESS_DETACH :
break ;
}
return TRUE ;
}
extern "C" __declspec ( dllexport ) int CreateANSLSHandle ( ANSCENTER :: ANSLSHelper * * Handle , const char * privateKey , const char * publicKey , const char * licenseServiceURL ) {
try {
if ( ! Handle || ! privateKey || ! publicKey || ! licenseServiceURL ) return 0 ;
std :: string st_privateKey = privateKey ;
std :: string st_publicKey = publicKey ;
std :: string st_licenseServiceURL = licenseServiceURL ;
( * Handle ) = new ANSCENTER :: ANSLSHelper ( st_privateKey , st_publicKey , st_licenseServiceURL );
if ( * Handle == nullptr ) return 0 ;
else return 1 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int Release ( ANSCENTER :: ANSLSHelper * * Handle ) {
try {
if ( ! Handle || ! ( * Handle )) return 1 ; // already released
delete * Handle ;
* Handle = nullptr ;
return 1 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) void SetLicenseServiceURL ( ANSCENTER :: ANSLSHelper * * Handle , const char * licenseServiceURL ) {
if ( ! Handle || ! ( * Handle ) || ! licenseServiceURL ) return ;
( * Handle ) -> SetLicenseServiceURL ( licenseServiceURL );
}
extern "C" __declspec ( dllexport ) int GetLicenseData ( ANSCENTER :: ANSLSHelper * * Handle , const char * licenseKey , LStrHandle licenseData ) {
try {
if ( ! Handle || ! ( * Handle ) || ! licenseKey ) return 0 ;
std :: string st = ( * Handle ) -> GetLicenseData ( licenseKey );
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( licenseData , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * licenseData ) -> cnt = size ;
memcpy (( * licenseData ) -> str , st . c_str (), size );
return 1 ;
}
else return 0 ;
}
else {
return 0 ;
}
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int LoadLicenseTemplate ( ANSCENTER :: ANSLSHelper * * Handle , const char * templateFilePath ) {
try {
if ( ! Handle || ! ( * Handle ) || ! templateFilePath ) return 0 ;
bool result = ( * Handle ) -> LoadLicenseTemplate ( templateFilePath );
if ( result == true ) return 1 ;
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int GetCurrentHardwareId ( ANSCENTER :: ANSLSHelper * * Handle , LStrHandle currentHwID ) {
try {
if ( ! Handle || ! ( * Handle )) return 0 ;
std :: string st = ( * Handle ) -> GetCurrentHardwareId ();
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( currentHwID , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * currentHwID ) -> cnt = size ;
memcpy (( * currentHwID ) -> str , st . c_str (), size );
return 1 ;
}
else return 0 ;
}
else return 0 ;
}
catch (...) {
return 0 ;
}
}
2026-06-18 05:55:31 +10:00
extern "C" __declspec ( dllexport ) int GetHardwareId ( LStrHandle currentHwID ) {
try {
std :: string st = ANSCENTER :: ANSLicenseHelper :: GetHardwareId ();
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( currentHwID , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * currentHwID ) -> cnt = size ;
memcpy (( * currentHwID ) -> str , st . c_str (), size );
return 1 ;
}
else return 0 ;
}
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int GetHardwareIdBuffer ( char * buffer , int bufferSize ) {
try {
if ( ! buffer || bufferSize <= 0 ) return 0 ;
std :: string st = ANSCENTER :: ANSLicenseHelper :: GetHardwareId ();
int size = ( int ) st . length ();
if ( size <= 0 ) return 0 ;
// Need room for the string plus the null terminator.
if ( size + 1 > bufferSize ) return 0 ;
memcpy ( buffer , st . c_str (), size );
buffer [ size ] = '\0' ;
return size ;
}
catch (...) {
return 0 ;
}
}
2026-03-28 16:54:11 +11:00
extern "C" __declspec ( dllexport ) int GenerateKey ( ANSCENTER :: ANSLSHelper * * Handle , int productId , const char * registrationName , int productFeature , int trialLicense , LStrHandle generatedKey ) {
try {
if ( ! Handle || ! ( * Handle ) || ! registrationName ) return 0 ;
bool enableTrialLicense = false ;
if ( trialLicense > 0 ) enableTrialLicense = true ;
std :: string st = ( * Handle ) -> GenerateKey ( productId , registrationName , productFeature , enableTrialLicense );
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( generatedKey , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * generatedKey ) -> cnt = size ;
memcpy (( * generatedKey ) -> str , st . c_str (), size );
return 1 ;
}
else return 0 ;
}
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int GenerateKeyWithExpiredDate ( ANSCENTER :: ANSLSHelper * * Handle , int productId , const char * registrationName , int productFeature , int expiredYear , int expiredMonth , int expiredDate , LStrHandle generatedKey ) {
try {
if ( ! Handle || ! ( * Handle ) || ! registrationName ) return 0 ;
std :: string st = ( * Handle ) -> GenerateKey ( productId , registrationName , productFeature , expiredYear , expiredMonth , expiredDate );
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( generatedKey , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * generatedKey ) -> cnt = size ;
memcpy (( * generatedKey ) -> str , st . c_str (), size );
return 1 ;
}
else return 0 ;
}
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int CheckLicenseKey ( ANSCENTER :: ANSLSHelper * * Handle , const char * licenseKey , const char * registrationName , int productId ){ //, LStrHandle strEnableFeature) { // Check if the license key is valid
try {
if ( ! Handle || ! ( * Handle ) || ! licenseKey || ! registrationName ) return - 1 ;
int enFeatures = 0 ;
bool result = ( * Handle ) -> CheckLicenseKey ( licenseKey , registrationName , productId , enFeatures );
if ( result ) return enFeatures ;
else return - 1 ;
}
catch (...) {
return - 1 ;
}
}
extern "C" __declspec ( dllexport ) int ValidateLicense ( ANSCENTER :: ANSLSHelper * * Handle , const char * licenseKey , const char * registrationName , const char * existingActivationKey , LStrHandle activationKey ) {
try {
if ( ! Handle || ! ( * Handle ) || ! licenseKey || ! registrationName || ! existingActivationKey ) return UNKNOWN ;
std :: string st = existingActivationKey ;
int result = ( * Handle ) -> ValidateLicense ( licenseKey , registrationName , st );
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( activationKey , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * activationKey ) -> cnt = size ;
memcpy (( * activationKey ) -> str , st . c_str (), size );
return result ;
}
else return UNKNOWN ;
}
else return INVALID_LICENSE_KEY ;
}
catch (...) {
return UNKNOWN ;
}
}
extern "C" __declspec ( dllexport ) int ActivateLicense ( ANSCENTER :: ANSLSHelper * * Handle , const char * licenseKey , const char * registrationName , LStrHandle activationKey ) { // Always activate the license (need internet connection)
try {
if ( ! Handle || ! ( * Handle ) || ! licenseKey || ! registrationName ) return UNKNOWN ;
std :: string st = "" ;
int result = ( * Handle ) -> ActivateLicense ( licenseKey , registrationName , st );
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( activationKey , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * activationKey ) -> cnt = size ;
memcpy (( * activationKey ) -> str , st . c_str (), size );
return result ;
}
else return UNKNOWN ;
}
else return INVALID_LICENSE_KEY ;
}
catch (...) {
return UNKNOWN ;
}
}
extern "C" __declspec ( dllexport ) int ActivateLicenseWithCustomHWID ( ANSCENTER :: ANSLSHelper * * Handle , const char * licenseKey , const char * registrationName , const char * hardwareId , LStrHandle activationKey ) {
try {
if ( ! Handle || ! ( * Handle ) || ! licenseKey || ! registrationName || ! hardwareId ) return UNKNOWN ;
std :: string st ;
int result = ( * Handle ) -> ActivateLicenseWithCustomHWID ( licenseKey , registrationName , hardwareId , st );
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( activationKey , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * activationKey ) -> cnt = size ;
memcpy (( * activationKey ) -> str , st . c_str (), size );
return result ;
}
else return UNKNOWN ;
}
else return INVALID_LICENSE_KEY ;
}
catch (...) {
return UNKNOWN ;
}
} // Always activate the license (need internet connection)
extern "C" __declspec ( dllexport ) int IsLicenseKeyValid ( ANSCENTER :: ANSLSHelper ** Handle , const char * licenseKey , const char * registrationName ) { // Only check the license key with registration name and expiration date only. This is used when developer to use internal APIs called
try {
if ( ! Handle || ! ( * Handle ) || ! licenseKey || ! registrationName ) return 0 ;
bool result = ( * Handle ) -> IsLicenseKeyValid ( licenseKey , registrationName );
if ( result ) return 1 ;
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int GenerateOfflineActivationData ( ANSCENTER :: ANSLSHelper * * Handle , const char * licenseKey , const char * registrationName , LStrHandle offlineActivationData ) {
try {
if ( ! Handle || ! ( * Handle ) || ! licenseKey || ! registrationName ) return 0 ;
std :: string st = "" ;
int result = ( * Handle ) -> GenerateOfflineActivationData ( licenseKey , registrationName , st );
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( offlineActivationData , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * offlineActivationData ) -> cnt = size ;
memcpy (( * offlineActivationData ) -> str , st . c_str (), size );
return 1 ;
}
else return 0 ;
}
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int InstallOfflineLicense ( ANSCENTER :: ANSLSHelper * * Handle , const char * licenseKey , const char * registrationName , const char * activationKey ) {
try {
if ( ! Handle || ! ( * Handle ) || ! licenseKey || ! registrationName || ! activationKey ) return 0 ;
return ( * Handle ) -> InstallOfflineLicense ( licenseKey , registrationName , activationKey );
}
catch (...) {
return 0 ;
}
}
//Utilities
extern "C" __declspec ( dllexport ) int ExtractModelZipFile ( const char * modelZipFile , const char * password , const char * modelName , LStrHandle extractedOutputFolder ) {
try {
std :: string st = "" ;
int result = ANSCENTER :: ANSLSHelper :: ExtractModelZipFile ( modelZipFile , password , modelName , st );
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( extractedOutputFolder , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * extractedOutputFolder ) -> cnt = size ;
memcpy (( * extractedOutputFolder ) -> str , st . c_str (), size );
return 1 ;
}
}
return result ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int ZipFolderToZipFile ( const char * modelFolderSource , const char * modelZipFileDes , const char * password ) {
try {
std :: string stPass = password ;
if ( stPass . empty ()) password = "Sh7O7nUe7vJ/417W0gWX+dSdfcP9hUqtf/fEqJGqxYL3PedvHubJag==" ;
bool result = ANSCENTER :: ANSLSHelper :: ZipFolerWithPassword ( modelFolderSource , modelZipFileDes , password );
if ( result == true ) return 1 ;
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int PrepareEdgeModel ( const char * modelZipFile , const char * zipFilePassword , const char * edgePassword , const char * modelName , const char * edgeSerialNumber , LStrHandle pathArray ) {
try {
std :: string st_configFilePathName = "" ;
std :: string st_labelMapPathName = "" ;
std :: string st_zipFilePathName = "" ;
int result = ANSCENTER :: ANSLSHelper :: PrepareEdgeModel ( modelZipFile , zipFilePassword , edgePassword , modelName , edgeSerialNumber , st_configFilePathName , st_labelMapPathName , st_zipFilePathName );
std :: string st = st_configFilePathName + ";" + st_labelMapPathName + ";" + st_zipFilePathName ;
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( pathArray , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * pathArray ) -> cnt = size ;
memcpy (( * pathArray ) -> str , st . c_str (), size );
return 1 ;
}
}
return result ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int GetSystemHardwareInformation ( LStrHandle systemHardwareInformation ) {
try {
std :: string st = ANSCENTER :: ANSLSHelper :: GetSystemHardwareInformation ();
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( systemHardwareInformation , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * systemHardwareInformation ) -> cnt = size ;
memcpy (( * systemHardwareInformation ) -> str , st . c_str (), size );
return 1 ;
}
else return 0 ;
}
else return 0 ;
}
catch (...) {
return 0 ;
}
}
2026-05-09 16:47:46 +10:00
// SystemHealthParameters cluster, decomposed into individual scalar outputs so
// LabVIEW can wire each indicator straight to a Call Library Function Node.
// Any pointer may be nullptr (LabVIEW will pass nullptr for cluster fields the
// caller hasn't bound). cpuModel is optional but recommended; pass an LStrHandle
// or nullptr to skip. Returns 1 on success, 0 on hard failure.
extern "C" __declspec ( dllexport ) int GetSystemHealthParameters (
double * cpuLoadPercent ,
double * cpuTempDegC ,
double * cpuFreqGHz ,
LStrHandle cpuModel ,
double * memTotalGB ,
double * rssPercent ,
double * swapPercent ,
double * gpuLoadPercent ,
int64_t * valIRSS_MB ,
int64_t * valSwap_MB ,
int64_t * valIGPU_MB ,
double * memoryUsedGB ,
double * memoryFreeGB ,
double * diskLoadPercent ,
double * diskReadSpeedMBs ,
double * diskWriteSpeedMBs ,
double * diskUsedGB ,
double * diskTotalGB ,
double * netLoadPercent ,
double * netReceiveSpeedMBs ,
double * netSendSpeedMBs ,
LStrHandle gpuName ,
2026-05-09 20:57:13 +10:00
LStrHandle gpuAdaptersDetail ,
double * cpuUtilizationPercent )
2026-05-09 16:47:46 +10:00
{
try {
const ANSCENTER :: SystemHealthInfo info =
ANSCENTER :: ANSLicenseHelper :: GetSystemHealthInformation ();
auto writeLStr = []( LStrHandle handle , const std :: string & s ) {
if ( ! handle ) return ;
const int size = static_cast < int > ( s . length ());
const MgErr err = DSSetHandleSize ( handle , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( err == noErr ) {
( * handle ) -> cnt = size ;
if ( size > 0 ) memcpy (( * handle ) -> str , s . c_str (), size );
}
};
2026-05-09 20:57:13 +10:00
if ( cpuLoadPercent ) * cpuLoadPercent = info . cpuLoadPercent ;
if ( cpuTempDegC ) * cpuTempDegC = info . cpuTempDegC ;
if ( cpuUtilizationPercent ) * cpuUtilizationPercent = info . cpuUtilizationPercent ;
2026-05-09 16:47:46 +10:00
if ( cpuFreqGHz ) * cpuFreqGHz = info . cpuFreqGHz ;
if ( memTotalGB ) * memTotalGB = info . memTotalGB ;
if ( rssPercent ) * rssPercent = info . rssPercent ;
if ( swapPercent ) * swapPercent = info . swapPercent ;
if ( gpuLoadPercent ) * gpuLoadPercent = info . gpuLoadPercent ;
if ( valIRSS_MB ) * valIRSS_MB = info . valIRSS_MB ;
if ( valSwap_MB ) * valSwap_MB = info . valSwap_MB ;
if ( valIGPU_MB ) * valIGPU_MB = info . valIGPU_MB ;
if ( memoryUsedGB ) * memoryUsedGB = info . memoryUsedGB ;
if ( memoryFreeGB ) * memoryFreeGB = info . memoryFreeGB ;
if ( diskLoadPercent ) * diskLoadPercent = info . diskLoadPercent ;
if ( diskReadSpeedMBs ) * diskReadSpeedMBs = info . diskReadSpeedMBs ;
if ( diskWriteSpeedMBs ) * diskWriteSpeedMBs = info . diskWriteSpeedMBs ;
if ( diskUsedGB ) * diskUsedGB = info . diskUsedGB ;
if ( diskTotalGB ) * diskTotalGB = info . diskTotalGB ;
if ( netLoadPercent ) * netLoadPercent = info . netLoadPercent ;
if ( netReceiveSpeedMBs ) * netReceiveSpeedMBs = info . netReceiveSpeedMBs ;
if ( netSendSpeedMBs ) * netSendSpeedMBs = info . netSendSpeedMBs ;
writeLStr ( cpuModel , info . cpuModel );
writeLStr ( gpuName , info . gpuName );
writeLStr ( gpuAdaptersDetail , info . gpuAdaptersDetail );
return 1 ;
} catch (...) {
return 0 ;
}
}
2026-05-09 21:55:01 +10:00
extern "C" __declspec ( dllexport ) int GetPublicIPAddress ( LStrHandle ipv4 ) {
try {
if ( ! ipv4 ) return 0 ;
const std :: string s = ANSCENTER :: ANSLicenseHelper :: GetPublicIPAddress ();
const int size = static_cast < int > ( s . length ());
const MgErr err = DSSetHandleSize ( ipv4 , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( err != noErr ) return 0 ;
( * ipv4 ) -> cnt = size ;
if ( size > 0 ) memcpy (( * ipv4 ) -> str , s . c_str (), size );
return s . empty () ? 0 : 1 ;
} catch (...) {
return 0 ;
}
}
namespace {
inline void WriteLStr ( LStrHandle h , const std :: string & s ) {
if ( ! h ) return ;
const int size = static_cast < int > ( s . length ());
const MgErr err = DSSetHandleSize ( h , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( err == noErr ) {
( * h ) -> cnt = size ;
if ( size > 0 ) memcpy (( * h ) -> str , s . c_str (), size );
}
}
}
extern "C" __declspec ( dllexport ) int GetPublicNetworkParameters (
LStrHandle publicIP ,
LStrHandle country ,
LStrHandle countryCode ,
LStrHandle region ,
LStrHandle city ,
LStrHandle isp ,
LStrHandle timeZone ,
double * latitude ,
double * longitude ,
LStrHandle errorMsg )
{
try {
const ANSCENTER :: PublicNetworkInfo info =
ANSCENTER :: ANSLicenseHelper :: GetPublicNetworkInformation ();
WriteLStr ( publicIP , info . publicIP );
WriteLStr ( country , info . country );
WriteLStr ( countryCode , info . countryCode );
WriteLStr ( region , info . region );
WriteLStr ( city , info . city );
WriteLStr ( isp , info . isp );
WriteLStr ( timeZone , info . timezone );
WriteLStr ( errorMsg , info . error );
if ( latitude ) * latitude = info . latitude ;
if ( longitude ) * longitude = info . longitude ;
return info . ok ? 1 : 0 ;
} catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int GetPublicNetworkParametersString ( LStrHandle outString ) {
try {
if ( ! outString ) return 0 ;
const ANSCENTER :: PublicNetworkInfo info =
ANSCENTER :: ANSLicenseHelper :: GetPublicNetworkInformation ();
auto sanitize = []( std :: string s ) {
std :: replace ( s . begin (), s . end (), ';' , ',' );
return s ;
};
std :: ostringstream os ;
os . imbue ( std :: locale :: classic ());
os << std :: fixed << std :: setprecision ( 6 );
os << sanitize ( info . publicIP ) << ';'
<< sanitize ( info . country ) << ';'
<< sanitize ( info . countryCode ) << ';'
<< sanitize ( info . region ) << ';'
<< sanitize ( info . city ) << ';'
<< sanitize ( info . isp ) << ';'
<< sanitize ( info . timezone ) << ';'
<< info . latitude << ';'
<< info . longitude ;
const std :: string s = os . str ();
const int size = static_cast < int > ( s . length ());
const MgErr err = DSSetHandleSize ( outString , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( err != noErr ) return 0 ;
( * outString ) -> cnt = size ;
if ( size > 0 ) memcpy (( * outString ) -> str , s . c_str (), size );
return info . ok ? 1 : 0 ;
} catch (...) {
return 0 ;
}
}
2026-05-09 16:47:46 +10:00
extern "C" __declspec ( dllexport ) int GetSystemHealthParametersString ( LStrHandle outString ) {
try {
if ( ! outString ) return 0 ;
const ANSCENTER :: SystemHealthInfo info =
ANSCENTER :: ANSLicenseHelper :: GetSystemHealthInformation ();
// Keep ';' as a clean separator: rewrite any literal ';' inside any
// free-form string field (rare, but vendor strings aren't safe by
// contract).
auto sanitize = []( std :: string s ) {
std :: replace ( s . begin (), s . end (), ';' , ',' );
return s ;
};
const std :: string model = sanitize ( info . cpuModel );
const std :: string gpuName_ = sanitize ( info . gpuName );
const std :: string gpuDetail = sanitize ( info . gpuAdaptersDetail );
std :: ostringstream os ;
os . imbue ( std :: locale :: classic ()); // force '.' decimal regardless of system locale
os << std :: fixed << std :: setprecision ( 2 );
os << info . cpuLoadPercent << ';'
<< info . cpuTempDegC << ';'
<< info . cpuFreqGHz << ';'
<< model << ';'
<< info . memTotalGB << ';'
<< info . rssPercent << ';'
<< info . swapPercent << ';'
<< info . gpuLoadPercent << ';'
<< info . valIRSS_MB << ';'
<< info . valSwap_MB << ';'
<< info . valIGPU_MB << ';'
<< info . memoryUsedGB << ';'
<< info . memoryFreeGB << ';'
<< info . diskLoadPercent << ';'
<< info . diskReadSpeedMBs << ';'
<< info . diskWriteSpeedMBs << ';'
<< info . diskUsedGB << ';'
<< info . diskTotalGB << ';'
2026-05-09 20:57:13 +10:00
<< info . netLoadPercent << ';'
<< info . netReceiveSpeedMBs << ';'
<< info . netSendSpeedMBs << ';'
<< gpuName_ << ';'
<< gpuDetail << ';'
<< info . cpuUtilizationPercent ;
2026-05-09 16:47:46 +10:00
const std :: string s = os . str ();
const int size = static_cast < int > ( s . length ());
const MgErr err = DSSetHandleSize ( outString , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( err != noErr ) return 0 ;
( * outString ) -> cnt = size ;
if ( size > 0 ) memcpy (( * outString ) -> str , s . c_str (), size );
return 1 ;
} catch (...) {
return 0 ;
}
}
2026-03-28 16:54:11 +11:00
extern "C" __declspec ( dllexport ) int ReleaseLoggers () {
try {
bool result = ANSCENTER :: ANSLSHelper :: ReleaseLogger ();
if ( result ) return 1 ;
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int ListANSLicenses ( std :: string & listLicense ) {
try {
listLicense = ANSCENTER :: ANSLicenseHelper :: ListLicenses ();
if ( ! listLicense . empty ()) return 1 ;
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int ListANSLicenses_LV ( LStrHandle ansProductLicenses ) {
try {
std :: string st = ANSCENTER :: ANSLicenseHelper :: ListLicenses ();
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( ansProductLicenses , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * ansProductLicenses ) -> cnt = size ;
memcpy (( * ansProductLicenses ) -> str , st . c_str (), size );
return 1 ;
}
else return 0 ;
}
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int ActivateTrialLicense ( const char * productName ) {
return ANSCENTER :: ANSLicenseHelper :: ActivateTrialLicense ( productName );
}
extern "C" __declspec ( dllexport ) int DeactivateLicense ( const char * productName ) {
return ANSCENTER :: ANSLicenseHelper :: DeactivateLicense ( productName );
}
extern "C" __declspec ( dllexport ) int ActivateProductLicense ( const char * productName , const char * licenseKey ) {
return ANSCENTER :: ANSLicenseHelper :: ActivateLicense ( productName , licenseKey );
}
extern "C" __declspec ( dllexport ) int ActivateProductLicenseWithCustomHWID ( const char * productName , const char * licenseKey , const char * hwid , LStrHandle lvActivationKey ) {
try {
std :: string st ;
int result = ANSCENTER :: ANSLicenseHelper :: ActivateLicenseWithCustomHWID ( productName , licenseKey , hwid , st );
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( lvActivationKey , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * lvActivationKey ) -> cnt = size ;
memcpy (( * lvActivationKey ) -> str , st . c_str (), size );
return result ;
}
else return LicenseKeyStatus :: UNKNOWN ;
}
else return LicenseKeyStatus :: INVALID_LICENSE_KEY ;
}
catch (...) {
return LicenseKeyStatus :: UNKNOWN ;
}
}
extern "C" __declspec ( dllexport ) int GetRegistrationName ( const char * validationData , LStrHandle registrationName ) {
try {
std :: string st = ANSCENTER :: ANSLicenseHelper :: DecodeValidationData ( validationData );
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( registrationName , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * registrationName ) -> cnt = size ;
memcpy (( * registrationName ) -> str , st . c_str (), size );
return 1 ;
}
else return 0 ;
}
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int GenerateActivationKeyData ( const char * activationKey , const char * licenseKey , const char * hardwareId , const char * validationData , LStrHandle activationData ) {
try {
std :: string st = ANSCENTER :: ANSLicenseHelper :: GenerateActivationDataFile ( activationKey , licenseKey , hardwareId , validationData );
int size = ( int ) st . length ();
if ( size > 0 ) {
MgErr error ;
error = DSSetHandleSize ( activationData , sizeof ( int32 ) + size * sizeof ( uChar ));
if ( error == noErr )
{
( * activationData ) -> cnt = size ;
memcpy (( * activationData ) -> str , st . c_str (), size );
return 1 ;
}
else return 0 ;
}
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int ANSLicenseVerification ( const char * licenseKey , int productId , const char * registrationName ) {
try {
bool result = ANSCENTER :: ANSLicenseHelper :: LicenseVerification ( licenseKey , productId , registrationName );
if ( result ) return 1 ;
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int ANSModelConversion ( const char * zipModelFile , const char * zipModelPassword ) {
try {
//1. Uzip the model file to a temp location
std :: string parentFolder = GetParentFolder ( zipModelFile );
if ( parentFolder . empty ()) {
return - 1 ; // or handle error appropriately
}
std :: string modelName = GetFileNameWithoutExtension ( zipModelFile ) + "_converted" ;
const std :: string outputFolder = GenerateOutputFolder ( zipModelFile , modelName , true );
if ( ! FolderExist ( outputFolder )) fs :: create_directory ( outputFolder );
bool extractedResult = ExtractProtectedZipFile ( zipModelFile , zipModelPassword , modelName , outputFolder );
if ( ! extractedResult ) return 0 ;
//2. Zip the model file to a temp location
std :: string newModelZipFile = CreateFilePath ( parentFolder , modelName + ".zip" );
std :: string newModelZipPassword = "Sh7O7nUe7vJ/417W0gWX+dSdfcP9hUqtf/fEqJGqxYL3PedvHubJag==" ;
//3. Read names of classes from the label map file
std :: string labelMapFile = CreateFilePath ( outputFolder , "classes.names" );
if ( labelMapFile . empty ()) return 0 ;
std :: vector < std :: string > classesNames = Split ( ReadFileContent ( labelMapFile ), " \n " );
// 4. Create Categories folder
std :: string categoriesFolder = outputFolder + " \\ Categories" ;
if ( FolderExist ( categoriesFolder )) DeleteFolder ( categoriesFolder );
fs :: create_directory ( categoriesFolder );
for ( size_t i = 0 ; i < classesNames . size (); ++ i ) {
std :: ofstream outFile ( categoriesFolder + "/" + classesNames [ i ] + "." + std :: to_string ( i + 1 ));
outFile . close ();
}
bool zipResult = ZipFolderWithPassword ( outputFolder . c_str (), newModelZipFile . c_str (), newModelZipPassword . c_str ());
if ( zipResult ) {
DeleteFolder ( outputFolder );
return 1 ;
}
else return 0 ;
}
catch (...) {
return 0 ;
}
}
extern "C" __declspec ( dllexport ) int DeletePathRecursively ( const char * pathTobeDeleted ) {
try {
bool result = ANSCENTER :: ANSLicenseHelper :: DeleleteRecursively ( pathTobeDeleted );
if ( result ) return 1 ;
else return 0 ;
}
catch (...) {
return 0 ;
}
}