• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

VB equivalent of C++ ULARGE_INTEGER type?

The on-line MSDN has the following to say: "The ULARGE_INTEGER structure is actually a union. If your compiler has built-in support for 64-bit integers, use the QuadPart member to store the 64-bit integer. Otherwise, use the LowPart and HighPart members to store the 64-bit integer. typedef struct ULARGE_INTEGER {ULONGLONG QuadPart;

OK, fine, I can handle that. But how do I use that in VB? Is there an equivalent to this datatype in VB? Do I create my own type, and how would I use that type with API functions like GetDiskFreeSpaceEx that returns those values?

The above reference is from http://premium.microsoft.com/msdn/library/sdkdoc/winbase/largeint_44tu.htm
  • 6
  • 4
  • 4
  • +1
1 Solution
The longest integer VB allows is that of 32 bits (a LONG variable). You can define your own type with something like:

End Type

Anyway, if you have to show the value stored at a ULONG-variable, or use it for some arithmetic operation, you'll have to do some calculations (involving both parts) to get the actual value.
vikiing is rith there is no support for that in VB.

The other way that i think you can do it is to create a DLL in Vc that handles all you need, and gives the results for ex in a String (BSTR)
mollercwAuthor Commented:
vikiing mentioned creating your type much the same way as is done in VC. How would I go about using that type to get back the results, and what arithmetic will have to take place on it? Would it be possible to work with the real value when the largest VB can work with is LONG? Surely truncation will still take place if I try to display that number?
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Yes you will never work with the real number, but with to numbers. The aritmetical operations will need to be done by you cos Vb will truncate a value to a long.

Vb supports no aritmetical operations usingn a structure!!!
I didn't try GetDiskFreeSpaceEx, but I think you can use Currency in your declaration.
>>I think you can use Currency in your declaration

Currency type has NOTHING to see (nor even close) with a 64-bit integer.
Hi, vikiing
This is from VB Help:
Currency variables are stored as 64-bit (8-byte) numbers in an integer format.
Range -922,337,203,685,477.5808 to 922,337,203,685,477.5807

(Long has range -2,147,483,648 to 2,147,483,647
so it cannot be used when disk partition is >2.2GB)
i must agree with ameba, i've remember that but it is true that the currecy is a 64 bit number, but there is only one point were i don't know if it works, cos they do have a decimal part.

So they aren't integer but real numbers. The only way to find out is to try it !!
If you ask me (and my income), Currency can be LESS then 'six figures' format.
LOL :)
My apologizes to Ameba. You're right about the 64-bits representation (although the number is scaled by 10000).
Thanks, vikiing
mollercwAuthor Commented:
re ameba's proposal to use Currency:

I tried it, and it worked, but not completely correctly. On my 1.6GB drive it worked fine (gave all the digits, although the last four were after the decimal point) On my 2.5GB though, it gave an answer that is incorrect by a factor of 10. The reason is that the total amount of bytes on that drive ends in a 0, so when the decimal gets hold of it, it's discarded, reducing my 2.5GB drive to a 250MB drive (in it's eyes). Unless the amount of decimals can be set, Currency is useless.

I read about the Decimal type over the weekend. Seems to be what I'm looking for, but how does one implement that seeing as VB doesn't support it yet (it's a subtype of Variant).

Or, try this code (I don't have OSR2 and all my partitions are < 2.2GB)

' add 1 combobox to form
Option Explicit
Private Declare Function GetLogicalDriveStrings Lib "kernel32" _
   Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
   ByVal lpBuffer As String) As Long
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
   Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, _
   lpFreeBytesAvailableToCaller As Currency, _
   lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Long
Private Sub Form_Click()
   Dim r As Long
   Dim BytesFreeToCalller As Currency
   Dim TotalBytes As Currency
   Dim TotalFreeBytes As Currency
   Dim TotalBytesUsed As Currency
   Dim RootPathName As String   'the drive to find
   RootPathName = Combo1.List(Combo1.ListIndex)
   'get the drive's disk parameters
   Call GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
   'show the results, multiplying the returned
   'value by 10000 to adjust for the 4 decimal
   'places that the currency data type returns.  Cls  Print
   Print "  Total Number Of Bytes:", _
      Format$(TotalBytes * 10000, "###,###,###,##0") & " bytes"
   Print "  Total Free Bytes:", _
      Format$(TotalFreeBytes * 10000, "###,###,###,##0") & " bytes"
   Print "  Free Bytes Available:", _
      Format$(BytesFreeToCalller * 10000, "###,###,###,##0") & " bytes"
   Print "  Total Space Used :", _
      Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0") & " bytes"
End Sub

Private Sub Form_Load()
    On Error Resume Next
   Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
   LoadAvailableDrives Combo1
   Combo1.ListIndex = 1
   Caption = "select drive and click on form"
End Sub

Private Function rgbGetLogicalDriveStrings() As String
   'returns a single string of available drive
   'letters, each separated by a chr$(0) null 'and terminated with two nulls
   Dim r As Long
   Dim sBuffer As String
   sBuffer = Space$(64)
   Call GetLogicalDriveStrings(Len(sBuffer), sBuffer)
   'need the two terminating chr$(0)'s,  'so just trim the trailing spaces
   sBuffer = Trim$(sBuffer)
   rgbGetLogicalDriveStrings = sBuffer
End Function

Private Sub LoadAvailableDrives(cmbo As ComboBox)
   Dim r As Long
   Dim DriveSize As Long
   Dim lpBuffer As String
   Dim currDrive As String
   'get the list of all available drives
   lpBuffer = rgbGetLogicalDriveStrings()
   'Separate the drive strings and add them 'to the combobox.
   Do Until lpBuffer = Chr(0)     'strip off one drive item from the lpBuffer
      currDrive = StripNulls(lpBuffer)     'add the drive to the combo list
      cmbo.AddItem currDrive
End Sub

Private Function StripNulls(startStrg As String) As String
   'Take a string separated by a space, and split off 1 item, and
   'shorten the string so that the next item is ready for removal.
   Dim c As Long
   Dim item As String
   c = 1
      If Mid(startStrg, c, 1) = Chr(0) Then
         item = Mid(startStrg, 1, c - 1)
         startStrg = Mid(startStrg, c + 1, Len(startStrg))
         StripNulls = item
         Exit Function
      End If
      c = c + 1
End Function

In Form_Click line 12:  Cls and Print should go to next line
mollercwAuthor Commented:
ok kewl ... i'll go look at that code at home tonight ... seems to me that just multiplying the value by 10000 is not going to solve the problem that a drivesize might end in a zero as one of mine does (ie. 2*10^8 = 200,000,000 = 20000.0000 when represented by Currency)
mollercwAuthor Commented:
thx ameba =)

i used that code and it works perfectly :) the little bit of arithmetic i do on it (changing values from bytes to megabytes) also works as it should :)

thx a mil :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now