I tried converting this win32 hello.c program to pascal without success...
#include <windows.h>
int STDCALL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) { MessageBox (NULL, "Hello, Windows!", "Hello", MB_OK); return 0; }
I was getting undefined references to messagebox at the linking stage. To compile I did...
gpc -mno_cygwin -mwindows whello.pas -o whello.exe
Thanks,
Mark.
-- Mark Taylor, Department of Corporate Information & Computing Services, Extension 21145. (0114) 222 1145 http://www.shef.ac.uk/misc/personal/ad1mt
The opinions expressed in this email are mine and not those of the University of Sheffield.
Mark Taylor wrote:
#include <windows.h>
int STDCALL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) { MessageBox (NULL, "Hello, Windows!", "Hello", MB_OK); return 0; }
I was getting undefined references to messagebox at the linking stage. To compile I did...
gpc -mno_cygwin -mwindows whello.pas -o whello.exe
This was a nice example in C. But how does your whello.pas look like?
Peter
On 9 Mar 00, at 11:15, Mark Taylor wrote:
I tried converting this win32 hello.c program to pascal without success...
[...]
You need to import the WinAPI functions before you can call them. e.g., {$define WINAPI(X) asmname X; attribute(stdcall)}
FUNCTION GetModuleHandle ( lpModuleName : PChar ) : Integer; WINAPI ( 'GetModuleHandleA' );
This involves translating the C headers into Pascal. I have been working for more than a year on some units to import whole chunks of the WinAPI (e.g., messages, wintypes, and winprocs) - but of course I don't have too much free time, so the work is progressing slowly. Having said that, more than 80% of the API has already been converted (I wrote a little program to help automate some of the work), although I have not tested and cannot test everything. For precompiled versions of these units, get the file; ftp://agnes.dida.physik.uni-essen.de/home/chief/units.zip and extract wintypes.*, winprocs.* and messages.* from it. Put them in a directory that is accessible to the GPC compiler (preferably the 'units' subdirectory), and then you can do something like this;
program hello; uses messages, wintypes, winprocs; begin MessageBox (0, 'Hello World.', 'Greetings', mb_ok); end.
BTW: if anyone is willing to help in completing work on these units, then just drop me a line.
[...]
To compile I did...
gpc -mno_cygwin -mwindows whello.pas -o whello.exe
You mean '-mno-cygwin'.
Best regards, The Chief ----- Dr Abimbola A Olowofoyeku (The African Chief) Email: African_Chief@bigfoot.com Author of Chief's Installer Pro v5.22 for Win32 http://www.bigfoot.com/~African_Chief/chief32.htm
Subject: Re: How to compile hello.pas for win32
You need to import the WinAPI functions before you can call them.
I knew this was necessary, but did not know the syntax - is it documented anywhere? I looked for it (honestly) but couldn't find it. I must admit I didn't look in the info database, because I assumed that this would be so win32 specific it wouldn't be there.
e.g., {$define WINAPI(X) asmname X; attribute(stdcall)}
FUNCTION GetModuleHandle ( lpModuleName : PChar ) : Integer; WINAPI ( 'GetModuleHandleA' );
Are you saying I can do c-style #defines in a pascal program using a syntax like this?
{$define macro definition}
Presumably these get fed through to the back-end c-preprocessor? Are there any other obscure "features" like this in GPC that I might need to know about?
ftp://agnes.dida.physik.uni-essen.de/home/chief/units.zip and extract wintypes.*, winprocs.* and messages.* from it. Put them in a directory that is accessible to the GPC compiler (preferably the 'units' subdirectory), and then you can do something like this;
program hello; uses messages, wintypes, winprocs; begin MessageBox (0, 'Hello World.', 'Greetings', mb_ok); end.
I will download these, and try again tonight.
You mean '-mno-cygwin'.
Yes I do mean -mno-cygwin (email typo, not a command line typo!)
BTW: if anyone is willing to help in completing work on these > >
units, then just drop me a line.
I will be in a position to help, once I have progressed from being a novice GPC user!
Many thanks for your help.
Mark.
-- Mark Taylor, Department of Corporate Information & Computing Services, Extension 21145. (0114) 222 1145 http://www.shef.ac.uk/misc/personal/ad1mt
The opinions expressed in this email are mine and not those of the University of Sheffield.
On 9 Mar 00, at 15:08, Mark Taylor wrote:
Subject: Re: How to compile hello.pas for win32
You need to import the WinAPI functions before you can call them.
I knew this was necessary, but did not know the syntax - is it documented anywhere? I looked for it (honestly) but couldn't find it. I must admit I didn't look in the info database, because I assumed that this would be so win32 specific it wouldn't be there.
The syntax for importing routines from the C libraries is documented (I can't remember where). As for the syntax for importing routines from the WinAPI, it is more or less the same as that for importing libc routines - but you need to declare them with the 'stdcall' attribute. You also need to use the 'asmname' directive, especially where the alias (imported name) of the routine is different from what it is called inside the Windows DLLs, but also because there are often two versions of a Win32 API call - one for ansi characters (ending with 'A' as in the 'GetModuleHandleA' example that I gave) and the other for wide (unicode) characters, ending in 'W' - and you need to specify which one you want.
e.g., {$define WINAPI(X) asmname X; attribute(stdcall)}
FUNCTION GetModuleHandle ( lpModuleName : PChar ) : Integer; WINAPI ( 'GetModuleHandleA' );
Are you saying I can do c-style #defines in a pascal program using a syntax like this?
{$define macro definition}
Yes. And IIRC you can also use '#define macro definition'.
Presumably these get fed through to the back-end c-preprocessor?
Presumably. I believe that this is one of those things that GPC inherits from GCC.
Are there any other obscure "features" like this in GPC that I might need to know about?
Many (e.g., I guess you could do something like 'Var x : integer (40)' to declare a 40-bit integer (if such a thing exists) - but I am not sure how it will be handled by the compiler). I am not sure where they are all documented though. I obtain a lot of my information from the GPC source code.
BTW: if anyone is willing to help in completing work on these > >
units, then just drop me a line.
I will be in a position to help, once I have progressed from being a novice GPC user!
Ok. Let me know when you are ready!
Best regards, The Chief ----- Dr Abimbola A Olowofoyeku (The African Chief) Email: African_Chief@bigfoot.com Author of Chief's Installer Pro v5.22 for Win32 http://www.bigfoot.com/~African_Chief/chief32.htm