[fpc-pascal]Win32 API function not working

Jonas Maebe jonas at zeus.rug.ac.be
Fri Jan 25 14:21:58 CET 2002


On donderdag, januari 24, 2002, at 10:53 , James_Wilson at i2.com wrote:

> const
>   MAX_SIZE = 255;
>
> var
>   NullString : pchar;
>
> GetComputerName.WINDOWS (NullString,MAX_SIZE);
>
>
> The Win32 API reference looks pretty much the same:
>
> BOOL GetComputerName
> (
>     LPTSTR lpBuffer,        // address of name buffer
>     LPDWORD nSize         // address of size of name buffer

As Marco already pointed out, you have to use unitname.procedure(). the 
reason it doesn't work, is that the two declarations present in the 
windows unit are:

function GetComputerName(lpBuffer:LPSTR; nSize:LPDWORD):WINBOOL; 
external 'kernel32' name 'GetComputerNameA';
function GetComputerName(lpBuffer: PChar; var nSize: DWORD): 
BOOL;external 'kernel32' name 'GetComputerNameA';
function GetComputerName(lpBuffer:LPWSTR; nSize:LPDWORD):WINBOOL; 
external 'kernel32' name 'GetComputerNameW';

The reason it complains it can't decide which overloaded function to 
call, is because there is no version which expects an integer constant 
as third parameter, it's always either a pointer or a var parameter.


Jonas





More information about the fpc-pascal mailing list