Decode text from CDB#
Problem Description#
Decode the loadcase titles from integer values.
Problem Solution#
The C++ project example can be found by following:
C:\<sofistik_installation>\2023\SOFiSTiK 2023\interfaces\examples\c++\number2text
The loadcases information is stored in the record LC_CTRL 012/LC:?
. The loadcase title
is stored into RTEX
array.
@25: RTEX [str*32] |Designation of loadcase | Bezeichnung des Lastfalls
From SP 2020-4 or later, we provide in sof_cdb_w-2023.dll
the
C sof_lib_cs2ps(pckcode*, char*, int)
function for decoding the integer values to text. Where pckcode
is following typedef:
typedef unsigned int pckcode;
See below an example how to use the function via C++:
//+============================================================================+
//| Company: SOFiSTiK AG |
//| Version: SOFiSTIK 2023 |
//+============================================================================+
////////////////////////////////////////////////////////////////////////////////
// ABOUT:
// In this example we will show how to use the sof_lib_ps2cs() function
// sof_lib_ps2cs() converts integer values to string
#include <iostream>
#include <Windows.h>
#include <string>
#include <iomanip>
// Include SOFiSTiK Libraries from :
// --> "... interfaces/examples/c++"
#include "cdbase.h"
#include "cdbtypeall.h"
#include "cdbtypecon.h"
#include "cdbtypegeo.h"
#include "cdbtypelfc.h"
#include "cdbtypemat.h"
#include "cdbtypesct.h"
#include "cdbtypesys.h"
#include "cdbtypeten.h"
using namespace std;
typedef unsigned int pckcode;
typedef void(*PS2CS)(pckcode*, char*, int);
typedef int(*INITPRT)(char*, int);
typedef int(*STATUSPRT)(int);
typedef int(*CLOSEPRT)(int);
typedef int(*GETPRT)(int, int, int, void*, int*, int);
using namespace std;
int main()
{
// Load the library
HINSTANCE hInst = LoadLibrary("S:\\sof\\2023\\exe\\trunk\\_build.fea-gui\\release_with_symbols\\x64\\bin\\sof_cdb_w-2023.dll");
if (!hInst)
{
cout << "Coult not Load the Library" << endl;
system("pause");
return EXIT_FAILURE;
}
// Resolve the function adress
INITPRT sof_cdb_init = (INITPRT)GetProcAddress(hInst, "sof_cdb_init");
if (!sof_cdb_init)
{
cout << "Could not locate the function!" << endl;
system("pause");
return EXIT_FAILURE;
}
STATUSPRT sof_cdb_status = (STATUSPRT)GetProcAddress(hInst, "sof_cdb_status");
if (!sof_cdb_status)
{
cout << "Could not locate the function!" << endl;
system("pause");
return EXIT_FAILURE;
}
PS2CS sof_lib_ps2cs = (PS2CS)GetProcAddress(hInst, "sof_lib_ps2cs");
if (!sof_lib_ps2cs)
{
cout << "Could not locate the function!" << endl;
system("pause");
return EXIT_FAILURE;
}
CLOSEPRT sof_cdb_close = (CLOSEPRT)GetProcAddress(hInst, "sof_cdb_close");
if (!sof_cdb_close)
{
cout << "Could not locate the function!" << endl;
system("pause");
return EXIT_FAILURE;
}
GETPRT sof_cdb_get = (GETPRT)GetProcAddress(hInst, "sof_cdb_get");
if (!sof_cdb_get)
{
cout << "Could not locate the function!" << endl;
return EXIT_FAILURE;
}
// Connect to CDB
/*
Index = 0 initialise CDBASE and open scratch data base only
Index > 0 open an existing data base with exactly tis index
(STATUS=UNKNOWN) = somehow obsolete call, use 99!
Index = 99 test if NAME is a valid database and open the base
if possible. Return with the assigned index.
If the file does not exist, it will be created.
Index = 97 open the database via pvm
Return with the assigned index.
Index = 96 open a scratch database, filename is the path to
use or NULL.
Index = 95 open in read-only mode
Index = 94 create a new data base (STATUS=NEW)
*/
int index = 99;
char* fileName = "S:\\test\\155852\\155852.cdb";
int ie = sof_cdb_init(fileName, index);
if (ie < 0)
{
cout << "ERROR: Index= " << ie << " < 0 - see clib1.h for meaning of error codes" << endl;
cout << "Press any <key> to close the program";
system("pause");
return(0);
}
else if(ie == 0)
{
cout << "ERROR: Index= " << ie << " - The File is not a database" << endl;
cout << "Press any <key> to close the program";
system("pause");
return(0);
}
// Get Status
// int sof_cdb_status (int ie);
cout << "The CDB Status: " << sof_cdb_status(ie) << endl;
int datalen = sizeof(tagCDB_LC_CTRL);
int *datalenptr;
datalenptr = &datalen;
tagCDB_LC_CTRL clc_ctrl;
char s[17*4+1]; // 17 array elements × 4 + include 0
int len = sizeof(s);
// &clc_ctrl pass the address of the struct to pointer
while (sof_cdb_get(ie, 12, 1, &clc_ctrl, &datalen, 1) < 2)
{
sof_lib_ps2cs(clc_ctrl.m_rtex, s, sizeof(s));
cout << s << endl;
datalen = sizeof(clc_ctrl);
}
// Close the CDB
// int sof_cdb_close (int ie);
sof_cdb_close(0);
cout << "The CDB Status after closing: " << sof_cdb_status(ie) << endl;
system("pause");
return 0;
}