#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    8
    Rep Power
    0

    working about a to make a function to work.. help!


    anybody knows NetShareEnum ? of curse not delphi doesnt have in at any units.. its function from msdn so i delcare it
    i am about a week to make it work but it keeps to crash and crash like nothing, so i tut somthing not good with my declare so i even tryed with NetShareEnum from the new api libary
    here is my codes, with 2 trys maby anybody can help me out.

    http://www.jinote.com/css/GetShareS.rar
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    England
    Posts
    952
    Rep Power
    14
    There were a few problems concerning how you were passing parameters to the NetShareEnum function.
    Looking at this code:
    Code:
    var
    .
    .
      EntRead, ResHandle, EntTotal: PDWORD;
    begin
    .
    .
      NetShareEnum(nil, 0, lpBuffer, dword(-1), EntRead, EntTotal, ResHandle);
    You were passing PDWORDs to the function but you did not create any DWORD variables for the results to be stored in.
    Also in this line:
    Code:
    SharesInfo     := @lpBuffer;
    you are getting the address of the lpBuffer pointer but what you need to do is cast the pointer to PShareInfo0.
    Try the following modified code:
    Code:
    var
      pb: PByte;
      Counter: DWORD;
      SharesInfo, p: PShareInfo0;
      NetApiStatus: Integer;
      EntRead, ResHandle, EntTotal: DWORD;
    begin
    
      repeat
        
        NetApiStatus := NetShareEnum(nil, 0, pb, dword(-1),
                                   @EntRead, @EntTotal, @ResHandle);
        SharesInfo := PShareInfo0(pb);
        if (NetApiStatus = ERROR_SUCCESS)
          or (NetApiStatus = ERROR_MORE_DATA) then
        begin
          p := SharesInfo;
          for Counter := 0 to EntRead-1 do
          begin
            writeln(string(p^.shi0_netname));
            Inc(p);
          end;
    
          NetApiBufferFree(SharesInfo);
        end
        else WriteLn('Error: '+IntToStr(NetApiStatus));
    
      until (NetApiStatus <> ERROR_MORE_DATA);
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    8
    Rep Power
    0
    i dont know what to say for those help, u just didnt wrote the fixed code, u wrote the problems and thats very helped me i want to thank u very much for explaining it like this keep it up..
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    8
    Rep Power
    0
    P.S

    why are u incrssing the P ?
    E.G : Inc(p);
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    England
    Posts
    952
    Rep Power
    14
    NetShareEnum generates a list of PShareInfo0 records. Inc(p) increments the pointer 'p' to point to the next record.

IMN logo majestic logo threadwatch logo seochat tools logo