Board index » delphi » NETAPI.DLL Question

NETAPI.DLL Question

Can anyone tell me why the following code refuses to run, and
what I can do to fix it?

function NetGetDCName(Serv: PWideChar; Dom: PWideChar; Bufptr:
PWideChar):
  PWideChar; stdcall; external 'NETAPI' name 'NetGetDCName';

procedure TForm1.Button1Click(Sender: TObject);
var
  Servname, DomName,Locator: AnsiString;
begin
  Servname := 'BLUE1';
  DomName := 'BLUE';
NetGetDCName(PWideChar(Servname),PWideChar(DomName),
PWideChar(Locator));
  Edit1.Text := Locator;
end;

Every time I try to run this code, I get an error message.
The error message isn't always consistent. On Windows 95,
it tells me that NETAPI.DLL is corrupt (although when I
use the TDUMP utility I can see that the NETGETDCNAME function
is declared). When I run it on a Windows NT 4.0 workstation,
I get a message saying the application couldn't be started.

Any help would be most appreciated.

 

Re:NETAPI.DLL Question


Quote
Edward McSweeney wrote:

> Can anyone tell me why the following code refuses to run, and
> what I can do to fix it?

Actually, there are a couple of problems: First is in the declaration of
the function

Quote
> function NetGetDCName(Serv: PWideChar; Dom: PWideChar; Bufptr:
> PWideChar):
>   PWideChar; stdcall; external 'NETAPI' name 'NetGetDCName';

should be 'NETAPI32' not 'NETAPI'

Quote
> procedure TForm1.Button1Click(Sender: TObject);
> var
>   Servname, DomName,Locator: AnsiString;
> begin
>   Servname := 'BLUE1';
>   DomName := 'BLUE';
> NetGetDCName(PWideChar(Servname),PWideChar(DomName),
> PWideChar(Locator));

second, the VCL is not WideChar compatible, so before you can assign the
Edit1.Text property, you should convert the WideChar to an ANSIChar
(WideCharToString function, or WideCharToMultiByte API call, if you
prefer)

Quote
>Edit1.Text := Locator;

NETAPI.DLL is, I believe, a 16-bit DLL and hence would appear as corrupt
in a 32-bit program that imports it.

Dave Heinecke

Re:NETAPI.DLL Question


On Fri, 13 Dec 1996 10:59:02 -0600, Edward McSweeney

Quote
<emcswee...@mayo.edu> wrote:
>Can anyone tell me why the following code refuses to run, and
>what I can do to fix it?

>function NetGetDCName(Serv: PWideChar; Dom: PWideChar; Bufptr:
>PWideChar):
>  PWideChar; stdcall; external 'NETAPI' name 'NetGetDCName';

>procedure TForm1.Button1Click(Sender: TObject);
>var
>  Servname, DomName,Locator: AnsiString;
>begin
>  Servname := 'BLUE1';
>  DomName := 'BLUE';
>NetGetDCName(PWideChar(Servname),PWideChar(DomName),
>PWideChar(Locator));
>  Edit1.Text := Locator;
>end;

Every time I try to run this code, I get an error message.

Quote
>The error message isn't always consistent. On Windows 95,
>it tells me that NETAPI.DLL is corrupt (although when I
>use the TDUMP utility I can see that the NETGETDCNAME function
>is declared). When I run it on a Windows NT 4.0 workstation,
>I get a message saying the application couldn't be started.

>Any help would be most appreciated.

You need to use StringToWideChar to conver the strings.

Other Threads