[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 753
  • Last Modified:

LONGLONG C++ to VB conversion

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
Marco_Panza
Asked:
Marco_Panza
  • 6
  • 5
  • 2
  • +1
1 Solution
 
PaulHewsCommented:
What is the API?  
0
 
PaulHewsCommented:
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
 
gecko_au2003Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Marco_PanzaAuthor Commented:
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
 
PaulHewsCommented:
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
 
Marco_PanzaAuthor Commented:
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
 
PaulHewsCommented:
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
 
Marco_PanzaAuthor Commented:
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
 
PaulHewsCommented:
>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
 
ShauliCommented:
LongLong's equivalent in VB can be the Currency Data Type, as both are 8 bytes integers.

S
0
 
PaulHewsCommented:
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
 
Marco_PanzaAuthor Commented:
Ok ,

Now I try this Code ...
0
 
Marco_PanzaAuthor Commented:
Wow

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

VERY GOOD !!!!!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 6
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now