Sign in Join

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

Mailing lists / fpc-pascal / 2002-01

Win32 API function not working

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

I'm trying to compile a program using the Win32 API function GetComputerName, but when I do I get the message "Error: Can't determine which overloaded function to call". The string GetComputerName does not exist anywhere in my code, other then this one line where I attempt to call that function, so it's not being overloaded by me. :-)

If I call the function explicitly -- GetComputerName.WINDOWS -- I don't get the overload error but I do get these two messages "Error: Wrong amount of parameters specified" and "Fatal: Syntax error, ";" expected but "(" found". According to ascdef.inc the calling convention is "function GetComputerName(lpBuffer:LPSTR; nSize:LPDWORD):WINBOOL;".

The portion of my source code in question looks like this:

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 );

ppc386 -i says this:

Free Pascal Compiler version 1.1
Compiler Date : 2001/06/19
Compiler Target: i386

It's probably fairly obvious, but I sure can't see it. Can anyone see what I'm doing wrong here? TIA...

Jim

Reply by email

Unknown author
GetComputerName.Windows ? Windows.GetComputerName?

Yup, I missed that one. :-) I had it backwards in the code, and looked at it 10 times, but still didn't see that.

Unfortunately, that doesn't solve the problem. Calling the function properly (Windows.GetComputerName) still results in the same error "Can't determine which overloaded function to call". Any other ideas?

Thanks,
Jim

Reply by email

Kanzelsberger Pavel

Try GetComputerNameW

In Win32 libraries there are sometime more versions of procedures (ANSI, Unicode...)

Anyway do not use "Try & Compile" method, it's a time killer. Just download the RTL sources and check real procedure/function definition.

regards, Pavel Kanzelsberger

Earlier message 20 lines
-----Original Message----- From: Sent: Friday, January 25, 2002 1:49 PM To: Subject: Re: [fpc-pascal]Win32 API function not working > GetComputerName.Windows ? > Windows.GetComputerName? Yup, I missed that one. :-) I had it backwards in the code, and looked at it 10 times, but still didn't see that. Unfortunately, that doesn't solve the problem. Calling the function properly (Windows.GetComputerName) still results in the same error "Can't determine which overloaded function to call". Any other ideas? Thanks, Jim

Reply by email

Jonas Maebe
to Unknown author: I'm trying to compile a program using the Win32 API function GetComputerName, but when I…
Show quoted text 15 lines
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

Reply by email

Unknown author
Try GetComputerNameW. In Win32 libraries there are sometime more

versions of

procedures (ANSI, Unicode...)

Unfortunately, this function produces the same error, so I'm still stuck.

Anyway do not use "Try & Compile" method, it's a time killer. Just

download the RTL sources

and check real procedure/function definition.

I never develop in a "try & compile" manner. As you can tell from my original post I research what I want to do beforehand and then code. That's why I knew what was included in FPC's rtl and the Win32 API reference -- because I did do my homework. Perhaps it's something about this function I don't quite understand, or perhaps there's a bug in FPC, but whatever the ultimate answer is I can assure you that it won't be related to how much effort I put into determining what it was before I posted my question.

Jim

Reply by email

Unknown author
As Marco already pointed out, you have to use unitname.procedure().

This was merely an oversight on my part - I guess I should get a little more sleep :-)

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.

Yes, this I see now. I'll make the necessary changes to my program. Thanks for the help.

Jim

Reply by email