Click here to Skip to main content
15,899,754 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ganerate a report in C++/MFC Pin
Zouaoui Billel17-Apr-21 11:51
Zouaoui Billel17-Apr-21 11:51 
GeneralRe: ganerate a report in C++/MFC Pin
Victor Nijegorodov17-Apr-21 23:26
Victor Nijegorodov17-Apr-21 23:26 
AnswerRe: ganerate a report in C++/MFC Pin
Richard MacCutchan16-Apr-21 21:49
mveRichard MacCutchan16-Apr-21 21:49 
AnswerRe: ganerate a report in C++/MFC Pin
_Flaviu17-Apr-21 20:28
_Flaviu17-Apr-21 20:28 
SuggestionRe: ganerate a report in C++/MFC Pin
David Crow18-Apr-21 15:40
David Crow18-Apr-21 15:40 
QuestionVersion of a console application Pin
_Flaviu15-Apr-21 22:10
_Flaviu15-Apr-21 22:10 
AnswerRe: Version of a console application Pin
Richard MacCutchan15-Apr-21 22:50
mveRichard MacCutchan15-Apr-21 22:50 
GeneralRe: Version of a console application Pin
_Flaviu15-Apr-21 22:55
_Flaviu15-Apr-21 22:55 
GeneralRe: Version of a console application Pin
Richard MacCutchan15-Apr-21 23:03
mveRichard MacCutchan15-Apr-21 23:03 
AnswerRe: Version of a console application Pin
Maximilien16-Apr-21 6:13
Maximilien16-Apr-21 6:13 
GeneralRe: Version of a console application Pin
_Flaviu23-Apr-21 1:29
_Flaviu23-Apr-21 1:29 
QuestionRe: Version of a console application Pin
CPallini16-Apr-21 8:01
mveCPallini16-Apr-21 8:01 
AnswerRe: Version of a console application Pin
_Flaviu23-Apr-21 1:28
_Flaviu23-Apr-21 1:28 
AnswerRe: Version of a console application Pin
Mircea Neacsu16-Apr-21 23:11
Mircea Neacsu16-Apr-21 23:11 
GeneralDLL with a callback Pin
Bodo240715-Apr-21 6:05
Bodo240715-Apr-21 6:05 
GeneralRe: DLL with a callback Pin
Richard MacCutchan15-Apr-21 6:27
mveRichard MacCutchan15-Apr-21 6:27 
GeneralRe: DLL with a callback Pin
Bodo240715-Apr-21 6:41
Bodo240715-Apr-21 6:41 
GeneralRe: DLL with a callback Pin
Richard MacCutchan15-Apr-21 6:55
mveRichard MacCutchan15-Apr-21 6:55 
GeneralRe: DLL with a callback Pin
Bodo240715-Apr-21 7:33
Bodo240715-Apr-21 7:33 
GeneralRe: DLL with a callback Pin
CPallini15-Apr-21 20:51
mveCPallini15-Apr-21 20:51 
GeneralRe: DLL with a callback Pin
Richard MacCutchan15-Apr-21 22:44
mveRichard MacCutchan15-Apr-21 22:44 
PraiseRe: DLL with a callback Pin
Bodo240715-Apr-21 23:04
Bodo240715-Apr-21 23:04 
GeneralRe: DLL with a callback Pin
CPallini15-Apr-21 23:24
mveCPallini15-Apr-21 23:24 
GeneralRe: DLL with a callback Pin
Richard MacCutchan16-Apr-21 0:17
mveRichard MacCutchan16-Apr-21 0:17 
GeneralRe: DLL with a callback Pin
Bodo240716-Apr-21 3:47
Bodo240716-Apr-21 3:47 
OK, now I experience another issue with it, I'm sorry.
Hopefully you can help me here as well.

I now want to call the callback function if an timer expires. Therefore I create an timer in a function I call from the main application. I store the handles to the timer and the timer queue globally in static variables.
C++
static HANDLE gDoneEvent;
static HANDLE hTimer = NULL;
static HANDLE hTimerQueue = NULL;
int arg = 123; //will be passed to callback of timer


VOID CALLBACK TimerRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired)
{
    if (lpParam == NULL)
    {
        //do some error handling her
        return;
    }
    else
    {
        if(s_user_function!=nullptr)
            s_user_function(12);
    }
    //SetEvent(gDoneEvent);   //for periodic calls, don't set gDoneEvent
}


Now, in some function called from the main application, I allocate the timer and start it:
C++
char timer_init(void)
{   
    // Use an event object to track the TimerRoutine execution
    gDoneEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (NULL == gDoneEvent)
    {
        return 1;
    }
    // Create the timer queue.
    hTimerQueue = CreateTimerQueue();
    if (NULL == hTimerQueue)
    {
        return 2;
    }
    CreateTimerQueueTimer(&hTimer, hTimerQueue, (WAITORTIMERCALLBACK)TimerRoutine, &arg, 3000, 10000, 0);

    WaitForSingleObject(gDoneEvent, INFINITE); //if we don't wait it crashes although handles are stored globally?
        
    //the handles should be closed and deleted only after timer had occured. 

    ////CloseHandle(gDoneEvent);
    ////// Delete all timers in the timer queue.
    ////if (!DeleteTimerQueue(hTimerQueue))
    ////    printf("DeleteTimerQueue failed (%d)\n", GetLastError());
}

As you can see, I don't close the handles and delete the timer queue on purpose.
Everything works fine as long as the process waits. The callback in the main application is called.
If I comment out the line with WaitForSingleObject I'll get an access exception, although I stored all the handles globally. Teh exception occurs with the timing the timer would have. So most likely it tries to call the callback of the timer function but something is missing.
What is it I'm overlooking?
I need the dll running, not waiting inside a fucntion for a timer...

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.