SetTimer and Dll

Hello All,

    I'm developing a DLL, and I need a timer to check some events. I could use VCL TTimer, but DLL becomes too large, then I try to use SetTimer and KillTimer Win32 API, but it don't works well. Could someone tell me/show me an example about how to use SetTimer and how to define TimerProc callback?? OBS : My application don't have forms. I read Win32 reference and it says that the window handle can be NULL, but don't works too.

                                 Tanks in advance.



                                              Oberdan




















 
oberdanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
What's wrong with the callback proc? It should work fine unless you have wrongly declared the callback procedure. Important: it must be declared with calling convention stdcall:

prcoedure MyCallback(Wnd: HWND; uMsg: Cardinal; iEvent: Cardinal; dwTime: DWORD); stdcall;

begin
  // your stuff here
end;

Ciao, Mike
0
ITugayCommented:
Hi oberdan!

I have no idea why it happen. But sample bellow is working.

//*********** LIBRARY ***************
library p_dll;
uses  Windows;

var T : integer;

procedure DoSomething(hWnd: HWND; Msg,TimerID: Word; SysTime: LongInt); StdCall;
var F : Text;
begin
    assign(F,'c:\000.txt');
    rewrite(F);
    writeln(F,Msg,' ',TimerID,' ',SysTime);
    CloseFile(F);
end;

procedure InitTimer; stdcall;
begin // interval 2 sec
  T:=SetTimer(0,0,2000,@DoSomething);
end;

procedure DoneTimer; stdcall;
begin
  KillTimer(T,0);
end;

exports
   InitTimer,
   DoneTimer;
begin

end.



//************* PROJECT ************
program CALL_DLL;

uses
  ShareMem,
  Forms,
  Windows;

procedure InitTimer; external 'p_dll.dll';
procedure DoneTimer; external 'p_dll.dll';

var WaitFor : integer;
begin
   Application.Initialize;
   WaitFor:=GetTickCount+5000; // 5 sec to work
   InitTimer;
   while GetTickCount < WaitFor do Application.ProcessMessages;
{let windows to do any deals}
   DoneTimer;
end.

//********** END ***********

Best regards.

Igor.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LischkeCommented:
Igor, this was not fair. You gave essentially the same information as I but locked the question although you could see I was already discussing...

Please be so kind in the future and work only with comments unless you are the very first one in a thread or noone else can give further information and you have the solution.

Thank you, Mike
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

LischkeCommented:
Btw: your code is Delphi 1 stuff, right?
0
oberdanAuthor Commented:
Hello,

     I read the comments and the answer, and my code is the same as showed here. But I discover my error (and was a very, very stupid error). My call to SetTimer was right, and my callback was right too. The problem was on my Timer Handler. I'm using one pointer to a record with several Handlers and different data types, including the Timer handler. I forgot to initilize the pointers with "new". So, I was passing a null pointer to SetTimer, and my program blows. Your code show me that the error was not on the clock creation as I was thinking (it's the first time I try to do it).


                                        Very tanks,

                                                   Oberdan
   
0
ITugayCommented:
To  Lischke.

Sorry, I was sure that I'm first. (I'm new here).

By.

Igor
0
LischkeCommented:
Mmmh, Oberdan already argued why (s)he still picked your contribution and finally, well, it's always up to the questioneer to pick one solution. I just wanted to let you know for the future :-)

Ciao, Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.