Thread in driver

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Actually I would like to create a driver which I can pass a function
pointer in. And the driver is able to do the callback whenever there
is an interrupt. Here is my program...

File Driver_Main.c

void SomeISTThread()
{
while (TRUE)
{
/* Wait for the application event to be released */
WaitForSingleObject(Somevent, INFINITE);
Callback();
InterruptDone(SomeIntr);
}
}

BOOL WINAPI DllEntry(HANDLE hInstDll, DWORD dwReason, LPVOID
lpvReserved)
{
SomeThread = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE)SomeISTThread,
NULL, 0, NULL);
return TRUE;
}

File Callback.c

PVOID callback_function = NULL;

void Callback()
{
if (callback_function != NULL)
callback_function();
}

void Add_Callback(PVOID callback)
{
callback_function = callback;
}

BOOL Is_CallbackExist()
{
return (callback_function != 0);
}

In debug mode I can see that my callback pointer is passed into the
driver. I can call the callback from the driver. However when an
interrupt is triggered. The function Callback reported that the
callback_function is NULL (which I saw the same result from debug
mode).

P.S. I already passed a function pointer in the variable
callback_function. And I am able to call the callback function from my
application program.

Thanks for the help
.



Relevant Pages

  • Re: [RFC] timers, pointers to functions and type safety
    ... * they have callback of type void ... callback is called by the code that even in theory has no ... cast to unsigned long and cast back in the callback. ... number - not a pointer cast to unsigned long, not an index in array, etc. ...
    (Linux-Kernel)
  • Re: function pointer help!
    ... //the return void and input prameters are defined in the manual... ... void MyProjectView::CallHandler(int,unsigned int, unsigned int, void*) ... You are attempting to use a C++ member function as the callback, but the callback is defined in terms or C, not C++. ... The underlying problem is that C++ functions receive a hidden parameter, the 'this' pointer, so their signature is incompatible with C definitions. ...
    (microsoft.public.vc.mfc)
  • Re: legality of signature changes of callback functions
    ... Suppose that some type of callback function is declared ... to take a pointer to some struct as one of its argument. ... taking a void* for this argument. ... converts it to a Something* to add type information. ...
    (comp.lang.c)
  • Re: Global restricted function pointer
    ... void; ... I _can_ declare a global restricted object pointer, ... And even if it did, you do *not* want it optimized into a register, ... I.E. each callback returns the next callback instead of ...
    (comp.lang.c)
  • Re: Custom filter
    ... You expect a function pointer so better be safe and tell the ... STDMETHODIMP CPrintPressFilter::Setcallback(void* Callback) ... public delegate void MyCallback; ...
    (microsoft.public.win32.programmer.directx.video)