Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Use Currency instead of LARGE_INTEGER values
[ All Languages » VB »  Api]

Total Hit ( 3407)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


A few API calls require that you pass one or more LARGE_INTEGER arguments. These are 64-bit integer values, defined as follows:

Click here to copy the following block
Type LARGE_INTEGER
  lowpart As Long   ' lower 32-bit value
  highpart As Long  ' higher 32-bit value
End Type

Unfortunately, working with LARGE_INTEGER values in VB isn't easy, because you have to perform a lot of multiplications and divisions. A better solution is to pass the API function a Currency variable. Currency values are 64-bit integers, but when you print their values, VB scales them by a factor of 10,000 - to account for the 4 decimal digits that all Currency have.
As an example of this technique, let's see how you can retrieve the number of free bytes on the Windows versions that support partitions with more than 2G. In this case, you must call the GetDiskFreeSpaceEx API function, whose Declare is:

Click here to copy the following block
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias _
  "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, _
  lpFreeBytesAvailableToCaller As LARGE_INTEGER, _
  lpTotalNumberOfBytes As LARGE_INTEGER, lpTotalNumberOfFreeBytes As _
  LARGE_INTEGER) As Long

To apply the trick, you must define an aliased Declare, as follows:

Click here to copy the following block
Private Declare Function GetDiskFreeSpaceEx2 Lib "kernel32" Alias _
  "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, _
  lpFreeBytesAvailableToCaller As Currency, lpTotalNumberOfBytes As Currency, _
  lpTotalNumberOfFreeBytes As Currency) As Long

and then call it using this code:

Click here to copy the following block
Dim lpFreeBytesAvailableToCaller As Currency
Dim lpTotalNumberOfBytes As Currency
Dim lpTotalNumberOfFreeBytes As Currency

GetDiskFreeBytesEx2 "C:\", lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, _
  lpTotalNumberOfFreeBytes
Debug.Print "Free Bytes Available to Caller = " & lpFreeBytesAvailableToCaller
Debug.Print "Total Number of Bytes = " & lpTotalNumberOfBytes
Debug.Print "Total Number of Free Bytes = " & lpTotalNumberOfFreeBytes


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.