Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-08

Missing Win32 API Function -- Part 2

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Okay, after some playing around I'm fairly convinced that the reason I can't get any information returned from this Win32 function has something to do with FP. I made some mods to the test file and it now compiles with TMT, Virtual Pascal and FP. The only binary that gives me problems is the one compiled with FP -- the other 2 work properly.

Now, I've run into a number of compatibility issues with these 3 compilers before, so a glitch between what works for one and what works for another isn't uncommon, but this discrepancy seems to be different. Any ideas what I'm doing wrong here?

TIA...

Jim

Reply by email

Michał Bartoszkiewicz
to Unknown author
Now, I've run into a number of compatibility issues with these 3 compilers before, so a glitch between what works for one and what works for another isn't uncommon, but this discrepancy seems to be different. Any ideas what I'm doing wrong here?

1. You call Unicode version of the function - you probably want to call EnumPrintersA

2. You call the function from wrong library - correct is 'winspool.dll'

3. You call the function with invalid calling convention - you should use 'stdcall' for API functions

4. API functions don't return Booleans but Bools

The correct declaration would be:
Function EnumPrinters (Flags: dword; Name: pchar; Level: dword; pPrinterEnum: pointer;
         cbBuf: dword; var pcbNeeded, pcReturned: dword): bool; stdcall;
         external 'winspool' name 'EnumPrintersA';
__ ______________________________________________________________ | \/ | Michał Bartoszkiewicz | _ ) | |\/| | GG:2298240 ICQ:63168292 | _ \ |_| |_|_____Keyboard not detected. Press F1 to continue.______|___/

Reply by email

Unknown author

Thanks for the reply...

1. You call Unicode version of the function - you probably want to call EnumPrintersA

EnumPrinertsW is the unicode version of the function? I wasn't aware of that. I'll make this change.

2. You call the function from wrong library - correct is 'winspool.dll'

I don't have winspool.dll anywhere on my hard drive, but I do have winspool.drv. I used my editor to look inside that file and found winspool.drv has EnumPrintersA as a function. When I use that everything seems to work properly. I'm using Win2K.

3. You call the function with invalid calling convention - you should use 'stdcall' for API functions

I added this, but it didn't seem to make any difference. I also checked both the Win32 API Reference and the FPC docs, but there's not a whole lot of info on stdcall. What does it do?

4. API functions don't return Booleans but Bools

I checked the Win32 API Reference and the FPC docs for bools as well, but there's nothing mentioned. What's the difference between the two?

Jim

Reply by email

Michał Bartoszkiewicz
to Unknown author
EnumPrinertsW is the unicode version of the function? I wasn't aware of that. I'll make this change.

If function has two versions then name of the Unicode version ends in "W" (Wide) and name of the non-Unicode version ends in "A" (Ansi)

I added this, but it didn't seem to make any difference. I also checked both the Win32 API Reference and the FPC docs, but there's not a whole lot of info on stdcall. What does it do?

API uses slightly different method for calling functions than FPC does, so you need to tell the compiler that it has to generate special code.

I checked the Win32 API Reference and the FPC docs for bools as well, but there's nothing mentioned. What's the difference between the two?

Boolean variables takes 1 byte and can contain one of two values - True or False Bool variables take 4 bytes and can contain any 32-bit integer - 0 means False, any other value means True.

__ ______________________________________________________________ | \/ | Michał Bartoszkiewicz | _ ) | |\/| | GG:2298240 ICQ:63168292 | _ \ |_| |_|__________Draco Dormiens Nunquam Titillandus___________|___/

Reply by email

Full_Name
to Michał Bartoszkiewicz: 1. You call Unicode version of the function - you probably want to call EnumPrintersA 2.…

Quoting Micha³ Bartoszkiewicz :

Show quoted text 6 lines
The correct declaration would be: Function EnumPrinters (Flags: dword; Name: pchar; Level: dword; pPrinterEnum: pointer; cbBuf: dword; var pcbNeeded, pcReturned: dword): bool; stdcall; external 'winspool' name 'EnumPrintersA';

This is basically what Delphi 5 uses too, so I would have to concur. I didn't use your declaration when I tested it (silly of me) I just used 'winspool' and the function was defined already. The above declaration with your original code works in Delphi anyway.

Matt

"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." Kristian Wilson, Nintendo, Inc, 1989 -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GCS d? s+++:+ a- C++ UL+ P L++ E---- W- N+ o+ K- w O- M V PS PE-- Y PGP- t- 5-- X- R- tv+ b+ DI++ D+ G e++ h--- r+++ y+++ ------END GEEK CODE BLOCK------

Reply by email

Unknown author
Micha;

Thanks for the info -- that was very helpful.

Where did you learn about how to develop programs using the Win32 functions? I've been experimenting with more elaborate programs lately and have found myself confronting one obstacle after another. For example, I've came across another function related to printers that wants a "handle" passed to it. As usual, the Win32 API Reference provides no help. I looked through a lot of the RTL source code to see if I can figure it out, but I can't. I'd like to find a reference, or some web site, where I can learn about these things so I can make my wonderful programs even better! :-)

Jim

Reply by email

Marco van de Voort
to Unknown author
Show quoted text 11 lines
Thanks for the info -- that was very helpful. Where did you learn about how to develop programs using the Win32 functions? I've been experimenting with more elaborate programs lately and have found myself confronting one obstacle after another. For example, I've came across another function related to printers that wants a "handle" passed to it. As usual, the Win32 API Reference provides no help. I looked through a lot of the RTL source code to see if I can figure it out, but I can't. I'd like to find a reference, or some web site, where I can learn about these things so I can make my wonderful programs even better! :-)

When I created the service example (mental note: clean up and commit it), I also had this problem.

[humor mode on]
The solution is to think as a VB programmer.

I know, that is a big step, but you really have to leave the fundamental idea that _you_ can logically reason how the program is going to work, and just try to copy and paste random related code you find on the net, and link them together.

Good resources are:
- Delphi helpfiles (download on Borlands site)
- Microsoft Platform SDK (Microsoft site, needs recent IE to download, was quite some trouble to get it (1GB)) (helpfiles + the original Win32 headers)
- Google (throw a function name in it, see what it comes up with. Even if it is C or VB code, study it). Can't be overestimated, since it is typically
- Any related win32 project for which sourcecode is available. (which is nearly synonymous with Open Source) like
- Existing headers (Jedi, FPC sources etc), and crossreferencing them)
- Delphi code, but not really much is available with sourcecode
- Cygwin and projects that depend on it.
- FPC demo's and FCL source. GPC win32 stuff (from the Chief)in theory too, but haven't used it yet.

I also used the win32 Apache sourcecode, since that seemed to be the only opensource service that used win2000 extensions, but that was something specific to this project I think.

Reply by email