|
If the semaphore handle is being Create/Open-ed once, then you should get an error condition from WaitForSingleObject(), like WAIT_ABANDONED. It certainly works this way for Events. This assumes that the handle is created in one thread, and directly passed to another, rather than one thread using CreateXXXX and the other using OpenXXXX.
Steve S
Developer for hire
|
|
|
|
|
This one is a first for me.
"The value of ESP was not properly saved across a function call"
It's happening on a timer callback function I have placed in a base class, and it only occurs when I declare the non-static member as virtual. Here is the code
void *CSpecialFx::thisPtr;
CSpecialFx::CSpecialFx()
{
thisPtr = this;
uTimerId = SetTimer(0,0,30,(TIMERPROC)StaticProc);
}
CSpecialFx::~CSpecialFx()
{
KillTimer(0,uTimerId);
}
VOID CALLBACK CSpecialFx::TimerProc(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)
{
static int i = 0;
i++;
}
VOID CALLBACK CSpecialFx::StaticProc(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)
{
CSpecialFx *tmp = (CSpecialFx*)thisPtr;
tmp->TimerProc(hwnd,uMsg,idEvent,dwTime);
}
The code runs for a few seconds, but it never steps into the virtual callback. The error also goes on to mention the calling conventions being a probable cause. What did I miss?
|
|
|
|
|
Can you show the class declaration? Which function is static? which is virtual? I can probably assume which is which but just to be sure.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Sure
class CSpecialFx
{
public:
CSpecialFx();
virtual ~CSpecialFx();
protected:
virtual VOID CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime);
private:
static VOID CALLBACK StaticProc(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime);
static void *thisPtr;
UINT uTimerId;
};
|
|
|
|
|
I think maybe I have solved it. The object was declared within the scope of a function, so I have a feeling it was goind out of scope. I declared it as static and it seems to be working fine.
|
|
|
|
|
In your destructor be sure to set the thisPtr to NULL, and in the StaticProc be sure to check for NULL. If you don't you could run into problems if you have multiple instances of your class active.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
thanks for the heads up. I'm really bad when it comes to error checking, well bad or just plain lazy...
|
|
|
|
|
PJ Arends wrote: In your destructor be sure to set the thisPtr to NULL, and in the StaticProc be sure to check for NULL. If you don't you could run into problems if you have multiple instances of your class active.
He won't be able to have multiple instances of this object. What he has is a hacked-up singleton (which I don't think is what he wants).
I can't test this at the moment, but I believe if you pass SetTimer your member function as &CMyClass::MyTimerFunc it will avoid the need to make it static.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Does this help?
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hello,
I was trying to add a child window to another window that is not running with the same application instance. I used enumWindows to find the window I was looking for and then used createWindowEx to create the child window specifying the window handler that was found as the parent. It didn't work.
Is this possible?
thanks.
|
|
|
|
|
You said it didn't work what did you get error or a null handle.
|
|
|
|
|
I'm new in ATL control programming, I did write some ActiveX Controls, so I started with ATL Controls project intuitively, and I start find some problems.
Ie:
I'm developing an ATL Control with MFC support and a Composite Control.
Then I put a button and I write code for OnButton like that:
<br />
LRESULT OnClickedButton1(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)<br />
{<br />
AfxMessageBox("Hello");<br />
return 0;<br />
}<br />
That work fine using the control in a VB application.
But if I add a Dialog class and handle the OnButton1 in the CDialog class, the button do nothing when it's pressed in a VB application.
I know, I miss something to tell the control that the handle is in the Dialog class, but what?
I need the dialog class because I will have more controls there and members variables and more handles for every control.
I would really appreciate any help, meanwhile I'm going to read some ATL articles.
Thank you.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
hi
need a little help as new to c++.
when i run the code below to save the names to a text file and then output the names back to the console application i have all the names together with no spaces.
eg: markjohnpeterjames
what i need to know is there a way to output the data from the txt file to the console but with spaces between the names ( or if you can play around with the output format in general ) or is it possible to save them to the text file in a particular format ?????
This one has me stuck !!!!!
Plus any sugestions for improvements on the code below will be much appreciated.
char xx [20];
ofstream fout;
fout.open("c:/out.txt", ios::app);
cout<< "Please enter your first name: \t";
cin>> xx;
fout<< xx;
// close file
fout.close();
char yy;
ifstream myfile("c:/out.txt");
cout<< "\nAll names entered on file: \t";
while (!myfile.eof())
{
myfile>> yy;
cout<< yy;
}
Thanks in advance !!!!
The problem with political jokes is they get elected.
|
|
|
|
|
When wring the file, write the name in either of the following ways:
fout << name << endl;
four << name << " ";
For print the file to the screen:
#include <iterator>
#include <algorithm>
#include <vector>
#include <string>
vector<string> names;
copy(istream_iterator<string>(myFile), istream_iterator<string>(), back_inserter(names));
copy(names.begin(), names.end(), ostream_iterator<string>(cout, "\n"));
Note that depending on the version of your compiler/STL library, it may or may not have overrides for reading string types in this manner, in which case you would need to switch it to a vector of character buffers of some size.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi Zac
The input and output format issues are working ok now thanks, but one small issue and i dont know why its happening.
The last name that i enter is saved to the text file no problems but is always printed twice on the console application after the program is run ????? ( only saved once on the text file!!!! )
eg:
mark
peter
james
james
Any suggestions why this might be the case.
Sorry for the hassle.
The problem with political jokes is they get elected.
|
|
|
|
|
What does your code look like exactly?
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
char xx [20];
ofstream fout;
fout.open("c:/out.txt", ios::app);
cout<< "Please enter your first name: \t";
cin>> xx;
fout<< xx << endl;
fout.close();
char yy[100];
ifstream myfile("c:/out.txt");
cout<< "\nAll names entered on file: \t";
while (!myfile.eof())
{
myfile.getline(yy,100,'n');
cout << yy;
}
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Sorry Zac
Your last message just crossed the one i sent and it solved the issue.
Thanks for the code.
Thanks again for your time and help.
The problem with political jokes is they get elected.
|
|
|
|
|
Thanks EricDV
Will have a read up on the getline function
Thanks for looking at my code
I really hate this darn machine;
I wish that they would sell it.
It won't do what I want it to,
but only what I tell it.
~Author Unknown
|
|
|
|
|
I'm fairly new here too, but - welcome to The Code Project.
This site is great.
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
EricDV
Quick question with your code.
char yy[100];
ifstream myfile("c:/out.txt");
cout<< "\nAll names entered on file: \t";
while (!myfile.eof())
{
myfile.getline(yy,100, 'n');
cout << yy;
}
In the following line:
myfile.getline(yy,100, 'n');
When i enter a name beginning with the letter "n" like nigel on the console it saves as "nigel" no problems to my text file, but when i display the contents of the text file back into the console it seems to ignore the "n" and output is displayed as "igel". It seems like it is acting as an ignore function. Any ideas why or how to solve it.
Cheers
I really hate this darn machine;
I wish that they would sell it.
It won't do what I want it to,
but only what I tell it.
~Author Unknown
|
|
|
|
|
Mark_Murphy wrote: myfile.getline(yy,100, 'n');
That should be myfile.getline(yy, 100, "\n"), or simply myfile.getline(yy, 100); ('\n' is the default 3rd parameter).
Alternatively, you could use the generic getline method:
string name;<br />
getline(myfile, name);
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Excellent Zac
The
string name;
getline(myfile, name);
worked perfect, the other suggetions gave errors on compiling.
Leave you guys in peace now
Thanks for the help much appreciated !!!
I really hate this darn machine;
I wish that they would sell it.
It won't do what I want it to,
but only what I tell it.
~Author Unknown
|
|
|
|
|
Oops...sorry, I don't really use this stuff.
Should've been:
myfile.getline(yy,100,'\0');
This way the file read will quite when it hits a null char.
SEE:
Input Stream Member Functions[^]
and
istream::getline[^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
No worries EricDV
Thanks for the info and the links, will go read up the stuff for a while now ( maybe confuse myself a little further lol ). Its been 4 days now since i started with C++ and just finished my first program. All I got to do now is tweak the code a little and try to improve it.
So many thanks for your help today !!!!
I really hate this darn machine;
I wish that they would sell it.
It won't do what I want it to,
but only what I tell it.
~Author Unknown
|
|
|
|