?
Solved

LONGLONG C++ to VB conversion

Posted on 2005-03-25
14
Medium Priority
?
736 Views
Last Modified: 2008-01-09
Hi,

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 ?
0
Comment
Question by:Marco_Panza
[X]
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
14 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 13630767
What is the API?  
0
 
LVL 38

Expert Comment

by:PaulHews
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.
0
 
LVL 23

Expert Comment

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

Look at this :

http://www.csidata.com/custserv/onlinehelp/VBSdocs/vbs218.htm

Then from there you can determine what data type to use :)
0
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

by:Marco_Panza
ID: 13631137
The API is

'DeviceIoControl' with FSCTL_EXTEND_VOLUME .

Details:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/fsctl_extend_volume.asp

Thanks !
0
 
LVL 38

Expert Comment

by:PaulHews
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
''');


Private Type OVERLAPPED
           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?
0
 

Author Comment

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

1) Use an instrutions like:

Type LONG_LONG
   LOW AS ??
   HIGH AS ??
end type

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

******************************

Thanks PaulHews The number of sectors is 160055531
0
 
LVL 38

Expert Comment

by:PaulHews
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.
0
 

Author Comment

by:Marco_Panza
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 ?
0
 
LVL 38

Expert Comment

by:PaulHews
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.
0
 
LVL 19

Expert Comment

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

S
0
 
LVL 38

Accepted Solution

by:
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

Ex:

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)
    Next
    CopyMemory x, c, 8
    Debug.Print x.HIGH, x.LOW
   
End Sub
0
 

Author Comment

by:Marco_Panza
ID: 13632400
Ok ,

Now I try this Code ...
0
 

Author Comment

by:Marco_Panza
ID: 13632471
Wow

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

VERY GOOD !!!!!
0

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