|
|
I need to do 3-4 tasks after a fix time interval . the tasks are dependent on each other , i need to do all in parallel.currently I m doing these in separe threads (running 3-4 threads).problem is I m using sleep method in each thread to repeat task after a fix interval .but sleep is not guaranteed to sleeep for exact interval. how can I do parallel tasks after exact interval .
|
|
|
|
|
You could use an auto-reset event for each thread that the
corresponding thread waits on until it's signaled by a timer.
OnTimer
{
for each threadstartevent in arrayofthreadstartevents
SetEvent(threadstartevent)
}
threadproc
{
while (false == threadshouldterminate)
{
wait for event
do some processing
}
}
You could instead use a single manual-reset event to release all the waiting threads
at "the same time" but then you need some scheme to get the last thread that
completes its task to reset the event. The other threads would need to wait
for the last thread to complete.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have wrote an application which edit system file.when i run my application in limited user account it shows access denied error.i need to give admin privillage for limited user to edit that file . how i do this in vc++.
help me plea se
|
|
|
|
|
I am linking a C library in C++ application.
i have declared function in my c.h
#ifdef __cplusplus
extern "C" {
#endif
int fun(int,int);
#ifdef __cplusplus
}
#endif
created my c.lib
now in my capp.cpp i have included this c.h as
#include "c.h"
and i have linked the c.lib and calling this fun function in my cpp application as
int x=fun(2,3); directly ...
would this work ??
how can i be sure that the library is linked propery ??
|
|
|
|
|
Should work. Sounds like you've done everything correctly.
Steve
|
|
|
|
|
I m allocating memory using GlobalAlloc(GMEM_FIXED|GMEM_DDESHARE,)method
while deallocate using GlobalUnlock(),GlobalFree()but its not freeing memory what method should i use to allocate and deallocate
|
|
|
|
|
What is the return value of GlobalFree()? If it returns anything other than NULL you need to call GetLastError().
Best Wishes,
-David Delaune
|
|
|
|
|
please explain how getlasterror can help me by code
|
|
|
|
|
GlobalFree()[^] will return NULL if it succeeds. If GlobalFree()[^] fails it will return a positive HGLOBAL value which is essentialy a handle to the memory object.
If GlobalFree is returning any value other than NULL it is indeed failing. Calling GetLastError()[^] will tell you why it is failing.
So I ask you again:
What value is the GlobalFree() returning?
Best Wishes,
-David Delaune
|
|
|
|
|
Gloobal Unlock returned 1
global free returned 00000
|
|
|
|
|
This means your call to GlobalFree() was successful.
|
|
|
|
|
when i debug code , every time it give blue screen with message buffer overflow using locked memory and system restarted
|
|
|
|
|
If memory is unlocked then why system always dump memory and restart giving message driver_left locked files in process
modified on Monday, August 11, 2008 3:20 AM
|
|
|
|
|
|
|
Hi all,
I have this helper header file located at a common folder it is linked to my project right however I am getting these errors:
2>PrefDlg.obj : error LNK2019: unresolved external symbol "void __cdecl SendCtrlEndToWnd(char *)" (?SendCtrlEndToWnd@@YAXPAD@Z) referenced in function "public: long __thiscall CPrefDlg::OnButtonViewlogfile(unsigned short,unsigned short,struct HWND__ *,int &)" (?OnButtonViewlogfile@CPrefDlg@@QAEJGGPAUHWND__@@AAH@Z)
2>PrefDlg.obj : error LNK2019: unresolved external symbol "void __cdecl ClsMulWnd(char *)" (?ClsMulWnd@@YAXPAD@Z) referenced in function "public: long __thiscall CPrefDlg::OnButtonViewlogfile(unsigned short,unsigned short,struct HWND__ *,int &)" (?OnButtonViewlogfile@CPrefDlg@@QAEJGGPAUHWND__@@AAH@Z)
2>PrefDlg.obj : error LNK2019: unresolved external symbol "void __cdecl SetDateStr(char *)" (?SetDateStr@@YAXPAD@Z) referenced in function "public: long __thiscall CPrefDlg::OnButtonViewlogfile(unsigned short,unsigned short,struct HWND__ *,int &)" (?OnButtonViewlogfile@CPrefDlg@@QAEJGGPAUHWND__@@AAH@Z)
2>D:\SVN\Licensin System\Work Package\UpdateManager\Debug\UpdatePanel.cpl : fatal error LNK1120: 3 unresolved externals
I am a bit surprised as to why I am getting this but not on the other functions located at the helper header.
Is there something I forgot to do here?
Thanks,
Jayjay
|
|
|
|
|
Have you included the header file where you are calling those functions?
--
"Programming is an art that fights back!"
|
|
|
|
|
|
i got it now i forgot to include the header in the project headers sheeesh
|
|
|
|
|
Hello everyone,
Mentioned here, in section "Single-Threaded Apartment (STA)",
http://msdn.microsoft.com/en-us/library/ms809311.aspx
1. when making outgoing calls to other apartment in STA, the owner thread of STA is not blocked and continue to do message pump, it is the RPC thread (which is responsible for sending marshalled result to destination apartment) is blocked?
2. when the STA owner thread executes method DispatchMessage in message pump loop, DispatchMessage will use the same owner thread to send message to hidden window, also use the same owner thread to unmarshall through proxy, and the same owner thread to execute desired COM method?
thanks in advance,
George
|
|
|
|
|
can i take a good example about file filter by shell extension?
user may register some files to the extension module,
and then those registered files are not listed in explorer.
that's all.
help me.
|
|
|
|
|
Hi, I have a MFC Doc/View SDI application that in CDocument it opens a dialog box I need this dialog box to send and get data to the CDocument without halting the thread so I created a Mode less dialog box (CDialog m_dlgCalibrate),Now my problem is How can I send a message from this dialog box to CDocument
class. In CDocument class that I create this calibration dialog box I've
assigned its parent the CView associated with CDocument(I have only one view)
This is the code
void CMyDoc::OnCommandsCalibrate()
{
bool res;
POSITION pos = GetFirstViewPosition();
res = m_dlgCalibrate.Create(IDD_CALIBRATE, GetNextView(pos));
if(!res)
AfxMessageBox(_T("Error Creating Dialog Box"));
m_dlgCalibrate.ShowWindow(SW_SHOW);
}
So when in this calibration dialog box I executed
PostMessage(WM_CAL_COMMAND);
I expected it is routed to CMyView
I have put this in CMyView Message map
ON_MESSAGE(WM_CAL_COMMAND, CMyView::OnNewCalCommand)
I also have defined handler function as:
afx_msg LRESULT OnNewCalCommand(WPARAM, LPARAM);
but this message won't reach to CMyView let alone CMyDoc
but I could grab it in CMainFrame class using similar code(I only
executed AfxGetMainWnd()->PostMessage(WM_CAL_COMMAND) in dialog box in this
case). Is there anyway so I can post this message to CMyDoc directly or at
least to CMyView?
Thanks
|
|
|
|
|
Hi,
Is there any chance of giving the DialogBox a reference to your CMyDoc and then executing m_pMyDoc->OnCalibrate() directly in your CMyDialog::OnOK(). You are trying to use the Framework Message Routing Mechanism which was designed to implement MFC. I'm not sure how it routes WM_USER+x Messages. From your experiment it occurs to me that the message ends up in the BitBucket somewhere along the way.
Hope this is helpfull,
Regards
Bram van Kampen
|
|
|
|
|
Hi, I tried but I couldn't because it requires that I have a member variable of dialog box in CDocument class, so I have to include CDialog header file in CDocument header file in that case I also need to define a member variable that points to CDocument so I also need to include CDocument header file in CDialog header file and this causes the compiler to cry loudly and gives hundreds of errors I even tried to prevent compiler form reading a header file recursively. like this:
#ifndef __CDOCUMENT_H_
#define __CDOCUMENT_H_
.....
#endif
but again it wouldn't satisfy the compiler.
Regards ,
|
|
|
|