CEN/XFS: Why is wAntiFraudModule giving me these values? - c++

Why am I get this crazy high value in the field member of LPWFSIDCSTATUS? Does this mean that the ATM does not have an anti-fraud module? Am I missing anything?
Field values such as fwDevice or fwMedia produce the correct values, so I'm not sure why wAntiFraudModule or wDevicePosition is behaving this way.
Using visual studio debugger
Here's a code segment of what I've got going on.
LPWFSRESULT lpResult = NULL;
LPWFSPTRSTATUS lpStatus = NULL;
HRESULT result = WFMAllocateBuffer(sizeof(WFSPTRSTATUS), WFS_MEM_ZEROINIT | WFS_MEM_SHARE, (void**)&lpResult);
if (result != WFS_SUCCESS)
std::cout << "FAILED TO ALLOCATE\n";
dev_status = WFSGetInfo(XFS::GetServiceInstance(), WFS_INF_PTR_STATUS, NULL, 40000, &lpResult);
if (dev_status != WFS_SUCCESS)
std::cout << "Failed to get status for printer\n";
lpStatus = (LPWFSPTRSTATUS)lpResult->lpBuffer;
WORD my_fraud = lpStatus->wAntiFraudModule;
std::cout << "Anti-Fraud status: " << my_fraud << std::endl;
WFSFreeResult(lpResult);

Related

Handle PostgreSQL transaction errors in GDALVectorTranslate

In c++ I'm using the GDAL library for importing geo-spatial files into Postgres/PostGIS.
The GDAL library will create a table in the Postgres database and insert the data. But I can't figure out how to handle errors during the inserting of data.
I'm using GDALVectorTranslate https://gdal.org/api/gdal_utils.html#gdal__utils_8h_1aa176ae667bc857ab9c6016dbe62166eb
If an Postgres error occurs the error text will be outputted and the program continues to run. I would like to handle these Postgres errors.
An error could be:
ERROR 1: INSERT command for new feature failed.
ERROR: invalid byte sequence for encoding "UTF8": 0xe5 0x20 0x46
For now I let my program count the rows in the destination table and if zero then assume error. But that doesn't work if appending to an existing table.
auto *dst = (GDALDataset *) GDALVectorTranslate(nullptr, pgDs, 1, &sourceDs, opt, &bUsageError);
if (dst == nullptr) {
std::cout << "ERROR! Couldn't create table" << std::endl;
return FALSE;
} else {
OGRLayer *layer = dst->GetLayerByName(altName);
// Here the rows are counted
if (layer->GetFeatureCount() == 0) {
std::cout << "ERROR! Insert failed" << std::endl;
return FALSE;
}
std::cout << " Imported";
return TRUE;
}
You can register your own error handler to log and count the underlying errors:
struct {/*members for handling errors*/} ctx;
static void myErrorHandler(CPLErr e, CPLErrorNum n, const char* msg) {
ctx *myctx = (ctx*)CPLGetErrorHandlerUserData();
/* do something with ctx to log and increment error count */
}
int myTranslateFunc() {
ctx myctx; //+initialization
CPLPushErrorHandlerEx(&myErrorHandler,&myctx);
auto *dst = (GDALDataset *) GDALVectorTranslate(nullptr, pgDs, 1, &sourceDs, opt, &bUsageError);
CPLPopErrorHandler();
//inspect myctx for potential errors
}

vkCreateSwapchainKHR Error

Even though validation layers and debug callback extensions are enabled and working (they respond to wrong structs etc.), I'm still getting a "VK_ERROR_VALIDATION_FAILED_EXT" result from vkCreateSwapchainKHR(), and there's no validation layer error to pinpoint the mistake...
Swap chain creation (using GTX 970 ) :
VkBool32 isSupported = false;
vkGetPhysicalDeviceSurfaceSupportKHR( physicalDevices[0], 0, surface, &isSupported);
if (!isSupported) {
std::cout << "*ERROR* This device doesn't support surfaces" << std::endl;
}
VkSurfaceCapabilitiesKHR surfCaps;
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevices[0], surface, &surfCaps);
std::vector<VkSurfaceFormatKHR> deviceFormats;
uint32_t formatCount;
vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevices[0], surface, &formatCount, nullptr);
deviceFormats.resize(formatCount);
vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevices[0], surface, &formatCount, deviceFormats.data());
swapChainInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
swapChainInfo.pNext = nullptr;
swapChainInfo.flags = 0;
swapChainInfo.surface = surface;
swapChainInfo.minImageCount = surfCaps.minImageCount;
swapChainInfo.imageFormat = VK_FORMAT_B8G8R8A8_UNORM;
swapChainInfo.imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
swapChainInfo.imageExtent = surfCaps.currentExtent;
swapChainInfo.imageArrayLayers = 1;
swapChainInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
swapChainInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
swapChainInfo.queueFamilyIndexCount = 0;
swapChainInfo.pQueueFamilyIndices = VK_NULL_HANDLE;
swapChainInfo.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
swapChainInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
swapChainInfo.presentMode = VK_PRESENT_MODE_FIFO_KHR;
swapChainInfo.clipped = VK_TRUE; // TODO : TEST clipping against another window
swapChainInfo.oldSwapchain = VK_NULL_HANDLE;
result = vkCreateSwapchainKHR( device, &swapChainInfo, nullptr, &swapChain );
if (result) {
std::cout << "*ERROR* Swapchain Creation Failed :" << result << std::endl;
}
Surface Creation using GLFW (Which doesn't return any error):
if (result = glfwCreateWindowSurface(instance, window, nullptr, &surface))
{
std::cout << "*ERROR* Surface Creation Failed : " << result << std::endl;
}
There are a huge number of reasons validation of vkCreateSwapchainKHR will fail (check out PreCallValidateCreateSwapchainKHR in core_validation.cpp).
There may not be enough code here to tell why it is failing, for example, the failure might be because of an invalid surface. But, to pinpoint the problem, it should give a failure message in the debug log, which will tell you exactly why. You should enable it by calling CreateDebugReportCallbackEXT, before trying to create the swapchain. This will also require you to enable the VK_EXT_debug_report extension. See here for details.
Just a few points about your code (potentially cause of problems):
You are not checking VkResult of all the vkGet* commands
You are not checking swapChainInfo.imageFormat against supported formats in your deviceFormats
You are not accounting for the situation that surfCaps.currentExtent can be 0xFFFFFFFF
swapChainInfo.pQueueFamilyIndices is a pointer not a handle; use nullptr
You are not checking swapChainInfo.preTransform against surfCaps.supportedTransforms
You are not checking swapChainInfo.compositeAlpha against surfCaps.supportedCompositeAlpha

WMI strange values

I want to detect the RAM manufacturer in WMI. The problem that I get strange symbols instead of actual data. Also I have checked it using wmic command. Screenshots are listed below.
Screenshots:
I have tried different approaches to check value before output, but the problem is still present.
Code:
VARIANT ramManufacturer;
pclsObj->Get(L"Manufacturer", 0, &ramManufacturer, 0, 0);
QString userRAMManufacturer;
QStringList ramProperty;
QStringList ramData;
if (SysStringLen(ramManufacturer.bstrVal) != 0) {
userRAMManufacturer = QString::fromWCharArray(ramManufacturer.bstrVal);
if (!userRAMManufacturer.isEmpty()) {
ramProperty << QObject::tr("Manufacturer");
ramData << userRAMManufacturer;
}
}
Or
if (CComBSTR(ramManufacturer.bstrVal).Length() != 0) {
userRAMManufacturer = QString::fromWCharArray(ramManufacturer.bstrVal);
if (!userRAMManufacturer.isEmpty()) {
ramProperty << QObject::tr("Manufacturer");
ramData << userRAMManufacturer;
}
}
How to fix this issue? Thanks in advance.
#selbie
Thank you. I have checked for Get value and now the values are correct.
Code:
if (ramManufacturer.vt != VT_NULL && ramManufacturer.vt == VT_BSTR) {
userRAMManufacturer = QString::fromWCharArray(ramManufacturer.bstrVal);
ramProperty << QObject::tr("Manufacturer");
ramData << userRAMManufacturer;
}

SQLite3 Multiple Inserts with Paramaters; Only One Record Inserted

I am attempting to make my saving code more efficient through the use of re-using the prepared statement, the use of transactions, and parametrized queries. However whenever I run the save code only one record ends up in my table. I think it has to do with where the sqlite3_step is placed.
But I also want some other eyes to look over my code and let me know if I am doing things correctly; I could not find an example doing this anywhere so it is a jumble of about six forums posts and Stack Overflow topics I found on the various subjects:
//Planet Data
//Delete previous save data
dData("Generated_Planets", bErrors);
if (plData.size() > 0)
{
sqlite3_exec(dBase, "BEGIN TRANSACTION", NULL, NULL, &error);
sqlStr = "Insert Into Generated_Planets (ID, Name, Affiliation, Disposition, Race, Player_Owned, Is_Destroyed, EKS, Planet_Size, Current_Pop, Max_Pop) Values (?,?,?,?,?,?,?,?,?,?,?);";
if (sqlite3_prepare_v2(dBase, sqlStr.c_str(), sqlStr.size(), &statement, 0) == SQLITE_OK)
{
cout << "Saving planet data";
//Save new data
for (i = 0; i <= plData.size(); i++)
{
if (i == plData.size())
{
finalize(statement, bErrors);
}
else
{
sqlI1 = plData.at(i).pID;
sqlS1 = plData.at(i).pName;
sqlS2 = plData.at(i).pAffiliation;
sqlS3 = plData.at(i).pDispo;
sqlS4 = plData.at(i).pRace;
sqlI2 = plData.at(i).bIsPOwned;
sqlI3 = plData.at(i).bIsDestroyed;
sqlF1 = plData.at(i).pEKS;
sqlF2 = plData.at(i).pSize;
sqlLLI1 = plData.at(i).pCPop;
sqlLLI2 = plData.at(i).pMPop;
find = "'";
temp = "\"";
foundAt = sqlS1.find(find);
if (foundAt != string::npos)
{
sqlS1.replace(foundAt,1,temp);
}
//Bind parameters
sqlite3_bind_int(statement,1,sqlI1);
sqlite3_bind_text(statement,2,sqlS1.c_str(),sqlS1.size(),SQLITE_TRANSIENT);
sqlite3_bind_text(statement,3,sqlS2.c_str(),sqlS2.size(),SQLITE_TRANSIENT);
sqlite3_bind_text(statement,4,sqlS3.c_str(),sqlS3.size(),SQLITE_TRANSIENT);
sqlite3_bind_text(statement,5,sqlS4.c_str(),sqlS4.size(),SQLITE_TRANSIENT);
sqlite3_bind_int(statement,6,sqlI2);
sqlite3_bind_int(statement,7,sqlI3);
sqlite3_bind_double(statement,8,sqlF1);
sqlite3_bind_double(statement,9,sqlF2);
sqlite3_bind_int64(statement,10,sqlLLI1);
sqlite3_bind_int64(statement,11,sqlLLI2);
sqlite3_step(statement);
cout << ".";
}
}
}
else
{
*bErrors = true;
createBInfo();
d.createBReport("SQL Code 2",sqlite3_errmsg(dBase),bLocale + to_string(__LINE__),bTDate,"./SC_Log.txt");
}
sqlite3_exec(dBase, "END TRANSACTION", NULL, NULL, &error);
sFlags_Temp.push_back(saveFlag());
sFlags_Temp.at(sFlags_Temp.size()-1).sfName = "GPlanets";
sFlags_Temp.at(sFlags_Temp.size()-1).sfValue = 1;
cout << "Done" << endl << endl;
}
It looks like you're missing a call to sqlite3_reset after sqlite3_step and before binding the next set of parameters. And you're ignoring the return codes that would have told you about it.
See the documentation for sqlite3_step here: http://sqlite.org/c3ref/step.html

With C++ can you return a sqlite3_stmt from a method?

I'm trying to reduce duplicate sqlite code in my object. To do so I wanted one method that had the sqlite interaction and just return a sqlite3_stmt. My problem is that the sqlite3_stmt pointer is always null. My question is, am I doing something wrong or can this not be done with sqlite?
Usage:
SqliteIO sqldb;
string GET_CONFIG = "select* from config; ";
sqlite3_stmt *statement;
assert(sqldb.sqlForResults(GET_CONFIG, statement));
assert(statement != NULL); //this fails
Method:
bool SqliteIO::sqlForResults(string pSql, sqlite3_stmt *statement ){
bool lbRetVal=false;
if(mDB == NULL){
cerr << "No database to query";
Logger::error("SqlliteIO::getAllScheuled() null database handle");
} else {
sqlite3_busy_timeout(mDB, 2000);
if(sqlite3_prepare_v2(mDB, pSql.c_str(), -1, &statement, 0) == SQLITE_OK) {
lbRetVal = true;
}
string error = sqlite3_errmsg(mDB);
if(error != "not an error"){
cerr << pSql << " " << error << endl;
Logger::error("SqlliteIO::sqlForResults() "+ error + " " +pSql );
}
}
return lbRetVal;
sqlite3_stmt *statement; // this never gets initialized
assert(sqldb.sqlForResults(GET_CONFIG, statement));
assert(statement != NULL); //this fails
the statement variable in that block of code never gets initialized (you're passing a copy of it to sqlForResults()).
frankly, you're lucky that assertion is failing, as statement could have any garbage value (I'm guessing variables are zero-initialized in debug mode for your compiler)
The statement parameter of SqliteIO::sqlForResults() needs to have the type sqlite3_stmt**, not sqlite3_stmt*. So the call site would now look like:
SqliteIO sqldb;
string GET_CONFIG = "select* from config; ";
sqlite3_stmt *statement = NULL;
assert(sqldb.sqlForResults(GET_CONFIG, &statement));
Without the reference/address-of operator & before statement (like in the original question), you would be passing the value of statement to sqlForResults, which was NULL or 0 in this case. The relevant changes in sqlForResults are:
bool SqliteIO::sqlForResults(string pSql, sqlite3_stmt **statement ){
bool lbRetVal=false;
if(mDB == NULL){
// ...
} else {
// ...
if(sqlite3_prepare_v2(mDB, pSql.c_str(), -1, statement, 0) == SQLITE_OK) {
// ...
}
// ...
}
return lbRetVal;
The parameter list now accepts a sqlite_stmt** arg, and we pass that directly to sqlite3_prepare_v2. In the original question, sqlForResults passed &statement to sqlite3_prepare_v2 - which is the address of the statement parameter for this SqliteIO::sqlForResults method call - which isn't what you want.
I know this is an old question, but I hope this helps.
EDIT: for clarity and to elude some more code from sqlForResults