[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 876
  • Last Modified:

What is lpBuffer ?

Using Delphi 3 Pro

I am trying to get info about files sytems/disks on network servers using
WNetEnumResource, however, I cannot find what type lpBuffer should be declared as.

Could anyone give me an example starting with WNetOpenEnum through WNetEnumResource to WNetCloseEnum.

Thanks

John
0
nohj
Asked:
nohj
1 Solution
 
RBertoraCommented:
lobuffer should be declared as a pointer

var
MyBuff : Pointer;
size : DWord;
begin
  size := 100; //size in bytes;
  MyBuff := allocmem(size);

Rob ;-)

P.S.
or you could just pass an array of char

0
 
kretzschmarCommented:
yup,
a lpBuffer is a pointer to an allocated memory-area
(must mostly allocated byself before use)
meikl ;-)
0
 
KECommented:
I suggest that you use the Delphi build-in structures:

  PNetResourceA = ^TNetResourceA;
  PNetResourceW = ^TNetResourceW;
  PNetResource = PNetResourceA;
  {$EXTERNALSYM _NETRESOURCEA}
  _NETRESOURCEA = packed record
    dwScope: DWORD;
    dwType: DWORD;
    dwDisplayType: DWORD;
    dwUsage: DWORD;
    lpLocalName: PAnsiChar;
    lpRemoteName: PAnsiChar;
    lpComment: PAnsiChar;
    lpProvider: PAnsiChar;
  end;
  {$EXTERNALSYM _NETRESOURCEW}
  _NETRESOURCEW = packed record
    dwScope: DWORD;
    dwType: DWORD;
    dwDisplayType: DWORD;
    dwUsage: DWORD;
    lpLocalName: PWideChar;
    lpRemoteName: PWideChar;
    lpComment: PWideChar;
    lpProvider: PWideChar;
  end;
  {$EXTERNALSYM _NETRESOURCE}
  _NETRESOURCE = _NETRESOURCEA;
  TNetResourceA = _NETRESOURCEA;
  TNetResourceW = _NETRESOURCEW;
  TNetResource = TNetResourceA;
  {$EXTERNALSYM NETRESOURCEA}
  NETRESOURCEA = _NETRESOURCEA;
  {$EXTERNALSYM NETRESOURCEW}
  NETRESOURCEW = _NETRESOURCEW;
  {$EXTERNALSYM NETRESOURCE}
  NETRESOURCE = NETRESOURCEA;

If you choose the ansi version declare a MyBuffer as TNetResourceA (Well, you don't have to call it "buffer");

Reference this variable on call to the Enum function.

Regards
0
 
lortegaCommented:
need a listbox and a button...

procedure TForm1.Button1Click(Sender: TObject);
type
  PNetResourceArray = ^TNetResourceArray;
  TNetResourceArray = array[0..MaxInt div SizeOf(TNetResource) - 1] of TNetResource;
var
  I, BufSize, NetResult: Integer;
  NetHandle: THandle;
  NetResources: PNetResourceArray;
  Count, Size: LongWord;
begin
//    if WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_DISK, 0, nil,
    if WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_ANY, 0, nil,
      NetHandle) <> NO_ERROR then Exit;
    try
      BufSize := 50 * SizeOf(TNetResource);
      GetMem(NetResources, BufSize);
      try
        while True do
        begin
          Count := $FFFFFFFF;
          Size := BufSize;
          NetResult := WNetEnumResource(NetHandle, Count, NetResources, Size);
          if NetResult = ERROR_MORE_DATA then
          begin
            BufSize := Size;
            ReallocMem(NetResources, BufSize);
            Continue;
          end;
          if NetResult <> NO_ERROR then Exit;
          for I := 0 to Count - 1 do
              ListBox1.Items.Add(NetResources^[I].lpRemoteName);
        end;
      finally
        FreeMem(NetResources, BufSize);
      end;
    finally
      WNetCloseEnum(NetHandle);
    end;
end;


good luck,
luis
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now