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 - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Program HWprofile;
uses
windows;
const
HW_PROFILE_GUIDLEN = 39;
MAX_PROFILE_LEN = 80;
type
tProfileInfo = packed record
Docked : dword;
GUID : array[0..HW_PROFILE_GUIDLEN-1] of char;
Name : array[0..MAX_PROFILE_LEN-1] of char;
end;
var
Profile : TProfileInfo;
Results : boolean;
(*=======================================================================*)
Function GetCurrentHwProfile (var HWProfile: TProfileInfo): LongBool;
stdcall; 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.
