|
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
|
|
|
|
|
Thank you so much that was the problem. The code works fine now and I don't get any more BUS errors
|
|
|
|
|
how i can save dc of onpaint in MFC SDI c++?
when i draw a rectangle with mouse,i can draw only on rectangle at a time??: confused:
|
|
|
|
|
You shouldn't save the dc. If you need to paint multiple rectangles then do draw multiple rectangles in a single OnPaint
body.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
okay but which fuctions i have to use to save dc & load dc again??
|
|
|
|
|
i'm drawing rectangle with a mouse.but 1 rectangle is replaced by another...
|
|
|
|
|
You must NOT save (or load) the device context. On the other hand, you must save the state of your drawing. For instance, once a rectangle has been draw (on mouse action) you should save it somewhere in you class. Whenever the OnPaint call occurs you have to redraw all the saved rectangles.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
okay but which functions i have to use to save the state of rectangles....plzz tell me the complete way..
|
|
|
|
|
There's no function to do such a thing. You have to store all the rectangle information in a container (like for instance a std::list). If you don't know what a std::vector is, it is a kind of array of objects but which can grow dynamically. It is much easire to work with than C arrays.
So, the principle is: once you moved the mouse to show an additional rectangle, instead of drawing it directly, you create an instance of your rectangle class and you add it to the vector, then you call Invalidate() in your view, which will force a redraw of the view. In the OnPaint method, you simply iterate over all your elements in your vector and draw them one by one.
|
|
|
|
|
Cédric gave you the solution: after mouse action, store the (new) rectangle coordinates into an 'array of rectangle coordinates' (as suggested you may better use a STL container as the std::vector ) and call in sequence InvalidateRect , UpdateWindow (to make re-paint happen), Inside the OnPaint message handler draw all the rectangles of the array.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thankx Cédric & CPallini, i hope this will help me
|
|
|
|
|
Hi,
I am inserting a OLE object yellow arrow to the left of some text
It seem like whenever I insert the object it effects the starting pos of the text
if (curr_start_cur == 0)
{
curr_start_cur = start;
curr_end_cur = end;
SetSel(curr_start_cur,((curr_start_cur+pos)-5));
oleptr->InsertObject(&reobject);
}
SetSel(Begin,Begin+pos+1);
setfontsize(11);
setbold();
SetColour(RGB(255,0,0));
setfontsize(11);
}
The following is my text
======> _ 000000 90EC D00C 0000 C STM R14,R12,12(R13) line 1
_ 000000 18CF LR R12,R15 line 2
The "======>" represent the OLE arrow object
from line 2 and downward all "_' are in red the rest of the text remains the normal color
however at line 1 the "_" is in red and also the following text is in read "000000 90EC"
was wondering if the insert object effects where the stating character of the SetSel starts
|
|
|
|
|
Hi all :
I wrote a simple dialog based program to control a specific machine. And there is a button on the program.
When I pressed the button, some functions (from the API of the machine) would be called to do something.
Because the document said that the function is asynchronous, it used PostThreadMessage() to send some API-defined messages.
And the function might be time out. So I used CreateThread() and SetTimer() to check the success message is received or not within the thread.
But I met a strange problem.
If I ran it with debug mode and set the breakpoint on function A (function A wasn't still be called), it runs normally.
If I ran it with debug mode and didn't set the breakpoint on function A or ran it with release mode, the function A would timeout.
But if I ran the sample program (vendor provide, but only binary file, don't have source code), it runs normally...
I checked the debug mode and release mode settings of the project.
The included folders, linked folders, library dependencies...etc are the same.
So I don't know how to solve this question...
Does anyone can give a hint or pointed what's wrong with the code ?
Below is my code :
WaitPostThreadMessage(), MyFunc1() are global functions
SUCCESS_MSG, ERROR_MSG are two messages sent by the machine
TIMEOUT_MSG is the message which I defined to represent the timeout.
The parameter dwThreadId would be sent to the machine to indicate which thread is the post target of the machine
When a user click the button. MachineProc::ClickBtn() will be called.
And I put the workflow code in CreatedThread().
The problem which I mentioned above occured at calling APIFuncB()
UINT_PTR uTimer;
int timerCount;
int timerThreshold;
bool bTimeOut;
void CALLBACK TimerFunc(HWND hwnd, UINT message, UINT idTimer, DWORD dwTime) {
timerCount++;
if(timerCount >= timerThreshold) {
bTimeOut = true;
}
}
int WaitPostThreadMessage() {
MSG msg;
while(!bTimeOut) {
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE) {
switch(msg.message) {
case SUCCESS_MSG:
if(KillTimer(NULL, uTimer) == 0) {
}
return SUCCESS_MSG;
case ERROR_MSG:
if(KillTimer(NULL, uTimer) == 0) {
}
return ERROR_MSG;
default:
break;
};
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(bTimeOut) {
if(KillTimer(NULL, uTimer) == 0) {
}
break;
}
}
return TIMEOUT_MSG;
}
DWORD WINAPI CreatedThread(LPVOID) {
MSG msg;
PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
int iResult;
DWORD dwThreadId = GetCurrentThreadId();
iResult = APIFuncA(argu1, dwThreadId);
iResult = MyFunc1();
}
int MyFunc1() {
int iResult;
bTimeOut = false;
timerCount = 0;
timerThreshold = 2;
APIFuncB();
uTimer = SetTimer(NULL, WM_APP_TIMER, 1000, (TIMERPROC)TimerFunc);
iResult = WaitPostThreadMessage();
if(iResult != SUCCESS_MSG) {
}
}
void MachineProc::ClickBtn() {
HANDLE hThread;
DWORD nThreadID;
hThread = CreateThread(0, 0, CreatedThread, 0, 0, &nThreadID);
}
The running ide is visual stuido 2005 (don't install windows sdk)
Thanks a lot.
|
|
|
|
|