AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Übersetzung von CreateVirtualDisk
Thema durchsuchen
Ansicht
Themen-Optionen

Übersetzung von CreateVirtualDisk

Ein Thema von paritycheck · begonnen am 24. Okt 2010 · letzter Beitrag vom 27. Okt 2010
Antwort Antwort
Seite 2 von 2     12   
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#11

AW: Übersetzung von CreateVirtualDisk

  Alt 24. Okt 2010, 21:58
How would that matter? Shouldn't it still be 4 Bytes on the stack for a 32bit machine?
Yes, you are are right indeed (the argument is indeed passed as 4 bytes)
See my blog blog
See our Jedi blog

Geändert von Remko (24. Okt 2010 um 22:16 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.052 Beiträge
 
Delphi 12 Athens
 
#12

AW: Übersetzung von CreateVirtualDisk

  Alt 24. Okt 2010, 21:59
Ach stimmt ja, den Enum hab'sch übersehn.

Leider gibt es in Delphi nix Vergleichbares,
da es in C++ eher eine Bitmaske ist, bzw. der Enum in Delphi anders funktioniert, wo er mehr einen Bit-Index (für nur ein einziges Bit) für ein SET darstellt.
Delphi-Quellcode:
type
  _VIRTUAL_DISK_ACCESS_MASK = Cardinal;
const
  VIRTUAL_DISK_ACCESS_ATTACH_RO = $00010000;
  VIRTUAL_DISK_ACCESS_ATTACH_RW = $00020000;
  VIRTUAL_DISK_ACCESS_DETACH = $00040000;
  VIRTUAL_DISK_ACCESS_GET_INFO = $00080000;
  VIRTUAL_DISK_ACCESS_CREATE = $00100000;
  VIRTUAL_DISK_ACCESS_METAOPS = $00200000;
  VIRTUAL_DISK_ACCESS_READ = $000d0000;
  VIRTUAL_DISK_ACCESS_WRITABLE = $00320000;
  VIRTUAL_DISK_ACCESS_ALL = $003f0000;
oder
Delphi-Quellcode:
type
  _VIRTUAL_DISK_ACCESS_MASK = set of (
    VIRTUAL_DISK_ACCESS_ATTACH_RO = 16,
    VIRTUAL_DISK_ACCESS_ATTACH_RW = 17,
    VIRTUAL_DISK_ACCESS_DETACH = 18,
    VIRTUAL_DISK_ACCESS_GET_INFO = 19,
    VIRTUAL_DISK_ACCESS_CREATE = 20,
    VIRTUAL_DISK_ACCESS_METAOPS = 21
  );
const
  VIRTUAL_DISK_ACCESS_READ = [VIRTUAL_DISK_ACCESS_ATTACH_RO,
    VIRTUAL_DISK_ACCESS_DETACH, VIRTUAL_DISK_ACCESS_GET_INFO];
  VIRTUAL_DISK_ACCESS_WRITABLE = [VIRTUAL_DISK_ACCESS_ATTACH_RW,
    VIRTUAL_DISK_ACCESS_CREATE, VIRTUAL_DISK_ACCESS_METAOPS];
  VIRTUAL_DISK_ACCESS_ALL = [VIRTUAL_DISK_ACCESS_ATTACH_RO..VIRTUAL_DISK_ACCESS_METAOPS];
Neuste Erkenntnis:
Seit Pos einen dritten Parameter hat,
wird PoSex im Delphi viel seltener praktiziert.

Geändert von himitsu (24. Okt 2010 um 22:02 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#13

AW: Übersetzung von CreateVirtualDisk

  Alt 24. Okt 2010, 22:12
But it does mean that the recordsize of the CREATE_VIRTUAL_DISK_PARAMETERS might be wrong.
See my blog blog
See our Jedi blog
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#14

AW: Übersetzung von CreateVirtualDisk

  Alt 24. Okt 2010, 22:23
SizeOf(CREATE_VIRTUAL_DISK_PARAMETERS) = 44 and I think it should be 48 since the Union is not anonymous, try:
Delphi-Quellcode:
  CREATE_VIRTUAL_DISK_PARAMETERS = record
  case Version1: Integer of
    0: (
      UniqueId: TGUID;
      MaximumSize: ULONGLONG;
      BlockSizeInBytes: ULONG;
      ParentPath: PWideChar;
      SourcePath: PWideChar);
  end;
See my blog blog
See our Jedi blog
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#15

AW: Übersetzung von CreateVirtualDisk

  Alt 24. Okt 2010, 22:56
Ist in Delphi2009 nicht schon komplett Unicode implementiert?
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
paritycheck

Registriert seit: 8. Feb 2005
51 Beiträge
 
Delphi 2009 Professional
 
#16

AW: Übersetzung von CreateVirtualDisk

  Alt 25. Okt 2010, 09:31
Danke für Eure Tipps und Anregungen ich habs mittlerweile hinbekommen

Es war scheinbar eine Kombination aus _CREATE_VIRTUAL_DISK_PARAMETERS und der Konstante CREATE_VIRTUAL_DISK_PARAMETERS_DEFAULT_BLOCK_SIZE letztere ist nämlich 0 und nich $200000.

Delphi-Quellcode:
unit createvhd;

interface

uses Sysutils, Windows;

{$ALIGN ON}
{$MINENUMSIZE 4}

const
  VirtDisk_dll = 'VirtDisk.dll';

  VIRTUAL_STORAGE_TYPE_DEVICE_UNKNOWN = 0; //Device type is unknown or not valid.
  VIRTUAL_STORAGE_TYPE_DEVICE_ISO = 1; //Internal use only. Not supported.
  VIRTUAL_STORAGE_TYPE_DEVICE_VHD = 2; //Virtual hard disk device type.

  CREATE_VIRTUAL_DISK_PARAMETERS_DEFAULT_SECTOR_SIZE = $200;
  [COLOR="Red"]CREATE_VIRTUAL_DISK_PARAMETERS_DEFAULT_BLOCK_SIZE = $0;
[/COLOR]
var
  VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT: TGUID; // '{EC984AEC-A0F9-47e9-901F-71415A66345B}';
  VIRTUAL_STORAGE_TYPE_VENDOR_UNKNOWN : TGUID; //= 0;

type
/////////////////////////////////////////////////////////
// typedef struct _VIRTUAL_STORAGE_TYPE {
// ULONG DeviceId;
// GUID VendorId;
// } VIRTUAL_STORAGE_TYPE, *PVIRTUAL_STORAGE_TYPE;

  _VIRTUAL_STORAGE_TYPE = record
    DeviceId: ULONG;
    VendorId: TGUID;
  end;
  VIRTUAL_STORAGE_TYPE = _VIRTUAL_STORAGE_TYPE;
  PVIRTUAL_STORAGE_TYPE = ^_VIRTUAL_STORAGE_TYPE;

////////////////////////////////////////////////////////
// typedef enum _VIRTUAL_DISK_ACCESS_MASK {
// VIRTUAL_DISK_ACCESS_ATTACH_RO = 0x00010000,
// VIRTUAL_DISK_ACCESS_ATTACH_RW = 0x00020000,
// VIRTUAL_DISK_ACCESS_DETACH = 0x00040000,
// VIRTUAL_DISK_ACCESS_GET_INFO = 0x00080000,
// VIRTUAL_DISK_ACCESS_CREATE = 0x00100000,
// VIRTUAL_DISK_ACCESS_METAOPS = 0x00200000,
// VIRTUAL_DISK_ACCESS_READ = 0x000d0000,
// VIRTUAL_DISK_ACCESS_ALL = 0x003f0000,
// VIRTUAL_DISK_ACCESS_WRITABLE = 0x00320000
// } VIRTUAL_DISK_ACCESS_MASK;

  _VIRTUAL_DISK_ACCESS_MASK = (
    VIRTUAL_DISK_ACCESS_ATTACH_RO = $00010000,
    VIRTUAL_DISK_ACCESS_ATTACH_RW = $00020000,
    VIRTUAL_DISK_ACCESS_DETACH = $00040000,
    VIRTUAL_DISK_ACCESS_GET_INFO = $00080000,
    VIRTUAL_DISK_ACCESS_CREATE = $00100000,
    VIRTUAL_DISK_ACCESS_METAOPS = $00200000,
    VIRTUAL_DISK_ACCESS_READ = $000d0000,
    VIRTUAL_DISK_ACCESS_ALL = $003f0000,
    VIRTUAL_DISK_ACCESS_WRITABLE = $00320000
  );
  VIRTUAL_DISK_ACCESS_MASK = _VIRTUAL_DISK_ACCESS_MASK;
  PVIRTUAL_DISK_ACCESS_MASK = ^_VIRTUAL_DISK_ACCESS_MASK;

/////////////////////////////////////////////////////////////////////////
// typedef enum _CREATE_VIRTUAL_DISK_FLAG {
// CREATE_VIRTUAL_DISK_FLAG_NONE = 0x00000000,
// CREATE_VIRTUAL_DISK_FLAG_FULL_PHYSICAL_ALLOCATION = 0x00000001
// } CREATE_VIRTUAL_DISK_FLAG;

  _CREATE_VIRTUAL_DISK_FLAG = (
    CREATE_VIRTUAL_DISK_FLAG_NONE = $00000000,
    CREATE_VIRTUAL_DISK_FLAG_FULL_PHYSICAL_ALLOCATION = $00000001
  );
  CREATE_VIRTUAL_DISK_FLAG = _CREATE_VIRTUAL_DISK_FLAG;
  PCREATE_VIRTUAL_DISK_FLAG = ^_CREATE_VIRTUAL_DISK_FLAG;

////////////////////////////////////////////////////////////////
// typedef enum _CREATE_VIRTUAL_DISK_VERSION {
// CREATE_VIRTUAL_DISK_VERSION_UNSPECIFIED = 0,
// CREATE_VIRTUAL_DISK_VERSION_1 = 1
// } CREATE_VIRTUAL_DISK_VERSION;

  _CREATE_VIRTUAL_DISK_VERSION = (
    CREATE_VIRTUAL_DISK_VERSION_UNSPECIFIED = 0,
    CREATE_VIRTUAL_DISK_VERSION_1 = 1
  );
  CREATE_VIRTUAL_DISK_VERSION = _CREATE_VIRTUAL_DISK_VERSION;
  PCREATE_VIRTUAL_DISK_VERSION= ^_CREATE_VIRTUAL_DISK_VERSION;

////////////////////////////////////////////////////////////////////////////////
// typedef struct _CREATE_VIRTUAL_DISK_PARAMETERS {
// CREATE_VIRTUAL_DISK_VERSION Version;
// union {
// struct {
// GUID UniqueId;
// ULONGLONG MaximumSize;
// ULONG BlockSizeInBytes;
// ULONG SectorSizeInBytes;
// PCWSTR ParentPath;
// PCWSTR SourcePath;
// } Version1;
// } ;
//} CREATE_VIRTUAL_DISK_PARAMETERS, *PCREATE_VIRTUAL_DISK_PARAMETERS;

  TCreateVirtualDiskVersion1 = packed record
    UniqueId: TGUID;
    MaximumSize: ULONGLONG;
    BlockSizeInBytes: ULONG;
    SectorSizeInBytes: ULONG;
    ParentPath: Pointer;
    SourcePath: Pointer;
  end;

  _CREATE_VIRTUAL_DISK_PARAMETERS = packed record
    Version: _CREATE_VIRTUAL_DISK_VERSION;
   [COLOR="Red"] case V1:DWORD of[/COLOR]
         0: (Version1: TCreateVirtualDiskVersion1);
  end;
  CREATE_VIRTUAL_DISK_PARAMETERS = _CREATE_VIRTUAL_DISK_PARAMETERS;
  PCREATE_VIRTUAL_DISK_PARAMETERS = ^_CREATE_VIRTUAL_DISK_PARAMETERS;

{
DWORD CreateVirtualDisk(
  __in  PVIRTUAL_STORAGE_TYPE VirtualStorageType,
  __in  PCWSTR Path,
  __in  VIRTUAL_DISK_ACCESS_MASK VirtualDiskAccessMask,
  __in  PSECURITY_DESCRIPTOR SecurityDescriptor,
  __in  CREATE_VIRTUAL_DISK_FLAG Flags,
  __in  ULONG ProviderSpecificFlags,
  __in  PCREATE_VIRTUAL_DISK_PARAMETERS Parameters,
  __in  LPOVERLAPPED Overlapped,
  __out  PHANDLE Handle
);
}


function CreateVirtualDisk(VirtualStorageType: PVIRTUAL_STORAGE_TYPE;
                           Path: PWideChar;
                           VirtualDiskAccessMask: VIRTUAL_DISK_ACCESS_MASK;
                           SecurityDescriptor: PSECURITY_DESCRIPTOR;
                           Flags: CREATE_VIRTUAL_DISK_FLAG;
                           ProviderSpecificFlags: ULong;
                           Parameters: PCREATE_VIRTUAL_DISK_PARAMETERS;
                           Overlapped: POverlapped; Handle: PHandle): Cardinal;
                           stdcall external 'VirtDisk.dllname 'CreateVirtualDisk';

function CreateFixed(path: PWideChar; size: ULONGLONG; accessMask: _VIRTUAL_DISK_ACCESS_MASK; var AHandle: THandle;
                     source: PWideChar; securityDescriptor: Pointer; overlapped: POverlapped): Cardinal;

implementation

function CreateFixed(path: PWideChar; size: ULONGLONG; accessMask: _VIRTUAL_DISK_ACCESS_MASK; var AHandle: THandle;
                     source: PWideChar; securityDescriptor: Pointer; overlapped: POverlapped): Cardinal;
var
  pParam: PCREATE_VIRTUAL_DISK_PARAMETERS;
  pst: PVIRTUAL_STORAGE_TYPE;
  m_h: THandle;
begin
  pParam:= nil;
  pst:= nil;

  pst:= AllocMem(sizeof(VIRTUAL_STORAGE_TYPE));
  pst.DeviceId:= VIRTUAL_STORAGE_TYPE_DEVICE_VHD;
  pst.VendorId:= VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT;

  pParam:= AllocMem(sizeof(CREATE_VIRTUAL_DISK_PARAMETERS));
  pParam.Version:= CREATE_VIRTUAL_DISK_VERSION_1;
  pParam.Version1.BlockSizeInBytes:= CREATE_VIRTUAL_DISK_PARAMETERS_DEFAULT_BLOCK_SIZE;
  pParam.Version1.SectorSizeInBytes:= CREATE_VIRTUAL_DISK_PARAMETERS_DEFAULT_SECTOR_SIZE;
  pParam.Version1.MaximumSize:= size;
  pParam.Version1.ParentPath:= nil;
  pParam.Version1.SourcePath:= nil;
  pParam.Version1.UniqueId:= StringToGUid('{00000000-0000-0000-0000-000000000000}');

  Result:= CreateVirtualDisk(pst,
                             path,
                             accessMask,
                             securityDescriptor,
                             CREATE_VIRTUAL_DISK_FLAG_FULL_PHYSICAL_ALLOCATION,
                             0,
                             pParam,
                             overlapped,
                             @m_h);

  if Result = ERROR_SUCCESS then
     AHandle:= m_h
  else
     AHandle:= INVALID_HANDLE_VALUE;


  if Assigned(pParam) then FreeMem(pParam);
  if Assigned(pst) then FreeMem(pst);
end;

initialization
  VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT:= StringToGUid('{EC984AEC-A0F9-47e9-901F-71415A66345B}');
  VIRTUAL_STORAGE_TYPE_VENDOR_UNKNOWN := StringToGuid('{00000000-0000-0000-0000-000000000000}');

end.
Und der Aufruf

Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
var
  dwRet: Cardinal;
  H: THandle;
const
  DriveSize = 5242880;
begin
  dwRet:= CreateFixed('D:\Workdir\test.vhd', DriveSize, VIRTUAL_DISK_ACCESS_ALL, H, nil, nil, nil);
  if dwRet = ERROR_SUCCESS then
     Showmessage('OK')
  else
     Showmessage(SysErrorMessage(dwRet));
end;
Dann mach ich mich jetzt mal an die anderen VHD API Sachen

Geändert von paritycheck (25. Okt 2010 um 09:42 Uhr)
  Mit Zitat antworten Zitat
Dezipaitor

Registriert seit: 14. Apr 2003
Ort: Stuttgart
1.701 Beiträge
 
Delphi 7 Professional
 
#17

AW: Übersetzung von CreateVirtualDisk

  Alt 25. Okt 2010, 13:03
Würdest du das vielleicht an die JEDI API überarbeitet spenden?
Christian
Windows, Tokens, Access Control List, Dateisicherheit, Desktop, Vista Elevation?
Goto: JEDI API LIB & Windows Security Code Library (JWSCL)
  Mit Zitat antworten Zitat
paritycheck

Registriert seit: 8. Feb 2005
51 Beiträge
 
Delphi 2009 Professional
 
#18

AW: Übersetzung von CreateVirtualDisk

  Alt 25. Okt 2010, 13:25
Sicher doch Wenn ich den Rest übersetzt habe "spende" ich auch gerne die ganze unit.
  Mit Zitat antworten Zitat
paritycheck

Registriert seit: 8. Feb 2005
51 Beiträge
 
Delphi 2009 Professional
 
#19

AW: Übersetzung von CreateVirtualDisk

  Alt 27. Okt 2010, 14:49
So dann lade ich mal wie versprochen die fertige Unit hoch.

Der eigentliche Header ist die virtdisk.pas. Alles andere diente nur dazu zu sehen ob die Funktion was ausspuckt und sollte daher nicht zu streng bewertet werden.

Eigentlich sollte alles soweit funktionieren. Ich übernehme natürlich keinerle Garantie oder Gewährleistung dafür. Sollte also irgendwem die Bude abfackeln oder der PC explodieren...selbst schuld.

Getestet hab ich das ganze mit Delphi 2009 evtl könnten also noch kleine Änderungen unter älteren Versionen nötig sein.
Angehängte Dateien
Dateityp: rar virtdisk_test.rar (219,6 KB, 43x aufgerufen)
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:24 Uhr.
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