Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Function (WIMGetMountedImageInfo) (https://www.delphipraxis.net/178081-function-wimgetmountedimageinfo.html)

SlpLow 16. Dez 2013 17:38

Function (WIMGetMountedImageInfo)
 
Hallo! Hilfe bitte!
Warum function (WIMGetMountedImageInfo) nicht an zwei montierten Bildern zu arbeiten?
Delphi-Quellcode:
procedure TForm1.btn2Click(Sender: TObject);
var
  Created, Count: DWORD;
  Buffer: WIM_MOUNT_INFO_LEVEL0;
  size: Integer;
  wPath, wFile, wIndex, wWrite: string;
begin
  if not (WIMGetMountedImageInfo(0, @Count, @Buffer, size, @created)) then
  begin
    ShowMessage('Error Open ' + IntToStr(GetLastError));
    Exit;
  end
  else
  begin
    if Count > 0 then
    begin
//      for i := 1 to Count - 1 do
      begin
        wPath := Buffer.MountPath;
        wFile := Buffer.WimPath;
        wIndex := IntToStr(Buffer.ImageIndex);
        // Memo1.Lines.Add(BoolToStr(NewInfoBuf.MountedForRW, true));
        if Buffer.MountedForRW then
          wWrite := 'RW'
        else
          wWrite := 'R';
      end;
      Memo1.Lines.Add(wPath);
      Memo1.Lines.Add(wFile);
      Memo1.Lines.Add(wIndex);
      Memo1.Lines.Add(wWrite);
    end;
end;

Union 16. Dez 2013 20:11

AW: Function (WIMGetMountedImageInfo)
 
See the documentation

SlpLow 16. Dez 2013 21:56

AW: Function (WIMGetMountedImageInfo)
 
Zitat:

Zitat von Union (Beitrag 1240017)

Thank you! I studied it for three days.
When one image, everything works. If two simultaneously in different folders is not running. It is clear that there are many records but how to handle it I do not know.

himitsu 16. Dez 2013 22:05

AW: Function (WIMGetMountedImageInfo)
 
Then you did not read properly.

Zitat:

pMountInfo

[out opt] Pointer to a variable that receives the array of mounted image structures. The size of the information written varies depending on the type of structured defined by the fInfoLevelId parameter.

cbMountInfoLength

[in] The size of the buffer pointed to by the pMountInfo parameter, in bytes.

pcbReturnLength ( @created ? )

[out] A pointer to a variable in which the function returns the size of the requested information. If ...

SlpLow 17. Dez 2013 00:19

AW: Function (WIMGetMountedImageInfo)
 
I can tell you one thing! I do not know how to do, how to announce in the variables and how to apply.
Is all that is understood.
Delphi-Quellcode:
 if not (WIMGetMountedImageInfo([COLOR="Red"]MountedImageInfoLevel0[/COLOR], @Count, @Buffer, size, @created)) then
Yours!

SlpLow 17. Dez 2013 00:21

AW: Function (WIMGetMountedImageInfo)
 
I can tell you one thing! I do not know how to do, how to announce in the variables and how to apply.
Is all that is understood - MountedImageInfoLevel0.
Delphi-Quellcode:
 if not (WIMGetMountedImageInfo(MountedImageInfoLevel0, @Count, @Buffer, size, @created)) then
Yours!

Zacherl 17. Dez 2013 01:44

AW: Function (WIMGetMountedImageInfo)
 
Zitat:

Zitat von SlpLow (Beitrag 1240032)
When one image, everything works

I doubt that ... :roll:

You were just "lucky". The uninitialized size variable contained a sufficient size for the returned data struct. The api call in it's current form destroys a random memory region (directly behind the output buffer) in your program (buffer overflow), if there is more than one mounted image.

I cant really test it, because i have no mounted images, but it should work like this. Happy copy and paste:
Delphi-Quellcode:
type
  _WIM_MOUNT_LIST = packed record
    WimPath: array[0..MAX_PATH - 1] of WideChar;
    MountPath: array[0..MAX_PATH - 1] of WideChar;
    ImageIndex: DWord;
    MountedForRW: BOOL;
  end;
  WIM_MOUNT_LIST = _WIM_MOUNT_LIST;
  PWIM_MOUNT_LIST = ^WIM_MOUNT_LIST;
type
  WIM_MOUNT_INFO_LEVEL0 = _WIM_MOUNT_LIST;
  PWIM_MOUNT_INFO_LEVEL0 = ^WIM_MOUNT_LIST;
type
  MOUNTED_IMAGE_INFO_LEVELS = DWord;
const
  MountedImageInfoLevel0 = 1;
var
  WIMGetMountedImageInfo: function(fInfoLevelId: MOUNTED_IMAGE_INFO_LEVELS;
    var dwImageCount: DWord; pMountInfo: Pointer; cbMountInfoLength: DWord;
    var cbReturnLength: DWord): BOOL; stdcall;
type
  PWIM_MOUNT_INFO_LEVEL0_LIST = ^WIM_MOUNT_INFO_LEVEL0_LIST;
  WIM_MOUNT_INFO_LEVEL0_LIST = array[0..0] of WIM_MOUNT_INFO_LEVEL0;
var
  Success: Boolean;
  Buffer: PWIM_MOUNT_INFO_LEVEL0_LIST;
  BufferLength,
  ReturnLength,
  ImageCount: DWord;
  I: Integer;
begin
  @WIMGetMountedImageInfo := GetProcAddress(LoadLibrary('wimgapi.dll'), 'WIMGetMountedImageInfo');
  BufferLength := SizeOf(WIM_MOUNT_INFO_LEVEL0) * 8;
  GetMem(Buffer, BufferLength);
  try
    repeat
      Success := WIMGetMountedImageInfo(MountedImageInfoLevel0, ImageCount, Buffer, BufferLength,
        ReturnLength);
      if (Success) then
      begin
        for I := 0 to ImageCount - 1 do
        begin
          ShowMessage(StrPas(PChar(@Buffer^[I].WimPath[0])));
        end;
      end else if (GetLastError = ERROR_INSUFFICIENT_BUFFER) then
      begin
        ReallocMem(Buffer, ReturnLength);
      end;
    until (Success) or (GetLastError <> ERROR_INSUFFICIENT_BUFFER);
  finally
    FreeMem(Buffer);
  end;
end;

SlpLow 17. Dez 2013 02:35

AW: Function (WIMGetMountedImageInfo)
 
Zacherl! Vielen, vielen Dank! Ich werde versuchen, zu verstehen.
Adel liegt (sitzt) im Gemüte, nicht im Geblüte.

himitsu! Danke! Ich habe wenig Erfahrung, aber ich werde lernen!

SlpLow 17. Dez 2013 05:27

AW: Function (WIMGetMountedImageInfo)
 
Thank you again!
Strings and integer okay!
A logical always returns a -1 (RW, R) instead of 0 and 1
Delphi-Quellcode:
Idx: = BoolToStr (Buffer ^ [I]. MountedForRW, False);
:
or integer 257 (RW) or 1 (R) instead of 0 and 1
Delphi-Quellcode:
idx: = IntToStr (Integer (Buffer ^ [I]. MountedForRW));
:
Because it LongBool? Is there a solution?

I do not know, correct or not, but the problem disappeared when
Delphi-Quellcode:
const
MountedImageInfoLevel0 = 0;
Is it right decision?

Zacherl 17. Dez 2013 22:43

AW: Function (WIMGetMountedImageInfo)
 
Thats because of the C style boolean definition:
FALSE = 0
TRUE = everything else

You can just check the flag like this:
Delphi-Quellcode:
if (Buffer^[I].MountedForRW) then
or
Delphi-Quellcode:
if (not Buffer^[I].MountedForRW) then
If your problem is just the bool to string conversion you can go for this:
Delphi-Quellcode:
BoolToStr(Buffer^[I].MountedForRW, true)
or just write you an own function, if you dont like the -1 or the default bool strings.


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:47 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz