Structure already declared in a resident file

Everything else that doesn't fall into one of the other PB categories.
hoangdiemtinh
User
User
Posts: 29
Joined: Wed Nov 16, 2022 1:51 pm

Structure already declared in a resident file

Post by hoangdiemtinh »

Structure already declared STORAGE_DEVICE_NUMBER in a resident file.
why my code not run ?
Thanks

Code: Select all

#IOCTL_STORAGE_GET_DEVICE_NUMBER = $2d1080

Structure STORAGE_DEVICE_NUMBER
  DeviceType.l      ;// The FILE_DEVICE_XXX type For this device.
  DeviceNumber.l    ;// The number of this device
  PartitionNumber.l ;// If the device is partitionable, the partition number of the device. Otherwise -1
EndStructure

Procedure.s Drive_GetNumber()
  Protected DriveInfo.STORAGE_DEVICE_NUMBER, lpBytesReturned, Ret$="?:?", hDevice
  For iDiskCurr = 0 To 25; alphabet (A = 0)
    hDevice = CreateFile_("\\.\" + Chr(65 + iDiskCurr) + ":", 0, 0, 0, #OPEN_EXISTING, #FILE_ATTRIBUTE_NORMAL, #NUL)
    If hDevice <> #INVALID_HANDLE_VALUE
      If DeviceIoControl_(hDevice,#IOCTL_STORAGE_GET_DEVICE_NUMBER, 0, 0, DriveInfo, SizeOf(STORAGE_DEVICE_NUMBER), @lpBytesReturned, #NUL)
        Ret$ = Str(DriveInfo\DeviceNumber) + ":" + Str(DriveInfo\PartitionNumber)
      EndIf
      CloseHandle_(hDevice)
    EndIf
    ProcedureReturn Ret$
  Next
EndProcedure

Debug Drive_GetNumber()
AZJIO
Addict
Addict
Posts: 1298
Joined: Sun May 14, 2017 1:48 am

Re: Structure already declared in a resident file

Post by AZJIO »

I already gave a working code, why make a faulty one from a working code?
viewtopic.php?p=582300&hilit=Drive#p582300
Use the GetDrives() function to get existing drives.
hoangdiemtinh
User
User
Posts: 29
Joined: Wed Nov 16, 2022 1:51 pm

Re: Structure already declared in a resident file

Post by hoangdiemtinh »

I need mod it by your code can not read/count the UnFormated Partitions (or Hidden Partitions).
It only read/count partiton which have exist Letter Partition.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8422
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Structure already declared in a resident file

Post by netmaestro »

If you want to use a structure but you're not sure if it's defined in a resident or not, you can use a CompilerIf block like this:

Code: Select all

CompilerIf Defined(POINTS, #PB_Structure) = 0
  Structure POINTS
    x.w
    y.w
  EndStructure
CompilerEndIf
As it happens the POINTS structure is already defined in PB so the structure code will never execute. But if you need a structure and aren't sure if it's defined or not you can do it like this to avoid the IDE dinging at you.
BERESHEIT
AZJIO
Addict
Addict
Posts: 1298
Joined: Sun May 14, 2017 1:48 am

Re: Structure already declared in a resident file

Post by AZJIO »

hoangdiemtinh
I insert a card reader without a memory card and he sees it. It's definitely not formatted.
You can use "CreateFile_("\\.\PhysicalDrive" + DiskNumber, " instead of a letter.
Post Reply