` Printed Icetips Article

Icetips Article



Windows API: Using Large Integers (64bit) in Clarion applications
2002-04-01 -- Paul van Drunick
 
Newsgroups: comp.lang.clarion


Large integers (64 bit) and Win API GetDiskFreeSpaceEx. A contribution to
the community.



The last couple of days I was struggling with the Win API
GetDiskFreeSpaceEx. This API takes large integers of 64 bit as parameters.
Ulong is 32 bit and the largest integer in Clarion and GetDiskFreeSpace
works only well with max. 2GB.



So I looked around and gathered information from all kind of sources like
the Clarion community and Microsoft to make a working solution. I did not
find a ready working solution so had to do some thinking for my self.



Well I did and find the following working solution. Next I thought why
struggle all when one is enough. So here is my working solution for all who
are looking for something similar and as a thank you to those who gave me
some answers in the past and hopefully again in the future.



I'm always in for improvement so if somebody has something to add to this
code .



With kind regards,



Paul van Drunick

DruSoft Software

Netherlands

www.drusoft.nl

info@drusoft.nl





The code:



In WinApi.CLW:



LARGEINTEGER    GROUP,TYPE

dwLowPart        long

dwHighPart       long

                END



! You have to create a kernel32.lib with this api in it (with libmaker and
kernel32.dll)

! and add it to your project. This api is not in the clarion libs and

! only compatible with Win 95-OSR2/98/NT 4.0/2000/XP

MODULE('KERNEL32.DLL')



GetDiskFreeSpaceEx(*LPCSTR,*LARGEINTEGER,*LARGEINTEGER,*LARGEINTEGER),BOOL,P
ASCAL,RAW,NAME('GetDiskFreeSpaceExA')



END





Code for your function or method:



SomeFunction PROCEDURE



lintFreeBytesCaller   group(LARGEINTEGER)

                      end

lintTotalBytes        group(LARGEINTEGER)

                      end

lintFreeBytes         group(LARGEINTEGER)

                      end

decFreeBytesLow       DECIMAL(31) ! max decimal is not enough for

! max result of

! 3,3161584934796709483252973253515e+327

decFreeBytesHigh      DECIMAL(31) ! but is enough for this purpose

                                                           ! maybe someone
knows an alternative?

decFreeBytes             DECIMAL(31)

cstrPath                       CSTRING(MAX_PATH)



  CODE

  cstrPath = clip(SomePath)

  if GetDiskFreeSpaceEx(cstrPath, lintFreeBytesCaller, lintTotalBytes,
lintFreeBytes) then .



! you can also use lintFreeBytesCaller (users free space in this path)



  if lintFreeBytes.dwLowPart < 0

    decFreeBytesLow = 2 ^ 32 + lintFreeBytes.dwLowPart

  else

    decFreeBytesLow = lintFreeBytes.dwLowPart

  end



  if lintFreeBytes.dwHighPart < 0

    decFreeBytesHigh = 2 ^ 32 + lintFreeBytes.dwHighPart

  else

    decFreeBytesHigh = lintFreeBytes.dwHighPart

  end



  decFreeBytes = decFreeBytesLow + decFreeBytesHigh * 2 ^ 32



Printed May 13, 2024, 2:48 am
This article has been viewed/printed 35140 times.
Google search has resulted in 120 hits on this article since January 25, 2004.