[fpc-pascal]Win32 API Call

Michalis Kamburelis michalis at camelot.homedns.org
Tue Jun 22 06:00:21 CEST 2004


Hi

You made a few mistakes translating GetCurrentHwProfile to Pascal:

1. parameter to GetCurrentHwProfile should be TProfileInfo, not 
PProfileInfo (using "var" parameter already forces passing HWProfile by 
reference)

2. result of GetCurrentHwProfile should be LongBool (4 bytes), not 
boolean (1 byte)

3. most important, TProfileInfo.GUID and TProfileInfo.Name are not 
AnsiStrings. They are just char arrays, see attached code for correct 
declararions.

4. This is not important for FPC 1.0.x, but for newer FPC remember to 
declare WinAPI functions as "stdcall" (FPC 1.0.x just used "stdcall" by 
default).

I'm attaching corrected version of your program. On my Windows 2000 Prof 
it works fine compiled with FPC 1.0.10.

Regards,
-- 
Michalis

Jim Wilson wrote:
> I'm trying to get a Win32 API call to work, but either I found a bug in 
> FPC (not likely) or I'm doing something wrong (more then likely).
> 
> There's an API function called GetCurrentHwProfile that doesn't seem to 
> be recognized by FPC, so I added it myself using external. However, when 
> I try calling the function I don't seem to be getting anything returned. 
> I tried checking the Windows GetLastError function, but that doesn't 
> show me anything either.
> 
> I've included some code that shows what I mean. It's a text mode 
> program, compiled under Windows 2000 using FPC version 1.0.6 with the 
> command line of: ppc386 -TWin32 -vehnw -WC -XX -Sd
> 
> Since I doubt FPC has a bug I'm assuming it's me. Or is it?
> 
> ********************************************
> 
> Program HWprofile;
> 
> uses
>   windows;
> 
> type
> 
>   tProfileInfo = packed record
>                    Docked : dword;
>                    GUID   : ansistring;
>                    Name   : ansistring;
>                  end;
> 
>   pProfileInfo = ^tProfileInfo;
> 
> var
>   Profile : pProfileInfo;
>   Results : boolean;
> 
> (*=======================================================================*)
> Function GetCurrentHwProfile (var HWProfile: pProfileInfo): boolean; 
> external 'advapi32' name 'GetCurrentHwProfileA';
> (*=======================================================================*)
> 
> BEGIN
> 
>   Results := GetCurrentHwProfile (Profile);
> 
>   if not (Results) then
>   begin
>     Profile.GUID := 'Unknown';
>     Profile.Name := 'Unknown';
>   end;
> 
>   writeln ('GUID   : ',Profile.GUID);
>   writeln ('Name   : ',Profile.Name);
>   writeln ('Results: ',Results,' - ',GetLastError);
> 
> END.
> 
> Regards,
> Jim Wilson
> 
> 
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> 

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: profile_info_corrected.dpr
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20040622/abfd86b1/attachment.ksh>


More information about the fpc-pascal mailing list