+ Reply to Thread
Results 1 to 3 of 3

How can use LONGLONG type of C++ Dll in 'Declare Function' statement?

  1. #1
    Zoo
    Guest

    How can use LONGLONG type of C++ Dll in 'Declare Function' statement?

    Hi,
    I have a dll. I want to use a function in the dll on Excel VBA.
    The fuction is below.

    int GetDiskSpaceLeft(DWORD dwID, LONGLONG *lpllSpace);

    If this were "int GetDiskSpaceLeft(DWORD dwID, LONG *lpllSpace);",
    I knew how to use that.
    Private Declare Function GetDiskSpaceLeft lib 'xx.dll' (ByVal dwID as Long,
    ByRef lSpace as Long)

    However it's not "Long", but "LongLong"

    How can I use the dll function?



  2. #2
    Mat P:son
    Guest

    RE: How can use LONGLONG type of C++ Dll in 'Declare Function' stateme

    One really quick'n'dirty solution I saw posted on a MSDN webpage is to use
    the VB datatype Currency instead of LongLong, but you then have to remember
    to scale it by a factor 10,000 as well. The snippet below is taken from the
    following webpage:


    http://msdn.microsoft.com/library/de...ightweight.asp

    Surely, there must be cleaner ways of implementing support for LongLong, so
    I'll keep on looking, and when I find something I'll post it here...

    Cheers,
    /MP

    =================================================

    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 DiskInfo()
    Dim cuAvailable As Currency
    Dim cuTotal As Currency
    Dim cuFree As Currency

    Call GetDiskFreeSpaceEx("C:\", cuAvailable, _
    cuTotal, cuFree)
    Debug.Print "Disk space info" & vbCr & _
    "Available : "; _
    FormatByteSize(cuAvailable * 10000) & vbCr & _
    "Total : "; _
    FormatByteSize(cuTotal * 10000) & vbCr & _
    "Free : "; _
    FormatByteSize(cuFree * 10000) & vbCr & _
    "Used : "; _
    FormatByteSize((cuTotal - cuFree) * 10000)
    End Sub

    =================================================

    "Zoo" wrote:

    > Hi,
    > I have a dll. I want to use a function in the dll on Excel VBA.
    > The fuction is below.
    >
    > int GetDiskSpaceLeft(DWORD dwID, LONGLONG *lpllSpace);
    >
    > If this were "int GetDiskSpaceLeft(DWORD dwID, LONG *lpllSpace);",
    > I knew how to use that.
    > Private Declare Function GetDiskSpaceLeft lib 'xx.dll' (ByVal dwID as Long,
    > ByRef lSpace as Long)
    >
    > However it's not "Long", but "LongLong"
    >
    > How can I use the dll function?
    >
    >
    >


  3. #3
    Zoo
    Guest

    Re: How can use LONGLONG type of C++ Dll in 'Declare Function' stateme

    I tried that. It worked fine.
    Thank you for your great help!

    "Mat P:son" <[email protected]> wrote in message
    news:[email protected]...
    > One really quick'n'dirty solution I saw posted on a MSDN webpage is to use
    > the VB datatype Currency instead of LongLong, but you then have to

    remember
    > to scale it by a factor 10,000 as well. The snippet below is taken from

    the
    > following webpage:
    >
    >
    >

    http://msdn.microsoft.com/library/de...ightweight.asp
    >
    > Surely, there must be cleaner ways of implementing support for LongLong,

    so
    > I'll keep on looking, and when I find something I'll post it here...
    >
    > Cheers,
    > /MP
    >
    > =================================================
    >
    > 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 DiskInfo()
    > Dim cuAvailable As Currency
    > Dim cuTotal As Currency
    > Dim cuFree As Currency
    >
    > Call GetDiskFreeSpaceEx("C:\", cuAvailable, _
    > cuTotal, cuFree)
    > Debug.Print "Disk space info" & vbCr & _
    > "Available : "; _
    > FormatByteSize(cuAvailable * 10000) & vbCr & _
    > "Total : "; _
    > FormatByteSize(cuTotal * 10000) & vbCr & _
    > "Free : "; _
    > FormatByteSize(cuFree * 10000) & vbCr & _
    > "Used : "; _
    > FormatByteSize((cuTotal - cuFree) * 10000)
    > End Sub
    >
    > =================================================
    >
    > "Zoo" wrote:
    >
    > > Hi,
    > > I have a dll. I want to use a function in the dll on Excel VBA.
    > > The fuction is below.
    > >
    > > int GetDiskSpaceLeft(DWORD dwID, LONGLONG *lpllSpace);
    > >
    > > If this were "int GetDiskSpaceLeft(DWORD dwID, LONG *lpllSpace);",
    > > I knew how to use that.
    > > Private Declare Function GetDiskSpaceLeft lib 'xx.dll' (ByVal dwID as

    Long,
    > > ByRef lSpace as Long)
    > >
    > > However it's not "Long", but "LongLong"
    > >
    > > How can I use the dll function?
    > >
    > >
    > >



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1