|
I just ran the above code and it works correctly. I had to create my own version of the NewLandmarks structure, so maybe what you have is actually the issue.
|
|
|
|
|
Here is my struct and the NewLandmarks vector. Do you see anything in this code that could be causing this problem?
struct landmarktype {
std::string fiducial{};
std::string name{};
Matrix location{};
std::vector <size_t> subtractions{};
};
vector <landmarktype> NewLandmarks;
declared earlier in the code, but in case it's important here is my Matrix class:
class Matrix {
private:
double * M;
size_t ROWS, COLUMNS;
public:
Matrix(): M(NEW double[1]), ROWS(1), COLUMNS(1) {}
Matrix(size_t R, size_t C): M(NEW double[R * C]), ROWS(R), COLUMNS(C) {}
~Matrix() {delete[] M;};
Matrix(const Matrix & m): M(NEW double[m.ROWS * m.COLUMNS]),
ROWS(m.ROWS), COLUMNS(m.COLUMNS) {
for (size_t i = 0; i != (ROWS * COLUMNS); i++) M[i] = m.M[i];
}
double & operator()(const size_t R,
const size_t C);
double operator()(const size_t R,
const size_t C) const;
[[nodiscard]] size_t rows() const { return ROWS; }
[[nodiscard]] size_t cols() const { return COLUMNS; }
void set(const size_t R, const size_t C) {
double* newMat = NEW double[R*C];
delete[] M;
M = newMat;
ROWS = R;
COLUMNS = C;
}
void clear()
{
double* newMat = DBG_NEW double[0];
delete[] M;
M = newMat;
ROWS = 0;
COLUMNS = 0;
}
void print(std::fstream & ) const;
}
void Matrix::print(fstream & fout) const {
size_t r, c;
for (c = 0; c != COLUMNS; ++c)
for (r = 0; r != ROWS; ++r)
{
fout << setiosflags(ios::fixed) << std::setprecision(outputprecision) << std::setw(22) << M[r * COLUMNS + c];
if ((r*COLUMNS+c) != (ROWS*COLUMNS - 1)) fout << ", ";
}
}
|
|
|
|
|
I cannot get that to build, the compiler does not know NEW or DBG_NEW . But either way that is a rather complex class. However, I can see nothing obvious, I guess the only way to find the problem is via the debugger.
[edit]
OK, with a bit of editing I got it to work and the output is correct (as far as I can see) in both cases.
So the issue must have something to do with what you are running, or your data.
[/edit]
|
|
|
|
|
Sorry, my mistake. That's my attempt at some debugging.
When I switch debugging off the preprocessor will replace NEW and DBG_NEW with new. Do that now and it should compile.
|
|
|
|
|
See the update in my previous message.
|
|
|
|
|
Hello,
We have an application. We want to check while starting that application in any system (customer place) whether any virus is there or not or the exe went out with or without virus.
Can we do this in C++ in the application startup itself or can we use any third party software?
Please suggest.
Regards,
Gopinath.
|
|
|
|
|
Gopi Nath wrote: Can we do this in C++ in the application startup Not unless you know how to write a virus check program, and have a database of all known viruses.
|
|
|
|
|
No, you can't.
The reason being is executable viruses have a nasty habit of hiding themselves from attempts to find them. File system reads/writes get redirected to what looks like good data, so your attempts to find them will actually find nothing.
It's far better to rely on actual anti-virus software, which protects the actual file system code from attempts to redirect/replace it. That's something your code cannot do when a user launches it.
|
|
|
|
|
Thank you Richard and Dave for reply and suggestion.
Regards,
Gopinath.
|
|
|
|
|
At first I thought I could set the above values in DrawItem (I have an ownerdraw combobox). The Drawitem however only gets invoked when clicking the right icon after the display
I have tried OnCtlColor in the dialog (for the text color) It does get invoked but doesnt set the text color.
Tried OnCreate in ComboBox for the font for that it just didn't get invoked
Thanks
|
|
|
|
|
Presubclasswindntrolow got the font working
Then I re-read remarks on CTLCOLOR seems like for a combobox the message is sent to the combobox as it is the parent to the edit control and list box
However the ctlcolor for the combobox only got called twice and both times had a value CTLCOLOREDIT
maybe the idea is then to set the color of the listbox in the Drawitem
Thanks
|
|
|
|
|
|
I downloaded it built it debug x64 and as I was stepping thru that code it got an exception it was somewhere in MFC code the call stack indicated it was from an Additem Ill go back and try to fix it up thank you
|
|
|
|
|
Hi,
In my trying on understanding semaphores I am looking on the following example:
DWORD WINAPI ChildThreadProc( HWND hWnd )
{
TCHAR szBuffer[256]; DWORD dwSemCount = 0; HANDLE hSemaphore = OpenSemaphore( SYNCHRONIZE, FALSE, "TEST SEMAPHORE");
wsprintf(szBuffer, "Thread %x waiting for semaphore %x", GetCurrentThreadId(), hSemaphore );
SendMessage(hWnd, WM_USER, 0, (LPARAM)szBuffer);
WaitForSingleObject( hSemaphore, INFINITE );
wsprintf(szBuffer, "Thread %x got semaphore", GetCurrentThreadId() );
SendMessage(hWnd, WM_USER, 0, (LPARAM)szBuffer);
Sleep(5000);
ReleaseSemaphore( hSemaphore, 1, (LPLONG)&dwSCount );
wsprintf( szBuffer, "Thread %x is done with semaphore. Its count was %ld.", GetCurrentThreadId(), dwSemCount );
SendMessage( hWnd, WM_USER, 0, (LPARAM)szBuffer );
CloseHandle( hSemaphore );
ExitThread ( TRUE );
}
And I am having 2 problems here:
-first, the dwSemCount value si always printed as 0, even if the semaphore works fine
-second, incrementing the counter with ReleaseSemaphore function from inside of thread doesn't working, I can't explain why.
Can you please help me with some advices?
Thank you very much,
|
|
|
|
|
|
Thank you Mircea,
I had changed the access rights for OpenSemaphore and the ReleaseSemaphore is working now.
Please help me and with the displaying of the semaphore counter:
ReleaseSemaphore( hSemaphore, 1, (LPLONG)&dwSCount );
wsprintf( szBuffer, "Thread %x is done with semaphore. Its count was %ld.", GetCurrentThreadId(), dwSemCount );
SendMessage( hWnd, WM_USER, 0, (LPARAM)szBuffer );
The displayed value of the dwSemCount is always 0, but it should be equal with the initial value, or with the decremented value, where is the mistake or where I am wrong?
Thank you,
|
|
|
|
|
Hmm, dwSCount vs dwSemCount . Could that be a typo?
Mircea
|
|
|
|
|
Good catch!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Sorry,
I made some test with SCount as global variable because of the problems, but yes, I had replaced this variable
and is ok now.
Thank you very much,
|
|
|
|
|
You should avoid using SendMessage form a worker to a main thread. It could lead to a deadlock. In most cases PostMessage is more preferable.
|
|
|
|
|
|
Hi
with the combobox it seems that drawitem function is only called after I click the icon of drop down.
My combobox displays with the first entry in the editbox (unformatted i.e. font and color).
Is there any to have drawitem invoked before it displays as I would like to format the entry in the edit control
Thanks
|
|
|
|
|
Perhaps your implementation/override of DrawItem is not complete?
Have a look at some of the CP articles describing the ownerdraw comboboxe, like this one:
Group Combo Box
|
|
|
|
|
Hi . Recently i've got to make a game called gomoku between two players and I don't know where to start. Could you please assist with the steps or at least a C++ code for the Gomoku game with comments so that I can at least be able to follow what has been coded.
|
|
|
|
|
The first thing you need to do is to study the game so you understand the rules. You can then start to figure out what each step of the game can do. From that you should be able to create a basic design document. Until you have done all that there is no point in thinking about actual code.
|
|
|
|