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
nohjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.