Board index » delphi » Delphi 2.0 / win 95 API question

Delphi 2.0 / win 95 API question

Good evening all,

I have a small problem.  Seems in going from 1.0 to 2.0, I can't call a windows
API correctly to save my soul.  Each time I code one, I get a message "De{*word*81}
Kernel Error.  Error Code : 1".  A simple example is:

unit Unit1;


  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    { Private declarations }
    { Public declarations }

  Form1: TForm1;
function TimeGetTIme : DWORD;

{$R *.DFM}

Function TimeGetTime : dword; External 'Kernel32' Name 'TimeGetTime';

procedure TForm1.Button1Click(Sender: TObject);
var x : dword;

x := TimeGetTime;

This looks the same as kernel calls I have seen in the Windows unit in the RTL
source code.  I can't figure it out.  Anyone you can help, I would really
appreciate it.  Also, just where am I supposed to look up "Error Code 1"?



Re:Delphi 2.0 / win 95 API question

In article <4jt2sh$>, (Doug Farmer) wrote:

>function TimeGetTIme : DWORD;

>{$R *.DFM}

>Function TimeGetTime : dword; External 'Kernel32' Name 'TimeGetTime';

>procedure TForm1.Button1Click(Sender: TObject);
>var x : dword;

>x := TimeGetTime;

For one thing, timeGetTime is in the MMSYSTEM.DLL, not KERNEL32.  You could
just write "uses MMSystem" to import this function.  Also, you need to put
"stdcall;" after the interface declaration so Delphi will pass values on the
stack, instead of in registers as is the default.

De{*word*81} kernel error 1 is (I think) given when there is an invalid link to a
DLL in your Delphi program.  Nice error message, huh?

Steven E. Hugg

Re:Delphi 2.0 / win 95 API question

There are couple of things here...
'TimeGetTime' is in 'winmm.dll'
not in 'kernel32'.
Secondly,  "stdcall" directive has to be included in
proc definition.
(.. i know, not obvious from the manuals..)

StdCall is used for normal Win32 API calling convention
(using stack frame for params).

By default D2 will use new "register-passing"
(also known as("fastcall"); using registers instead of stack for params)
calling convention which I think can only be used for Delphi to Delphi
linkage(ea D2's EXE calling D2 Dll).

Some C++ compilers(Symantec, Borland..) also support this calling convention
but I'm not sure that the use of registers will actually match the one in

For your particular instance it doesn't matter(you don't have any params).
But in the future  I hope you'll find this info useful.

Corrections to your code(marked with '>>><<<')
(I checked them, runs fine(NT 4.0beta, didn't check others)):

function TimeGetTime : DWORD; >>>stdcall<<<;
Function TimeGetTime : dword; External >>>'winmm.dll'<<< name 'timeGetTime';

Another thing if you find that after you start the program de{*word*81} just sits
at the first 'begin' in your program
And after you hit continue generates some {*word*99}py error message(differs between
NT 3.51, NT 4.0b & 95) it probably means that was a problem loading the program
in Windows. So just try to run executable from Explorer or File Manager and that
will give much more informative error message like 'DLL is not found' e.t.c

Other Threads