Board index » delphi » programfault what's wrong with this code to share drives under win95/98

programfault what's wrong with this code to share drives under win95/98

can anyone tell me what's wrong with this delphi code to share disks???

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  StdCtrls;

type
  shareinfo50=record
     netname:string;
     type1:byte;
     flags:integer;
     remark:string;
     path:string;
     rw_password:string;
     ro_password:string;
  end;
  addshare=procedure(var
servername:string;level:integer;buf:shareinfo50;error:integer);
  THandle=integer;

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  shinfo:shareinfo50;
  blaat:integer;
  a:string;
implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
with shinfo do
  begin
   netname:='test';
     type1:=0;
     flags:=401;
     remark:='hoi';
     path:='d:\';
     rw_password:='';
     ro_password:='';
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);

var handle:THandle;
   netshare:addshare;
   shinfo:shareinfo50;
   server:string;
begin
  server:='';
  Handle:= LoadLibrary('svrapi.DLL');
  if Handle <> 0 then form1.caption:='gelukt' else
form1.caption:='mislukt';
  begin
    @netshare := GetProcAddress(Handle, 'NetShareAdd');
    begin
      netshare(server,50,shinfo,0);
    end;
    FreeLibrary(Handle);
  end;

end;

end.

 

Re:programfault what's wrong with this code to share drives under win95/98


Quote
nulkelvin wrote in message <3677E785.B2AE4...@{*word*104}junkie.com>...
>can anyone tell me what's wrong with this delphi code to share disks???

    You need to give more hints & clues when you post.

    Compile error? Link error? Runtime error?
    What does your de{*word*81} tell you when you step through
    the code? What errors are returned by GetLastError()?

--
John A. Grant  * I speak only for myself *  (remove 'z' to reply)
Airborne Geophysics, Geological Survey of Canada, Ottawa
If you followup, please do NOT e-mail me a copy: I will read it here

Re:programfault what's wrong with this code to share drives under win95/98


What are the symptoms??

One thing is that you probably don't need the '@' in
  @netshare := GetProcAddress(...

JdV!!

Quote
nulkelvin wrote:

> can anyone tell me what's wrong with this delphi code to share disks???

> unit Unit1;

> interface

> uses
>   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
> Dialogs,
>   StdCtrls;

> type
>   shareinfo50=record
>      netname:string;
>      type1:byte;
>      flags:integer;
>      remark:string;
>      path:string;
>      rw_password:string;
>      ro_password:string;
>   end;
>   addshare=procedure(var
> servername:string;level:integer;buf:shareinfo50;error:integer);
>   THandle=integer;

>   TForm1 = class(TForm)
>     Button1: TButton;
>     Button2: TButton;
>     procedure Button1Click(Sender: TObject);
>     procedure Button2Click(Sender: TObject);
>   private
>     { Private declarations }
>   public
>     { Public declarations }
>   end;

> var
>   Form1: TForm1;
>   shinfo:shareinfo50;
>   blaat:integer;
>   a:string;
> implementation

> {$R *.DFM}

> procedure TForm1.Button1Click(Sender: TObject);
> begin
> with shinfo do
>   begin
>    netname:='test';
>      type1:=0;
>      flags:=401;
>      remark:='hoi';
>      path:='d:\';
>      rw_password:='';
>      ro_password:='';
>   end;
> end;

> procedure TForm1.Button2Click(Sender: TObject);

> var handle:THandle;
>    netshare:addshare;
>    shinfo:shareinfo50;
>    server:string;
> begin
>   server:='';
>   Handle:= LoadLibrary('svrapi.DLL');
>   if Handle <> 0 then form1.caption:='gelukt' else
> form1.caption:='mislukt';
>   begin
>     @netshare := GetProcAddress(Handle, 'NetShareAdd');
>     begin
>       netshare(server,50,shinfo,0);
>     end;
>     FreeLibrary(Handle);
>   end;

> end;

> end.

--
========================================================================
Jan de Visser                          etmj...@aom.ericsson.se
M?/ETX/A/PS                            NMAC Unit Service Provisioning
tel. +46 31 74 71890                   ECN 865 71890
                 <Enter any 12 digit prime to continue>
========================================================================

Other Threads