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;
}
Related
I have the following code, and can be compiled, but when I run it, it fails with error of missing resource.
I have checked the cascade installer and everything is clicked and installed. How could I fix this?
#include <TDocStd_Application.hxx>
#include <TDataStd_Integer.hxx>
int main()
{
Handle(TDocStd_Application) app = new TDocStd_Application;
Handle(TDocStd_Document) doc;
app->NewDocument("BinOcaf", doc);
if (doc.IsNull())
{
std::cout << "Error: cannot create an OCAF document." << std::endl;
return 1;
}
// to access the main label, the transient data framework
TDF_Label mainLab = doc->Main();
// attach some integer value to this label
TDataStd_Integer::Set(mainLab, 1002);
// save document to file
PCDM_StoreStatus sstatus = app->SaveAs(doc, "C:/Users/Administrator/Desktop/test.cbf");
if (sstatus != PCDM_SS_OK)
{
app->Close(doc);
std::cout << "cannot write OCAF document." << std::endl;
return 1;
}
// release the data of doc
app->Close(doc);
return 0;
}
Ok, so after some head scratching I realized one thing. Forgot to define format.
just add the line of code to the main function would fix the problem.
BinDrivers::DefineFormate(app);
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);
I am working on a small game and came across a big problem with lists.
Here's my code:
void cCollisionManager::checkCollision(cPlayer * pPlayer, std::list<cAsteroid*> *asteroidList, std::list<cShot*> *ShotList)
{
sf::FloatRect PlayerBox = pPlayer->getSprite()->getGlobalBounds();
for (auto it : *asteroidList) {
for (auto es : *ShotList) {
sf::FloatRect asteroidboundingBox = it->getSprite()->getGlobalBounds();
sf::FloatRect ShotBox = es->getSprite().getGlobalBounds();
if (asteroidboundingBox.intersects(ShotBox)) {
it = asteroidList->erase(it);
*pPlayer->pPunkte += 1;
std::cout << *pPlayer->pPunkte << std::endl;
}
if (asteroidboundingBox.intersects(PlayerBox)) {
if (*pPlayer->phealth >= 0.f)
*pPlayer->phealth -= 0.5f;
}
}
}
}
I used SFML and basically everything works. But if I want to delete the colliding asteroid and the shot, the programs exits with an error. In the if loop I tried to erase the object, but the compiler also gives an error saying that the argument type is not the same as the object type I am giving to it.
EDIT
I had another look at the other question, you recommended to me, but still I haven't found out how to solve that problem. So if I changed my code to a while loop, the game couldn't handle it, because the Collision Manager is actually called in every single Call of the SFML main loop. So it would just get stuck in my collision loop. So I changed my code a bit, but still, things are not working.
Don't modify sequences that are being enumerated with range-for. Use
iterators and the appropriate result of an erase. – WhozCraig
This is actually the answer to it. I did the mistake - using a for loop and not a while loop and so I had some big issues and bad construction ideas for my code - luckily everything now works!
Here is my final code:
auto it = asteroidList->begin();
auto es = ShotList->begin();
while (it != asteroidList->end()) {
sf::FloatRect PlayerBox = pPlayer->getSprite()->getGlobalBounds();
sf::FloatRect asteroidboundingBox = (*it)->getSprite()->getGlobalBounds();
while (es != ShotList->end())
{
sf::FloatRect ShotBox = (*es)->getSprite().getGlobalBounds();
if (asteroidboundingBox.intersects(ShotBox)) {
it = asteroidList->erase(it);
es = ShotList->erase(es);
std::cout << "Asteroid destroyed" << std::endl;
*pPlayer->pPunkte += 1;
std::cout << *pPlayer->pPunkte << std::endl;
}
if (es != ShotList->end())
es++;
}
if (asteroidboundingBox.intersects(PlayerBox))
{
if (*pPlayer->phealth > 3.f) {
*pPlayer->phealth -= 5.f;
it = asteroidList->erase(it);
}
else
*pPlayer->pBStateAlive = false;
}
if (it != asteroidList->end()) {
it++;
es = ShotList->begin();
}
}
}
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
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