[solved] Crash on EndProcedure

Windows specific forum
PureGuy
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Aug 30, 2010 11:51 am

[solved] Crash on EndProcedure

Post by PureGuy »

Hi guys,

I'm currently trying to convert this code Native Solution to PB.

Think I'm getting closer, but now it always crash on EndProcedure :shock:
What exactly I'm doing wrong?

BTW: You need Windows 7 or later with admin rights for this

Code: Select all



#VDS_QUERY_SOFTWARE_PROVIDERS = 1
#VDS_QUERY_HARDWARE_PROVIDERS = 2
#VDS_QUERY_VIRTUALDISK_PROVIDERS = 4

Structure _VDS_DISK_PROP
  id.i
  status.i
  ReserveMode.i
  health.i
  dwDeviceType.l
  dwMediaType.l
  ullSize.q
  ulBytesPerSector.l
  ulSectorsPerTrack.l
  ulTracksPerCylinder.l
  ulFlags.l
  BusType.i
  PartitionStyle.i
  StructureUnion
    dwSignature.l
    DiskGuid.i
  EndStructureUnion
  pwszDiskAddress.s
  pwszName.s
  pwszFriendlyName.s
  pwszAdaptorName.s
  pwszDevicePath.s
  
EndStructure

Structure _VDS_VDISK_PROPERTIES
  Id.i
  State.i
  VirtualDeviceType.i
  VirtualSize.q
  PhysicalSize.q
  pPath.s
  pDeviceName.s
  DiskFlag.i
  bIsChild.l
  pParentPath.s
EndStructure

Interface IVdsServiceLoader Extends IUnknown
  LoadService.i(Null.i, pService.i)  
EndInterface


Interface IVdsService Extends IUnknown
  IsServiceReady.i()
  WaitForServiceReady.i()
  GetProperties.i(*pServiceProp)
  QueryProviders.i(masks.l, *ppEnum)
  QueryMaskedDisks.i()
  QueryUnallocatedDisks.i(*ppEnum)
  GetObject.i(VDS_OBJECT_ID.i, VDS_OBJECT_TYPE.i, *ppObjectUnk)
  QueryDriveLetters.i(wcFirstLetter.s, count.l,*pDriveLetterPropArray)
  QueryFileSystemTypes.i(*ppFileSystemTypeProps,  *plNumberOfFileSystems.l)
  Reenumerate.i()
  Refresh.i()
  CleanupObsoleteMountPoints.i()
  Advise.i(*IVdsAdviseSink, *pdwCookie.l)
  Unadvise.i(dwCookie.l)
  Reboot.i()
  SetFlags.i(ulFlags.l)
  ClearFlags.i(ulFlags.l)
EndInterface


Interface IEnumVdsObject Extends IUnknown
  Next.i(celt.l, *ppObjectArray, *pcFetched)
  Skip.i(celt.l)
  Reset.i()
  Clone.i(*ppEnum)  
EndInterface

Interface IVdsVdProvider Extends IUnknown
  QueryVDisks.i(*ppEnum)
  CreateVDisk.i(VirtualDeviceType.i, pPath.s, pStringSecurityDescriptor.s, Flags.l, ProviderSpecificFlags.l, Reserved.l, *pCreateDiskParameters, *ppAsync)
  AddVDisk.i(VirtualDeviceType.i, pPath.s, *ppVDisk)
  GetDiskFromVDisk.i(*pVDisk, *ppDisk)
  GetVDiskFromDisk.i(*pVDisk, *ppDisk)
EndInterface

Interface IVdsVDisk Extends IUnknown
  Open.i(AccessMask.l, Flags.l, ReadWriteDepth.l, *ppOpenVDisk)
  GetProperties.i(pDiskProperties.i)
  GetHostVolume.i(*ppVolume)
  GetDeviceName.i(*ppDeviceName)  
EndInterface

Interface IVdsDisk Extends IUnknown
  GetPartitionFileSystemProperties.i(ullOffset.l, *pFileSystemProp)
  GetPartitionFileSystemTypeName.i(ullOffset.l, *ppwszFileSystemTypeName)
  QueryPartitionFileSystemFormatSupport.i(ullOffset.l, *ppFileSystemSupportProps, *plNumberOfFileSystems)
  FormatPartitionEx.i(ullOffset.l, pwszFileSystemTypeName.s, usFileSystemRevision.w, ulDesiredUnitAllocationSize.l, pwszLabel.s, bForce.l, bQuickFormat.l, bEnableCompression.l, *ppAsync)
EndInterface

Interface IVdsVolume Extends IUnknown
  GetProperties.i(*pVolumeProperties)
  GetPack.i(*ppPack)
  QueryPlexes.i(*ppEnum)
  Extend.i(*pInputDiskArray, lNumberOfDisks.l, *ppAsync)
  Shrink.i(ullNumberOfBytesToRemove.l, *ppAsync)
  AddPlex.i(VolumeId.i, *ppAsync)
  BreakPlex.i(plexId.i, *ppAsync)
  RemovePlex.i(plexId.i, *ppAsync)
  Delete.i(bForce.i)
  SetFlags.i(ulFlags.l, bRevertOnClose.l)
  ClearFlags.i(ulFlags.l)
EndInterface


CoInitialize_(0)

pLoader.IVdsServiceLoader
pService.IVdsService
pProviderEnum.IEnumVdsObject
pUnknown.IUnknown

pVdProvider.IVdsVdProvider
CLSCTX_LOCAL_SERVER.i = 4
HRESULT.i = 0
ulFetched.l = 0
bDone.l = 0



