![]() |
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; |
AW: Function (WIMGetMountedImageInfo)
See the
![]() |
AW: Function (WIMGetMountedImageInfo)
Zitat:
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. |
AW: Function (WIMGetMountedImageInfo)
Then you did not read properly.
Zitat:
|
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:
Yours!
if not (WIMGetMountedImageInfo([COLOR="Red"]MountedImageInfoLevel0[/COLOR], @Count, @Buffer, size, @created)) then
|
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:
Yours!
if not (WIMGetMountedImageInfo(MountedImageInfoLevel0, @Count, @Buffer, size, @created)) then
|
AW: Function (WIMGetMountedImageInfo)
Zitat:
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; |
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! |
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:
Is it right decision?
const
MountedImageInfoLevel0 = 0; |
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:
or
if (Buffer^[I].MountedForRW) then
Delphi-Quellcode:
If your problem is just the bool to string conversion you can go for this:
if (not Buffer^[I].MountedForRW) then
Delphi-Quellcode:
or just write you an own function, if you dont like the -1 or the default bool strings.
BoolToStr(Buffer^[I].MountedForRW, true)
|
AW: Function (WIMGetMountedImageInfo)
@Zacherl
Folgendes würde ich ändern
Delphi-Quellcode:
EDIT
var
Lwimgapi : HMODULE; LSuccess : Boolean; LBuffer : PWIM_MOUNT_INFO_LEVEL0_LIST; LBufferLength, LReturnLength, LImageCount : DWord; LIdx : Integer; LLastError : Cardinal; begin Lwimgapi := LoadLibrary( 'wimgapi.dll' ); if Lwimgapi = 0 then RaiseLastOSError; try @WIMGetMountedImageInfo := GetProcAddress( Lwimgapi, 'WIMGetMountedImageInfo' ); LBufferLength := SizeOf( WIM_MOUNT_INFO_LEVEL0 ) * 8; GetMem( LBuffer, LBufferLength ); try repeat LSuccess := WIMGetMountedImageInfo( MountedImageInfoLevel0, LImageCount, LBuffer, LBufferLength, LReturnLength ); if LSuccess then begin for LIdx := 0 to LImageCount - 1 do begin ShowMessage( StrPas( PWideChar( @LBuffer^[LIdx].WimPath[0] ) ) ); end; end else begin LLastError := GetLastError; case LLastError of ERROR_INSUFFICIENT_BUFFER : begin ReallocMem( LBuffer, LReturnLength ); end; else RaiseLastOSError( LLastError ); end; end; until LSuccess; finally FreeMem( LBuffer ); end; finally FreeLibrary( Lwimgapi ); end; end;
Delphi-Quellcode:
ist auch noch ein Kandidat zum Prüfen ... aber jetzt nicht mehr :)
GetProcAddress
|
AW: Function (WIMGetMountedImageInfo)
Dein Code sieht auf jeden Fall besser aus, als mein nächtlicher Versuch :), aber der Hinweis zu GetLastError in der Delphi Hilfe ist definitiv falsch :D Habe es unter verschiedenen Windows Versionen getestet und der Error Code wird auf jeden Fall nicht resetted. Im MSDN ist unter
![]() |
AW: Function (WIMGetMountedImageInfo)
Zitat:
Zitat:
Danach kann schon wieder sonst was drin stehen (you never know). Potentiell handelt man sich so diese unliebsamen SideEffects ein ;) |
AW: Function (WIMGetMountedImageInfo)
Der Vollständigkeit halber:
Zitat:
|
AW: Function (WIMGetMountedImageInfo)
Problematisch ist aber eben der unbewusste Aufruf von API Funktionen (weil die mit einem harmlosen Befehl irgendwo versteckt aufgerufen werden).
Bei MS wird es erklärt und Emba schürt Angst ;) |
AW: Function (WIMGetMountedImageInfo)
Zitat:
MountedImageInfoLevel0 = 0; Warum? Sir Rufo Vielen Dank! |
AW: Function (WIMGetMountedImageInfo)
Zitat:
|
AW: Function (WIMGetMountedImageInfo)
Zitat:
// MOUNTED_IMAGE_INFO_LEVELS MountedImageInfoLevel0 = 1; MountedImageInfoLevel1 = 2; MountedImageInfoLevelInvalid = 3; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:42 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz