|
|
This is the first time I am working with UNIX, and I have some problems related to threads.
I wish to have a timer class, which works fine as it does in WIN. So I created one, using signals, and now when the time interval is expired, I need to invoke a fn. say,
void OnTimer( int ProcessID );
When this Timer object is created, I am creating a new thread for the signals to execute, means this timer is running in a seperate thread. But the OnTimer fn. needs to be invoked from the thread that created the object. So I would like to know, is there any way by which I can get the CurrentThread handle ( main thread / the thread that created the object ), and make it to invoke the OnTimer fn.
Your suggestions are appreciated!!!
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
I got the fn. to get the thread handle which is pthread_self( ), But still I dont know how to make it to invoke the OnTimer fn.
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
Not sure exactly what you are trying to do here. Why do you want the timer in another thread, but the function called in the original thread? It's a bit excessive just to create a thread for the purpose of sleeping. How many timers are you likely to have running at once? Signals and threads dont really mix very well, so I wouldnt rely on that method. If you must have a seperate timer thread, then you need to look at some way of notifying the original thread - look at condition variables, or pipes, to achieve this. However, as your parent thread will need to be explicitly waiting for this notification, it may as well perform the timer itself and so not require a seperate thread.
|
|
|
|
|
Thanks for the reply.
If I am not going for a seperate thread, then the signals/timer would block the main thread. Thats why I decided to go for threads. Now my problem is not with notifying the main thread, But I need to invoke a method in the scope of main thread, and my main thread is not waiting for any notifications( If it were, then I would have gone for pthread_join ). The parent thread would still be working with some other tasks, and in btw, the timer object has to sent an interrupt like message ( by invoking some fns say OnTimer(...) ), and that fn. invocation has to be in the scope of the main thread.
It shud work some what like the OnTimer( ... ) msg in windows which is send by the framework when the SetTimer(...) is called, and the interval has expired.
Once again thanks for the suggestion Johnny...
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
You should re-design your application to work with the UNIX/POSIX threading model instead of trying to build a Windows emulation layer. Use condition variables and mutexes to synchronize the threads.
If you need a platform-independent interface, use Boost threads
|
|
|
|
|
errrrr mouse hook?
u should be enumerating all processes etc
"there is no spoon" biz stuff about me
|
|
|
|
|
That's true. But thing is that to get confidence I am just trapping one process at a time, using mouse. So that I should have good insight into hooking before integrating it with project. I am trying to get information like Handle of the winow, name of the window ..
|
|
|
|
|
Hi..
If all other exe r your..then u can use
1. Mailslot
2. Pipe
& check by communicate with other exe...
This is a good solution..if all exe are your.
One thing is sure that if u are not able to do mouse hook then u need to go in "Process" direction...
Thanks...sumit
Sumit Kapoor
|
|
|
|
|
Hi Pal!
It's not just my exe. I want handle of all the exe windows. The problem I am having is that with mouse hook is that system crashes very often. I am just trying to hook all exe and get handle of the exe I am interested.
with Cheer!!!
siddharth
|
|
|
|
|
I have a data like this
40126024302350123
The first no of this data reperesent what is the no of 4 digit nos in the data.
Here it is 4 because i have 4 4digit no.
If i have 3, 4digit no i will represent like this 3024302350123
CString GetString(int NO )
{
switch (NO)
{
case 1:
return 3024302350123;
break;
case 2:
return 40126024302350123;
break;
case 3:
return 10245;
break;
}
I need your help in these areas
1.The return type i have mentioned is CString .Is this correct one.
or else plz suggest the correct datatype
2.Then i need a function where
to trim the first character of the data and convert that into a integer
and put it into a for loop to fix how many loops the function have.
for example if it is 3024302350123 then the first character is 3 so the for loop should go 3 times and in first loop it should take the first 4 digit and do some operations and in second loop it should take the next 4 digit and do the same operation but with new value ie 2nd 4digits and in 3rd loop it should take the 3rd 4digit no and do same operations with that new no
Sir please if there is anybody who can help me in this
thanks in advance
vimal
|
|
|
|
|
i have no idea what ur actually asking but it doesnt look like rocket science so if u could asctually ask an intelligible question maybe u could get some help
"there is no spoon" biz stuff about me
|
|
|
|
|
hi
I want to program MicroSoft Agent Control in my VC++ application so how i program it.Please help me.Send me some sample code.
222222
|
|
|
|
|
Um, did you even take the time to type "MS Agent" in CP's search box? /ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
enum { IDD = IDD_SYMBOLSELECT };
CListCtrl m_list1;
//}}AFX_DATA
CImageList mm;
............
mm.Create (IDB_SYMBOLS, 16, 100, RGB(192,192,192));
............
DDX_Control(pDX, IDC_LIST1, m_list1);
............
BOOL CSymbolSelectDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_list1.SetImageList(&mm,LVSIL_SMALL);
CString cc;
for(int i=0;i
|
|
|
|
|
Hi, im writting a small W32 application (non MFC) and i need to parse the command line for passed arguments, and since the app MUST be compiled for unicode, the MSDN docs say i should use the GetCommandLine() function to get a unicode version of it, and it also suggests using CommandLineToArgvW() to get a main() style array of arguments and a count.
inside my winmain(), heres what i do:
<br />
int argcount=0;<br />
LPWSTR* arguments=CommandLineToArgvW(GetCommandLine(), &argcount);<br />
<br />
.<br />
.<br />
.<br />
<br />
if(arguments)<br />
GlobalFree((HGLOBAL)arguments);
the problem is that in the GlobalFree() line, the app takes an exception and crashes. but MSDN sais i should do the GlobalFree!
i quote:
"It is the caller's responsibility to free the memory used by the argument list when it is no longer needed. To free the memory, use a single call to the GlobalFree function."
any idea of what im doing wrong?
thanks!
|
|
|
|
|
|
hi, thanks for your reply.
when i ran that code in debug mode on my XP machine, it just caused a "first chance exception" shown in the output window of vc, (i dint even noticed it the first time) later i compiled the release version and it worked OK on windows XP, but when i tried it on NT4 server, then the exception became a "memory cant be read" error message, and the program crashed.
heres the code in "do stuff":
// checkout the command line for passed arguments
int nargs=0;
LPWSTR* cmdargs=CommandLineToArgvW(GetCommandLine(), &nargs);
LPWSTR argument=NULL;
for(int i=1; i<nargs; i++)
{
argument=cmdargs[i];
switch(i)
{
case 1: // 1st arg is times to do the test
{
int tests=_wtoi(argument);
tests=tests>=0? tests : 0;
if(!tests)
{
if(wcscmp(argument, L"0")!=0) // atoi failed or really zero?
days=DEFAULT_TEST_TIMES; // invalid argument!
}
mttimes=tests;
break;
}
case 2: // 2nd is "F" or "f" for File, (writte a log file)
if(wcsicmp(argument, L"F")==0)
dolog=TRUE;
break;
default:
break;
}
}
// release the memory
if(cmdargs)
GlobalFree((HGLOBAL)cmdargs);
the first chance exception occurs in the GlobalFree() line, if i remove it, then it runs fine on both XP and NT4 and both release and debug versions.
|
|
|
|
|
Greetings!
I'm a computer science major. I'm required to use Microsoft C++.net. I'm using the standard edition version 2003. This is the fisrt time I've used this software.
I need to turn in the .cpp, .dsp, and .dsw files. The only problem is that I can't find them. I used the search frature from the start menu and it reports the files that were created along with the software isntillation. I created files and I can't find the .cpp, .dsp, or the .dsw files that go with the files I created. I'm using Windows 2000.
Will you help me find thoes files?
Thanks,
Leonard Fear
|
|
|
|
|
.dsp and .dsw are the VC 6 project files. The names and formats changed in version 7. If you absolutely have to have dsp/dsw, there's a 7-to-6 project converter here on CP.
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
"That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."
-- Buffy
|
|
|
|
|
void get_comp_move()<br />
{<br />
vector <string> vecStr;<br />
string current;<br />
<br />
if(re == 0)<br />
{<br />
get_rand();<br />
cout << "empty\n";<br />
system("pause");<br />
}<br />
else<br />
{<br />
while(getline(data, current))
{<br />
vecStr.push_back(current);
}<br />
<br />
for(int i=0; i<vecStr.size(); ++i)<br />
{<br />
cout << vecStr[i] << endl;<br />
}<br />
<br />
cout <<"has something in it\n";<br />
}<br />
system("pause");<br />
}
|
|
|
|
|
What doesn't work?
Kuphryn
|
|
|
|
|
i am not using MFC.
i am trying to send an application the key strokes Shift-F5.
what i did was this (i used the decimal values for the key codes):
SendMessage(hwnd,WM_KEYDOWN,116,0);
SendMessage(hwnd,WM_KEYDOWN,16,0);
SendMessage(hwnd,WM_KEYDOWN,16,0);
SendMessage(hwnd,WM_KEYDOWN,116,0);
This combination only performs the F5 key press and completely ignores the fact that i used WM_KEYDOWN with shift before that.
i tried using Spy and found that i am sending the correct messages (like i said - F5 does work). Spy showed that WM_KEYDOWN is the message being sent when i press the keys in that order myself.
i tried other combinations this way with other windows and found out that it is completely NOT working - even with alt and control keys.
how can i make it work? can anyone see the problem?
|
|
|
|
|
i think lParam indicates the repeat count, so shouldnt it be atleast 1 instead of 0?
|
|
|
|
|
when i tried it with lParam = 0, it DID work for F5. i could see that F5 keydown was working, but not the combination Shift-F5.
anyway - i also tried with lParam = 1, and got the same result.
any ideas?
|
|
|
|