Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi All, I am trying to initializ

Status
Not open for further replies.

KCI

Programmer
Jun 30, 2003
39
DE
Hi All,

I am trying to initialize a timer within an ATL COM Service. I am having a little problem and I could use some help. This issue is about the CALLBACKS function.

I have wrapped the SetTimer and KillTimer around the Message loop like so:

// Start the timer before the message loop
UINT TimerId = ::SetTimer(NULL, ID_TIMER, 10000, TimerHit);

MSG msg;
while (GetMessage(&msg, 0, 0, 0))
DispatchMessage(&msg);

// Stop the timer after the message loop
::KillTimer(NULL, TimerId);

and I declared the CALLBACK like this:

void CALLBACK TimerHit(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
// Do some stuff
}

and I have this in the header file:

void CALLBACK TimerHit(HWND hwnd, UINT Msg, UINT idEvent, DWORD dwTime);

Other things in this app include ADO support. Other than that It is an off the self version of the ATL COM Wizard Service App. Some thing I did not understand was why I had to manually add the header file (SyncEmpS.h) for my main class (SyncEmpS.cpp) file.

When I compile I get the following:

Compiling...
SyncEmpS.cpp
C:\_Work\SyncEmpS\SyncEmpS.cpp(355) : error C2664: 'SetTimer' : cannot convert parameter 4 from 'void (struct HWND__ *,unsigned int,unsigned int,unsigned long)' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)'
None of the functions with this name in scope match the target type
Error executing cl.exe.

SyncEmpS.exe - 1 error(s), 0 warning(s)

Your thoughts or help would be greatly appreciated.

Best Regards,
KC
 
You could try by replacing
void CALLBACK TimerHit

with
void __stdcall TimerHit



/Per
[sub]Nerdy signatures are as lame as the inconsistent stardates of STTNG.[/sub]
 
/Per thanks for your response.

Yes, I did try your suggestion ... I was crossing my fingers as I hit F7. But it still did not work.

After a day of tinkering. I found the issue was related to where I (or C++) placed the following code.

void CALLBACK TimerHit(HWND hwnd, UINT Msg, UINT idEvent, DWORD dwTime);

I declared my function using "Add member function" and for some reason C++ put the above code in StdAfx.h ... remember I stated that C++ did not add SyncEmpS.h I had to add that myself.

Well, when I moved the above code into SyncEmpS.h it compiled fine. Go figure!

Thanks for your response I do appreciate it. And I will reciprocate your help by helping someone else. Maybe in the VB forum since I'm still a rookie here. ;)

Sincerely
KCI
 
// Start the timer before the message loop
UINT TimerId = ::SetTimer(NULL, ID_TIMER, 10000, [red]&[/red]TimerHit);

Please don't cross post


-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top