Procedure exploreVDiskProvider(pVdProvider.IVdsVdProvider)
  Protected ulFetched.l, HRESULT.i
  Protected bDone.l
  Protected pVDiskEnum.IEnumVdsObject
  Protected pVDisk.IVdsVDisk
  Protected pDisk.IVdsDisk
  Protected pVolume.IVdsVolume
  Protected vdiskProperties._VDS_VDISK_PROPERTIES
  Protected pUnknown.IUnknown
  
  HRESULT = pVdProvider\QueryVDisks(@pVDiskEnum)
  If HRESULT = 0
    Debug "Querying virtual disks"
            
    While 1
              
      ulFetched = 0
      HRESULT = pVDiskEnum\Next(1, @pUnknown, @ulFetched)
      If HRESULT = 1
        Break
      ElseIf HRESULT <> 0
        End
      EndIf
              
       hResult = pUnknown\QueryInterface(?IID_IVdsVDisk, @pVDisk)
       If hResult = 0
                 
         Debug "Virtual disk Found"
                 
         hResult = pVDisk\GetProperties(@vdiskProperties)
         If hResult = 0
           Debug vdiskProperties\pDeviceName
         Else
           Debug Hex(hResult) 
         EndIf
                 
       Else
         Break
       EndIf
              
   Wend
            
  EndIf
  
  
EndProcedure



If CoCreateInstance_(?CLSID_VdsLoader, 0, CLSCTX_LOCAL_SERVER, ?CLSID_IID_VdsLoader, @pLoader) = 0

  HRESULT = pLoader\LoadService(#Null, @pService)
  If HRESULT = 0
  
    Debug "pService: " + Str(pService)
    pLoader\Release()
  
  
    HRESULT = pService\WaitForServiceReady()
    If HRESULT = 0
    
      Debug "VDS initialized successfully."
    
      HRESULT = pService\QueryProviders(#VDS_QUERY_VIRTUALDISK_PROVIDERS, @pProviderEnum)
      If HRESULT = 0
        
        Debug "Querying providers..."      
        
        While 1
          
          ulFetched = 0
          HRESULT = pProviderEnum\Next(1, @pUnknown, @ulFetched)
          If HRESULT <> 0
            Break
          EndIf
                              
          HRESULT = pUnknown\QueryInterface(?IID_IVdsVdProvider, @pVdProvider)
          If HRESULT <> 0
            
            Break
          EndIf
          
          Debug "VDS Virtual Disk Provider Found"
          
          exploreVDiskProvider(pVdProvider)
          
          Break
          
        Wend
        
        
      EndIf  
    Else
      Debug "VDS failed to initialize."
    EndIf

  EndIf
EndIf 


DataSection

CLSID_VdsLoader:
  Data.L $9C38ED61
  Data.W $D565, $4728
  Data.B $AE, $EE, $C8, $09, $52, $F0, $EC, $DE
  
CLSID_IID_VdsLoader:
  Data.L $E0393303
  Data.W $90D4, $4A97
  Data.B $AB, $71, $E9, $B6, $71, $EE, $27, $29
  
IID_IVdsVdProvider:
  Data.L $B481498C
  Data.W $8354, $45F9
  Data.B $84, $A0, $0B, $DD, $28, $32, $A9, $1F
  
IID_IVdsVDisk:
  Data.L $1E062B84
  Data.W $E5E6, $4B4B
  Data.B $8A, $25, $67, $B8, $1E, $8F, $13, $E8
  
EndDataSection

Last edited by PureGuy on Wed Nov 21, 2012 6:54 pm, edited 1 time in total.
Fred
Administrator
Administrator
Posts: 16690
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Crash on EndProcedure

Post by Fred »

Try 'ProcedureC' instead of 'Procedure'
PureGuy
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Aug 30, 2010 11:51 am

Re: Crash on EndProcedure

Post by PureGuy »

Fred wrote:Try 'ProcedureC' instead of 'Procedure'
Same "invalid memory access" with ProcedureC.
User avatar
blueb
Addict
Addict
Posts: 1044
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Crash on EndProcedure

Post by blueb »

PureGuy...

Not sure what you're looking for but I ran the program successfully

Debug Results:

Code: Select all

pService: 5533468
VDS initialized successfully.
Querying providers...
VDS Virtual Disk Provider Found
Querying virtual disks
PS - Win 7 Pro Service Pack 1
- It was too lonely at the top.

System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
PureGuy
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Aug 30, 2010 11:51 am

Re: Crash on EndProcedure

Post by PureGuy »

Hi blueb,

sorry I forgot to mention, you need to have a virtual hard disk image (*.vhd) attached to the system. Else the code will stop before calling the exploreVDiskProvider Procedure that ends with the crash.
PureGuy
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Aug 30, 2010 11:51 am

Re: [solved] Crash on EndProcedure

Post by PureGuy »

Problem solved, I forgot to release the objects :oops:
Sundance
User
User
Posts: 16
Joined: Sat Jun 07, 2014 10:12 am

Re: [solved] Crash on EndProcedure

Post by Sundance »

Hi PureGuy,

when I run the script you posted I get an error when getting the handle with pLoader\LoadService. I've tried it under Windows 8.1 and Windows 10.
I haven't found any difference when looking at MSDN between Windows 7 and 8.1 concerning VDS.

Did you made any changes or improvements?


Thanks in advance
Sundance
User avatar
digital32
User
User
Posts: 23
Joined: Fri Dec 28, 2012 1:28 am

Re: [solved] Crash on EndProcedure

Post by digital32 »

Can this code be used to list VHDs Mounted and Then flush and unmount them?
Post Reply