|
I'm a bit confused: 0xE97804B9A34AB4E fits in an __int64 with a nibble to spare. I know it depends what your compiler is and __int64 isn't a standard type but if you've got it and it doesn't need to be portable then why not use it?
Ash
PS: I'm normally against using non-portable code but at least someone trying to compile your code for a platform with a 64 bit int would at least be warned something was up.
PPS: And if you need to store it in 32 bit values you can take advantage of some properties of ints that makes it relatively easy to calculate the modulus.
|
|
|
|
|
Hi All
what is difference between thread priority THREAD_PRIORITY_IDLE,THREAD_PRIORITY_NORMAL,THREAD_PRIORITY_HIGHEST.?We are using like this
AfxBeginThread(ThreadName, (LPVOID) this,THREAD_PRIORITY_HIGHEST,0,0);
How can i check it when application is running?
Please help me
|
|
|
|
|
|
Thanks
Through GetThreadPriority i can know application running with which priority(Like NORMAL,IDLE or HIGHEST).
where i can find theoretical difference?
|
|
|
|
|
|
|
Are you asking what thread priority "actually does"? What it means? What it is for?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
Hi all!
Now I am developing an application to read the disk driver's SerialNumber. I want to read it by WMI. The code is as following:
BOOL CData::GetSerialNumber(BYTE* out)
{
BOOL bRet = FALSE;
HRESULT hr;
hr = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hr))
{
cout << "Failed to initialize COM library. Error code = 0x"
<< hex << hr << endl;
return bRet;
}
hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
NULL);
if (FAILED(hr))
{
cout << "Failed to initialize security. Error code = 0x"
<< hex << hr << endl;
CoUninitialize();
return bRet;
}
IWbemLocator *pLoc = 0;
hr = CoCreateInstance(CLSID_WbemLocator, 0,
CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
if (FAILED(hr))
{
cout << "Failed to create IWbemLocator object. Err code = 0x"
<< hex << hr << endl;
CoUninitialize();
return bRet;
}
IWbemServices *pSvc = 0;
hr = pLoc->ConnectServer(
BSTR(L"ROOT\\CIMV2"),
NULL, NULL, 0, NULL, 0, 0, &pSvc);
if (FAILED(hr))
{
cout << "Could not connect. Error code = 0x"
<< hex << hr << endl;
pLoc->Release();
CoUninitialize();
return bRet;
}
cout << "Connected to WMI" << endl;
HRESULT hres;
hres = CoSetProxyBlanket(pSvc,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE
);
if (FAILED(hres))
{
cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return bRet;
}
IEnumWbemClassObject* pObj = 0;
IWbemClassObject* pwcObj = 0;
hres = pSvc->ExecQuery(L"WQL",L"select * from Win32_PhysicalMedia",WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,0,
&pObj);
char strID[20];
VARIANT vtData;
CIMTYPE ctType = 0;
long lFavor = 0;
ULONG ulRet;
if(SUCCEEDED(hres))
{
hres = pObj->Next(WBEM_INFINITE,1,&pwcObj,&ulRet);
if(SUCCEEDED(hres) && pwcObj)
{
ZeroMemory(strID,20);
vtData.pbstrVal = 0;
hres = pwcObj->Get(L"SerialNumber",0,&vtData,&ctType,&lFavor);
if(vtData.pbstrVal)
{
CopyMemory(strID,vtData.pbstrVal,20);
}
VariantClear(&vtData);
pwcObj->Release();
bRet = TRUE;
if(SUCCEEDED(hres) && out)
{
CopyMemory(out,strID,20);
}
}
pObj->Release();
}
pSvc->Release();
pLoc->Release();
CoUninitialize();
return bRet;
}
The variable vtData should contain the SerialNumber of the disk driver. But I am always get a value of NULL in vtData. And the return value from
Get(L"SerialNumber",0,&vtData,&ctType,&lFavor); is success. And I try to get some other data in pwcObj. They are all NULL. I don't know the reason. My disk driver is working well. I can get this number by some other software. I hope someone could be kind to tell me the right way. Thx!
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
Other than strID not being null terminated, your code works fine for me.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hello, i wanted to get an idea of some basic memory editing so i thought writing a simple trainer for my favorite game would be a good idea.
So i found out how to get the pointer, now when i use cheat engine it gives the correct value if i add the baseaddress + offset.
But if i try that in my program it wont work for some reason.
int offset = 0x804;
int address = 0x818794;
int totalhp = offset + address;
int value;
ReadProcessMemory(hProcess, (LPCVOID)totalhp, &value, sizeof(value), NULL );
std::cout << value << std::endl;
value always returns zero for god knows what reason.
Any idea what iam doing wrong?
|
|
|
|
|
How are you initializing hProcess ?
|
|
|
|
|
The problem is not the handle, the problem is the wrong value i get.
HWND hWnd = FindWindow(0, "AOEII");
if(hWnd == 0)
{
std::cout << "Cant find handle." << std::endl;
_getch();
}
else
{
DWORD proccess_ID;
GetWindowThreadProcessId(hWnd, &proccess_ID);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proccess_ID);
if(!hProcess)
{
std::cout << "Cant open process." << std::endl;
_getch();
}
else
{
Readprocessstuff...
|
|
|
|
|
Well found the solution, not exactly sure why i have to do it this way but iam reading about it right now, just thought id post the solution before i forget about it.
int offset = 0x804;
int baseaddress;
int value;
ReadProcessMemory(hProcess, (LPCVOID)0x00818794, (LPVOID)&baseaddress, sizeof(value), NULL );
ReadProcessMemory(hProcess, (LPCVOID)(baseaddress+offset), &value, sizeof(value), NULL );
Thanks for trying to help
|
|
|
|
|
Hello
I want to change the color of text in c(win32 console).
but not entire text only a piece of text that is in the middle.
what can I do?
best regards...
|
|
|
|
|
Look in documents for the console programming API functions. I would but you can do it just as easily as I can and I don't need to.
You can also search for articles on the console here. Most of them use C++ but at least you can see the API functions in action.
|
|
|
|
|
Looks like you're after the SetConsoleTextAttribute[^] function in combination with GetStdHandle[^] with code like this:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED);
Steve
|
|
|
|
|
Hi guys i wrote a program that connects to a DB that is in a LAN, and i have others PCs accessing it, the problems is how do i notify all the programs that are connected to that DB of a change in it?
Or maybe i am not using a good approach can someone help me please?
|
|
|
|
|
You can't reliably notify all interested PCs as some of them could be off-line or powered down. What you can do however is have a special table, row and field that contains say the "generation" number. And each of your applications could:
1. hold a copy of the generation number in a local file;
2. at start-up compare the database generation with the local copy, and when different, act on it.
It isn't clear what you want this for. There may be other and more appropriate ways depending on your goals.
|
|
|
|
|
Thanks Luc.
This program is a stock/selling system for a store. Problem is this i have for example 2 PCs that handle sells and the 3rd one is only watching the storage contents, there can be this issue when some items are not anymore in stock.
The only way is to use a timer then?
|
|
|
|
|
It depends on how you want to run the store I guess. You can't sell what isn't in stock, so your points of sale have to know and update stock quantities; how often do you order? how about running the order program once a day, checking all items are sufficiently stocked?
|
|
|
|
|
Hi all,
I was recently working on a C++ application in Xcode (free Mac developer tool) and started running into some really weird BUS errors. What happened was that the code would compile and run fine in terminal up until I initialized two new variables just like this --> int r, c;
After going back and getting rid of that line of code I tried a few new initialization but found that virtually any new initialization I wrote into the code caused the same problem. I would recompile and execute the code only to find that the terminal was still throwing BUS errors. Yet when I got rid of those new initializations it went back to running perfectly well.
All the code I have written and compiled is included below and I have commented some of relevant sections where the problem occurs. If anyone could help me that would be much obliged because I have no clue what could be causing these errors.
-----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*-------STRUCTURES---------*/
typedef struct {
int rows;
int cols;
int num_colors;
int file_size;
int vector_size;
int* data;
} sImage;
/*----------GET IMAGE INFO SUBPROGRAM--------------*/
long get_info(FILE* inputFile, long offset, int numberOfChars)
{
unsigned char dummy = '0';
unsigned char *ptrC = &dummy;
long value = 0;
fseek(inputFile, offset, SEEK_SET);
for(int i = 0; i < numberOfChars; i++) {
fread(ptrC, sizeof(char), 1, inputFile);
/* calculate value based on adding bytes */
value = (long)(value + (*ptrC)*(pow(256, (i))));
}
return(value);
}
/*-----------SET IMAGE DATA SUBPROGRAM----------------*/
void set_image_data(FILE* inputFile, sImage* bmp) {
bmp->cols = (int)get_info(inputFile, 18, 4);
bmp->rows = (int)get_info(inputFile, 22, 4);
bmp->file_size = (int)get_info(inputFile, 2, 4);
bmp->num_colors = (int)get_info(inputFile, 46, 4);
bmp->vector_size = (int)(bmp->file_size - (14 + 40 + 4*(bmp->num_colors)));
}
/*------------PRINT IMAGE DATA SUBPROGRAM-------------*/
void print_image_data(sImage* bmp){
printf("Width: %d\n", bmp->cols);
printf("Height: %d\n", bmp->rows);
printf("File size: %ld\n", bmp->file_size);
printf("# Colors: %d\n", bmp->num_colors);
printf("Vector size: %d\n", bmp->vector_size);
}
int main(int argc, char* argv[])
{
// Check that correct file path entered
if(argc < 2)
{
printf("Usage: %s bmpInput.bmp\n", argv[0]);
exit(0);
}
printf("Reading filename %s\n", argv[1]);
// Variable Declarations
FILE *bmpInput, *rasterOutput; /* Input file and text file with raster output */
sImage *original; /* Original BMP image data */
/*--------READ INPUT FILE------------*/
bmpInput = fopen(argv[1], "rb");
fseek(bmpInput, 0L, SEEK_END);
/*--------DECLARE OUTPUT TEXT FILE--------*/
rasterOutput = fopen("data.txt", "w");
/*--------SET AND PRINT IMAGE DATA--------*/
set_image_data(bmpInput,original);
print_image_data(original);
/*
*
* TRYING TO ACCESS ORIGINAL->NUM_COLORS IN THIS LINE CAUSES A BUS ERROR TO BE THROWN
* WHEN EXECUTED IN TERMINAL, EVEN THOUGH IT IS CLEARLY ACCESSED IN THE NEXT LINE OF CODE
*
*/
// SHOULD THROW BUS ERROR WHEN UNCOMMENTED
// original->num_colors++;
/*----START AT BEGINNING OF RASTER DATA-----*/
fseek(bmpInput, (54 + 4*original->num_colors), SEEK_SET);
/*
*
* INITIALIZING TWO NEW INTEGER VARIABLES WILL ALSO CAUSE THE PROGRAM TO THROW A BUS ERROR
*
*/
// SHOULD THROW BUS ERROR WHEN UNCOMMENTED
// int r, c;
/*
*
* WAS WRITTING THE BELLOW BIT OF CODE WHEN I FIRST NOTICED THE PROBLEM WITH THE BUS ERRORS
*
*/
/*----------READ RASTER DATA----------*/
//for(int r = 0; r < original->rows; r++) {
//for(int c = 0; c < original->cols; c++) {
/*-----read data and print in (row,column) form----*/
//fread(pChar, sizeof(char), 1, bmpInput);
//fprintf(rasterOutput, "(%d, %d) = %d\n", r, c, *pChar);
//}
//}
fclose(bmpInput);
fclose(rasterOutput);
}
-----------------------------------------------------------------------
|
|
|
|
|
We did some development on mac with Xcode ages ago but i have a faint memory about you having to set the maximum size of the stack for your application, and if you would set this to a too small value then, yepp, you guessed it, BUS error when adding variables. I might be completely off the track but try looking for this setting (i think it was somewhere along the project settings but this is an even fainter memory), increase it and see if it helps.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
Don't suppose you have any further idea about how to increase the stack size do you? I've already tried adding in something to the effect of -Wl,-stack_size,0x10000000 as a linker flag but it doesn't seem to be having any effect.
|
|
|
|
|
No, sorry, as said, it was ages ago...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
I'm not a Mac developer but the first thing I'd look into would be the use of original . I can't see anywhere where you initialise the thing OR that would cause it to be initialised to the address of a real object. It looks like set_image_data is just writing data over some random bit of memory.
Cheers,
Ash
|
|
|
|
|