Click here to Skip to main content
15,888,263 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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...
GeneralRe: DLL with a callback Pin
Richard MacCutchan16-Apr-21 4:33
mveRichard MacCutchan16-Apr-21 4:33 
GeneralRe: DLL with a callback Pin
Bodo240716-Apr-21 4:46
Bodo240716-Apr-21 4:46 
GeneralRe: DLL with a callback Pin
Richard MacCutchan16-Apr-21 5:32
mveRichard MacCutchan16-Apr-21 5:32 
Questionmac desing: Pin
prasad 202114-Apr-21 23:09
prasad 202114-Apr-21 23:09 
AnswerRe: mac desing: Pin
Richard MacCutchan14-Apr-21 23:12
mveRichard MacCutchan14-Apr-21 23:12 
AnswerRe: mac desing: Pin
Dave Kreskowiak15-Apr-21 4:35
mveDave Kreskowiak15-Apr-21 4:35 
AnswerRe: mac desing: Pin
David Crow15-Apr-21 5:39
David Crow15-Apr-21 5:39 
QuestionEACCES when not running under VS debugger Pin
ForNow11-Apr-21 10:10
ForNow11-Apr-21 10:10 
AnswerRe: EACCES when not running under VS debugger Pin
Richard MacCutchan11-Apr-21 21:27
mveRichard MacCutchan11-Apr-21 21:27 
GeneralRe: EACCES when not running under VS debugger Pin
ForNow12-Apr-21 1:34
ForNow12-Apr-21 1:34 
GeneralRe: EACCES when not running under VS debugger Pin
Richard MacCutchan12-Apr-21 1:52
mveRichard MacCutchan12-Apr-21 1:52 
GeneralRe: EACCES when not running under VS debugger Pin
ForNow12-Apr-21 2:02
ForNow12-Apr-21 2:02 
Questionuse of dependent type name must be prefixed Pin
_Flaviu1-Apr-21 7:02
_Flaviu1-Apr-21 7:02 
AnswerRe: use of dependent type name must be prefixed Pin
Greg Utas1-Apr-21 8:00
professionalGreg Utas1-Apr-21 8:00 
GeneralRe: use of dependent type name must be prefixed Pin
_Flaviu1-Apr-21 8:25
_Flaviu1-Apr-21 8:25 
GeneralRe: use of dependent type name must be prefixed Pin
Greg Utas1-Apr-21 10:50
professionalGreg Utas1-Apr-21 10:50 
GeneralRe: use of dependent type name must be prefixed Pin
_Flaviu1-Apr-21 19:34
_Flaviu1-Apr-21 19:34 

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.