[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Implementing SetTimer from ISAPI Filter DLL

Posted on 1997-07-18
10
Medium Priority
?
532 Views
Last Modified: 2006-11-17
I'm trying to set up a timer callback function with SetTimer in an ISAPI Filter DLL. In the CWinApp Constructor, I call SetTimer passing it the address of my TimerProc => SetTimer(NULL,NULL,300,TimerProc);

the TimerProc is defined as Follows:

extern "C" void CALLBACK EXPORT TimerProc(HWND hWnd,UINT nMsg,UINT nEvt, DWORD dwSysTime);

the SetTimer gets called but TimerProc doesn't ever get called.)

This one's worth all the points I have.
0
Comment
Question by:vince123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 3

Accepted Solution

by:
jaba earned 800 total points
ID: 1165346
How is timer working ? When you installing timer ( even without hwnd param and with callback function) it implementing by the messages. I.e.  you message loop translating message to call of this callback funtion. Timer even ( event when you xalling SetTimer without hwnd param) is a WM_TIMER message. You callback function calling while TranslateMessage function processing. So , you cant get timer without message loop. You ISAPI dll dont have it :-( So , ther is 2 solutions of you problem:
1 - create message loop ( but its not good solution)
2 - Uee Sleep funtion as shown in sampel below :
do {
[You processing code ]
Sleep(1000 ) ; // waiting 1 second
} while (...) ;

This methodis best because it dont eat processor resources while waiting next event

0
 

Author Comment

by:vince123
ID: 1165347
   I think this is still a problem. where would you have me put the sleep call? if in the OnAuthentication method, every request would end up calling the cleanup function. Conversely when there were no requests to the server, the function wouldn't run. Both undesirable situations. I'll try to clarify the scenario.
    An Isapi filter DLL for authentication will get called for every request that comes to the server. My routine must decide to allow the request or deny. User information is stored in SQL Server. It wouldn't be feasible to check the database every request. A single page of html with a dozen graphics would generates 13 requests. To make the process more efficient I maintain in memory a linked list of user objects which have already been authenticated. Each time they make a request, a time field in the user object is updated. If the user object is not updated within a certain time, they are removed from the list and would again have to be authenticated against the database in order to regain entry. I need for the timer function to run at an interval that I specify, without needing to be triggered by a client request. Imagine that I wish to examine the list once a minute and remove every user idle for longer than 15 minutes. If no requests come in for 4 or 5 minutes, I have no way to force the cleanup function to run.
0
 
LVL 3

Expert Comment

by:jaba
ID: 1165348
Nice scenario. You need to create idle thread while initialization of DLL and write somthing like this :
DWORD WINAPI MyIdleCleaner( LPVOID pParam)
{
   do {
    // Do my list cleaning  checks
   // Dont forget about syncronization
   Sleep(1000);
   } while (...)
}

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 3

Expert Comment

by:jaba
ID: 1165349
Obvious, MyIdleCleaner function start working after CreateThread call :-)
Do this call in DllMain on DLL_PROCESS_ATTACH .
Good luck
0
 

Author Comment

by:vince123
ID: 1165350
I like where you're headed with this, but did we switch to Win32? Remember I'm doing this with MFC and I don't have access to DllMain, or do I??? If I do, I'll try and do that and give you the points. I think, though, that I probably need to override something in CWinApp, can you clarify this?.

BTW, I know I'm making you work for these points, but this is the last part of my project before I wrap the current release. :)
0
 
LVL 3

Expert Comment

by:jaba
ID: 1165351
I am sorry , i forgot about MFC usage :-)
When you created ISAPI project , thewr is CWinApp object in you CPP file. You need create new class , derived from CWinApp , override InitInstance function and start you idle thred in it.
Like this :
class CMyISapi : public CWinApp {
public :
virtual BOOL InitInstance( );
};

BOOL CMyISapi::InitInstance()
{
CWinApp::InitInstance();
DWORD id;
CreateThread(NULL , 0 , MyIdleFunc , 0 , 0 , &id);
}


0
 

Author Comment

by:vince123
ID: 1165352
OK we're almost there I think. if we derive from CWinApp, is it better to create an idle thread or override CWinApp::OnIdle() ?
0
 
LVL 3

Expert Comment

by:jaba
ID: 1165353
Dont forget change
CWinApp theApp;
to CMyApp theApp; in you source code.
About OnIdle. This function never be called in DLL :-(
This function calling by CWinApp Run function when message loop empty. DLLs have no message loop and Run method not calling in DLLs .
0
 

Author Comment

by:vince123
ID: 1165354
ok, jaba, one more clarification and you get all the points and an A!

i'm using create thread just like you said but I get very strange compilation errors about not being able to convert the parameter to unsigned long (__stdcall *)(void *). I've tried to declare MyIdleFunc every way I can think of and it doesn't match up.
0
 

Author Comment

by:vince123
ID: 1165355
ok, jaba, never mind the implementation stuff, i figured that out on my own. you get the points and an A.

Ray@vbnetwork.com
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question