LONGLONG C++ to VB conversion

Posted on 2005-03-25
Medium Priority
Last Modified: 2008-01-09

I was use a API that required a value with 'LONGLONG' type but VB don' t support this type.What can i do create a 'LONGLONG' compatible type ?
Question by:Marco_Panza
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
  • +1
LVL 38

Expert Comment

ID: 13630767
What is the API?  
LVL 38

Expert Comment

ID: 13630811
You may be able to use a byte array or even a Currency type with some trickery, but if you let us know the API we might be able to give you specific help.
LVL 23

Expert Comment

ID: 13630918
You could store it into a variant data type and use VarType(VariableName)

Look at this :


Then from there you can determine what data type to use :)
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 13631137
The API is

'DeviceIoControl' with FSCTL_EXTEND_VOLUME .



Thanks !
LVL 38

Expert Comment

ID: 13631277
So it's the size of the volume.  You should be able to use this declaration:

Option Explicit
'''BOOL DeviceIoControl(
'''  (HANDLE) hDevice,           // handle to device
'''  FSCTL_EXTEND_VOLUME,        // dwIoControlCode
'''  (LPVOID) lpInBuffer,        // input buffer
'''  (DWORD) nInBufferSize,      // size of input buffer
'''  NULL,                       // lpOutBuffer
'''  0,                          // nOutBufferSize
'''  (LPDWORD) lpBytesReturned,  // number of bytes returned
'''  (LPOVERLAPPED) lpOverlapped // OVERLAPPED structure

           Internal As Long
           InternalHigh As Long
           offset As Long
           OffsetHigh As Long
           hEvent As Long
End Type

Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, _
        ByVal dwIoControlCode As Long, lpInBuffer As Any, _
        ByVal nInBufferSize As Long, lpOutBuffer As Any, _
        ByVal nOutBufferSize As Long, lpBytesReturned As Long, _
        lpOverlapped As OVERLAPPED) As Long

The fun is getting the size of the volume into a byte array without errors.  Where are you getting that number from?

Author Comment

ID: 13631411
Thanks  gecko_au2003 but 'LONG LONG' is not VB type and for me the ways are 2:

1) Use an instrutions like:

   LOW AS ??
   HIGH AS ??
end type

2) Use an array but i don't known ....


Thanks PaulHews The number of sectors is 160055531
LVL 38

Expert Comment

ID: 13631543
You can use a type like that.

Private Type LONG_LONG
   LOW As Long
   HIGH As Long
End Type

If the number is smaller than a long, just pass it to the LOW part.
x.LOW = 160055531

But where that might work in this case, it doesn't work where the number of sectors is larger than the max that you can have in a long...

The datatypes that would actually hold a 64 bit integer tend to be floating point which can introduce errors in calculations.  So depending where your source gets this information (string? another API?) you would have to do the conversion appropriately.

Author Comment

ID: 13631599
Thare is anthother problem:

The long type is signed.Are you sure that work ?
The LongLong Type I dont known if it is signed or unsigned.

What you thing ?
LVL 38

Expert Comment

ID: 13631712
>The long type is signed.Are you sure that work ?

The goal is to get the bytes into the right position, then signed or unsigned doesn't make any difference.  The API pass as "Any" allows a lot of flexibility that way.

With this example, because 160055531 is small enough not to occupy the highest bit in a long, it should work.  However, when it's too big to fit in a long, you will have problems.
LVL 19

Expert Comment

ID: 13631728
LongLong's equivalent in VB can be the Currency Data Type, as both are 8 bytes integers.

LVL 38

Accepted Solution

PaulHews earned 2000 total points
ID: 13631814
But you have to insert a decimal point there.  It's easy if the input is a string.  But the other techniques I mentioned work as well


Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)

Private Sub Command1_Click()
    Dim x As LONG_LONG
    Dim c As Currency
    c = 16005.5531
    CopyMemory bInBuffer(0), c, 8
    Dim i
    For i = 0 To 7
        Debug.Print bInBuffer(i)
    CopyMemory x, c, 8
    Debug.Print x.HIGH, x.LOW
End Sub

Author Comment

ID: 13632400
Ok ,

Now I try this Code ...

Author Comment

ID: 13632471

Your code work fine  !!!!!!!!!


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question