-
Jul 30th, 2009, 05:31 AM
#1
Thread Starter
Frenzied Member
How can I have unsigned Integers and Longs in VB6?
I know there are ONLY signed versions of the 2-byte Integer and 4-byte Long in VB6. But I have a burning question. Is there any DLL file that adds unsigned Integer and unsigned Long capabilities to VB6? If Microsoft hasn't made one, has any computer programing hobbiest made such a DLL file? If there is one, where can I download it?
-
Jul 30th, 2009, 06:14 AM
#2
Addicted Member
Re: How can I have unsigned Integers and Longs in VB6?
hmmmmmm... Not sure about the DLL part, but if you want more memory space use larger data types such a Currency and Double. Otherwise, you might need mathematical help to implement DataTypes as User Defined Types in VB6. In any case:
I think your talking about something like this.
Code:
Private Type LARGE_INTEGER
lowpart As Long
highpart As Long
End Type
Unfortunately, i dont understand how id implement something like this, as my mathematical skills havent yet reached fully into logic gates and bitshifting.
Using Currency DataType for storing integer type values that require more than 4 bytes (VB6 Long). Thanks to Randy Birch for enlightening me a while back.
Code:
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32.dll" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, ByRef lpFreeBytesAvailableToCaller As Any, ByRef lpTotalNumberOfBytes As Any, ByRef lpTotalNumberOfFreeBytes As Any) As Long
Private Function getOutputDirDriveFreeSpace()
Dim cFreeSpace As Currency, cTotalSpace As Currency, lRet As Long
lRet = GetDiskFreeSpaceEx("C:\", ByVal 0, cTotalSpace, cFreeSpace)
If (lRet <> 0) Then
'Curreny has a precision of 4 decimal places, so multiplay by 10000 to move the decimal point to the end
cFreeSpace = (cFreeSpace * 10000) / 1024# / 1024# / 1024#
cTotalSpace = (cTotalSpace * 10000) / 1024# / 1024# / 1024#
Call MsgBox(Format(cFreeSpace, "#,##0.00") + " GB / " + Format(cTotalSpace, "#,##0.00") + " GB")
Else
Call MsgBox("Invalid Dir")
End If
End Function
Last edited by Xiphias3; Jul 30th, 2009 at 06:16 AM.
Reason: ;]
-
Jul 30th, 2009, 06:59 AM
#3
Re: How can I have unsigned Integers and Longs in VB6?
You can write functions that simulate unsigned integer math using signed integer types. Although any such function would be much slower than native unsigned support it would still probably be faster than making a call to a DLL (if such a DLL existed).
Here are a couple of rather hefty but speedy functions for unsigned addition and multiplication of Longs. There are much simpler techniques which involve coercing/casting to other types.
vb Code:
Public Function uAdd(ByVal A As Long, ByVal B As Long) As Long
Dim lOr As Long, lAnd As Long, P As Long
lOr = (A Or B) And &HC0000000
If lOr Then 'it might overflow
lAnd = (A And B) And &HC0000000
P = (A And &H3FFFFFFF) + (B And &H3FFFFFFF)
Select Case lAnd 'the last two bits common to both numbers
Case 0&
If (P And lOr) Then
If lOr < 0 Then uAdd = (P And &H3FFFFFFF) Else uAdd = (P And &H3FFFFFFF) Or &H80000000
Else
uAdd = P Or lOr
End If
Case &H80000000: If (P And lOr) Then uAdd = (P And &H3FFFFFFF) Or &H80000000 Else uAdd = P Or (lOr And &H40000000)
Case &H40000000: If (lOr < 0) Then uAdd = P Else uAdd = P Or &H80000000
Case Else: uAdd = P Or &H80000000
End Select
Else 'it won't overflow
uAdd = A + B
End If
End Function
Public Function uMult(ByVal A As Long, ByVal B As Long) As Long
'Unsigned 32bit integer multiplication with signed 32bit numbers
'Returns a signed 32bit number as if it were unsigned.
'Will overflow without error
'It might look ugly, but it's much faster than converting Longs to Doubles and back (when compiled)
Dim A1 As Long, A2 As Long
Dim B1 As Long, B2 As Long
Dim P As Long, P2 As Long
A1 = A And &H7FFF&
B1 = B And &H7FFF&
A2 = (A And &H3FFF8000) \ &H8000& 'quicker than... (A \ &h8000&) And &H7FFF&
B2 = (B And &H3FFF8000) \ &H8000& 'quicker than... (A \ &h8000&) And &H7FFF&
'multiply first 2 bits of A by last 2 bits of B
Select Case B And &HC0000000
Case 0&
Case &H40000000
Select Case A And 3&
Case 0&:
Case 1&: P = &H40000000
Case 2&: P = &H80000000
Case 3&: P = &HC0000000
End Select
Case &H80000000
If A And 1& Then P = &H80000000
Case Else
Select Case A And 3&
Case 0&:
Case 1&: P = &HC0000000
Case 2&: P = &H80000000
Case 3&: P = &H40000000
End Select
End Select
'multiply first 2 bits of B by last 2 bits of A
Select Case A And &HC0000000
Case 0&
Case &H40000000
Select Case B And 3&
Case 0& 'P+0
Case 1&: If P And &H40000000 Then P = P Xor &HC0000000 Else P = P Or &H40000000 'P+&H40000000
Case 2&: P = P Xor &H80000000 'P+&H80000000
Case 3&: If P And &H40000000 Then P = P Xor &H40000000 Else P = P Xor &HC0000000 'P+&H40000000+&H80000000
End Select
Case &H80000000
If B And 1& Then P = P Xor &H80000000 'P+&H80000000
Case Else
Select Case B And 3&
Case 0& 'P+0
Case 1&: If P And &H40000000 Then P = P Xor &H40000000 Else P = P Xor &HC0000000 'P+&H40000000+&H80000000
Case 2&: P = P Xor &H80000000 'P+&H80000000
Case 3&: If P And &H40000000 Then P = P Xor &HC0000000 Else P = P Or &H40000000 'P+&H40000000
End Select
End Select
'multiply bits 16 and 17 of A and B
Select Case (A2 * B2) And &H3&
Case 0& 'P+0
Case 1&: If P And &H40000000 Then P = P Xor &HC0000000 Else P = P Or &H40000000 'P+&H40000000
Case 2&: P = P Xor &H80000000 'P+&H80000000
Case Else: If P And &H40000000 Then P = P Xor &H40000000 Else P = P Xor &HC0000000 'P+&H40000000+&H80000000
End Select
'multiply first 15 bits of A and B
P = (A1 * B1) Or P
'multiply first 15 bits of A with bits 16 to 30 of B
P2 = A1 * &H2&
If P2 And &H10000 Then P2 = ((P2 And &HFFFF&) * &H8000&) Or &H80000000 Else P2 = (P2 And &HFFFF&) * &H8000&
P = uAdd(P, P2)
'multiply first 15 bits of B with bits 16 to 30 of A
P2 = A2 * &H1&
If P2 And &H10000 Then P2 = ((P2 And &HFFFF&) * &H8000&) Or &H80000000 Else P2 = (P2 And &HFFFF&) * &H8000&
uMult = uAdd(P, P2)
End Function
-
Jul 30th, 2009, 07:06 AM
#4
Addicted Member
Re: How can I have unsigned Integers and Longs in VB6?
Originally Posted by Milk
You can write functions that simulate unsigned integer math using signed integer types. Although any such function would be much slower than native unsigned support it would still probably be faster than making a call to a DLL (if such a DLL existed).
Here are a couple of rather hefty but speedy functions for unsigned addition and multiplication of Longs. There are much simpler techniques which involve coercing/casting to other types.
vb Code:
Public Function uAdd(ByVal A As Long, ByVal B As Long) As Long
Dim lOr As Long, lAnd As Long, P As Long
lOr = (A Or B) And &HC0000000
If lOr Then 'it might overflow
lAnd = (A And B) And &HC0000000
P = (A And &H3FFFFFFF) + (B And &H3FFFFFFF)
Select Case lAnd 'the last two bits common to both numbers
Case 0&
If (P And lOr) Then
If lOr < 0 Then uAdd = (P And &H3FFFFFFF) Else uAdd = (P And &H3FFFFFFF) Or &H80000000
Else
uAdd = P Or lOr
End If
Case &H80000000: If (P And lOr) Then uAdd = (P And &H3FFFFFFF) Or &H80000000 Else uAdd = P Or (lOr And &H40000000)
Case &H40000000: If (lOr < 0) Then uAdd = P Else uAdd = P Or &H80000000
Case Else: uAdd = P Or &H80000000
End Select
Else 'it won't overflow
uAdd = A + B
End If
End Function
Public Function uMult(ByVal A As Long, ByVal B As Long) As Long
'Unsigned 32bit integer multiplication with signed 32bit numbers
'Returns a signed 32bit number as if it were unsigned.
'Will overflow without error
'It might look ugly, but it's much faster than converting Longs to Doubles and back (when compiled)
Dim A1 As Long, A2 As Long
Dim B1 As Long, B2 As Long
Dim P As Long, P2 As Long
A1 = A And &H7FFF&
B1 = B And &H7FFF&
A2 = (A And &H3FFF8000) \ &H8000& 'quicker than... (A \ &h8000&) And &H7FFF&
B2 = (B And &H3FFF8000) \ &H8000& 'quicker than... (A \ &h8000&) And &H7FFF&
'multiply first 2 bits of A by last 2 bits of B
Select Case B And &HC0000000
Case 0&
Case &H40000000
Select Case A And 3&
Case 0&:
Case 1&: P = &H40000000
Case 2&: P = &H80000000
Case 3&: P = &HC0000000
End Select
Case &H80000000
If A And 1& Then P = &H80000000
Case Else
Select Case A And 3&
Case 0&:
Case 1&: P = &HC0000000
Case 2&: P = &H80000000
Case 3&: P = &H40000000
End Select
End Select
'multiply first 2 bits of B by last 2 bits of A
Select Case A And &HC0000000
Case 0&
Case &H40000000
Select Case B And 3&
Case 0& 'P+0
Case 1&: If P And &H40000000 Then P = P Xor &HC0000000 Else P = P Or &H40000000 'P+&H40000000
Case 2&: P = P Xor &H80000000 'P+&H80000000
Case 3&: If P And &H40000000 Then P = P Xor &H40000000 Else P = P Xor &HC0000000 'P+&H40000000+&H80000000
End Select
Case &H80000000
If B And 1& Then P = P Xor &H80000000 'P+&H80000000
Case Else
Select Case B And 3&
Case 0& 'P+0
Case 1&: If P And &H40000000 Then P = P Xor &H40000000 Else P = P Xor &HC0000000 'P+&H40000000+&H80000000
Case 2&: P = P Xor &H80000000 'P+&H80000000
Case 3&: If P And &H40000000 Then P = P Xor &HC0000000 Else P = P Or &H40000000 'P+&H40000000
End Select
End Select
'multiply bits 16 and 17 of A and B
Select Case (A2 * B2) And &H3&
Case 0& 'P+0
Case 1&: If P And &H40000000 Then P = P Xor &HC0000000 Else P = P Or &H40000000 'P+&H40000000
Case 2&: P = P Xor &H80000000 'P+&H80000000
Case Else: If P And &H40000000 Then P = P Xor &H40000000 Else P = P Xor &HC0000000 'P+&H40000000+&H80000000
End Select
'multiply first 15 bits of A and B
P = (A1 * B1) Or P
'multiply first 15 bits of A with bits 16 to 30 of B
P2 = A1 * &H2&
If P2 And &H10000 Then P2 = ((P2 And &HFFFF&) * &H8000&) Or &H80000000 Else P2 = (P2 And &HFFFF&) * &H8000&
P = uAdd(P, P2)
'multiply first 15 bits of B with bits 16 to 30 of A
P2 = A2 * &H1&
If P2 And &H10000 Then P2 = ((P2 And &HFFFF&) * &H8000&) Or &H80000000 Else P2 = (P2 And &HFFFF&) * &H8000&
uMult = uAdd(P, P2)
End Function
Haha! Yea, everything here i dont understand.
-
Jul 30th, 2009, 02:35 PM
#5
Re: How can I have unsigned Integers and Longs in VB6?
In many cases you can just use Long instead of unsigned Integer and Currency is probably the next most efficient replacement for unsigned Long. However, if you need to save to a file or manipulate memory things are different... there are tons of case dependant situatations.
So the burning question is: what are you trying to achieve that would require unsigned Integer & Long?
-
Jul 30th, 2009, 06:21 PM
#6
Thread Starter
Frenzied Member
Re: How can I have unsigned Integers and Longs in VB6?
I know VB6 has these DataTypes for integer numbers:
Byte (1 byte of unsigned data)
Integer (2 bytes of signed data)
Long (4 bytes of signed data)
What I need add to those basic DataTypes are these:
UInteger (2 bytes of unsigned data)
ULong (4 bytes of unsigned data)
Why? Why not use a Long instead of Integer for unsigned "integers", or Currency instead of Long for unsigned "longs"? Well I have a very good reason. This is inefficient in file size. If I have a number that only needs 2 bytes of data, I shouldn't have to use 4 bytes. If I have a number that only needs 4 bytes, I shouldn't have to use 8 bytes. This will save file space, and in many cases I'll be writing to a file that is meant to be read by an already made program who's specifications REQUIRE an unsigned integer or unsigned long. If I use for example a long instead of an unsigned integer, the program will NOT correctly read the file. I need a fix to that. User defined types don't add Datatypes to those natively in VB. That is
Code:
Public type UInteger
HighByte as byte
LowByte as byte
End type
can NOT be written to with
Code:
Dim x as UInteger
x = 60000
because it isn't really a DataType, it is just a user defined type with 2 parts, each of which is a byte.
What I need is a DLL file (or any other addon that I could use, whether official from MS or unofficial from a "hacker", I don't really care) that adds UInteger and ULong into Visual Basic as basic DataTypes, so that the list of DataTypes VB6 can handle would become:
Byte (1 byte of unsigned data)
Integer (2 bytes of signed data)
UInteger (2 bytes of unsigned data)
Long (4 bytes of signed data)
ULong (4 bytes of unsigned data)
If anyone on this site knows of such an addon and the site that I could download it from, please link to that site.
-
Jul 30th, 2009, 06:51 PM
#7
Re: How can I have unsigned Integers and Longs in VB6?
Have you looked at Milk's posting above? If you don't want to expand the byte size, then you'll have to use conversion functions that convert both ways to signed/unsigned from unsigned/signed.
For example, an Integer value of Max(Int Positive Value)+1 is an overflow. But converted to unsigned, it becomes a negative value in VB. However, in any app that expects UINT will see that negative VB integer as a positive UINT, since UINT can't be negative anyway.
Edited: here are some I have used in the past. Double check it, I had to modify some things when I pulled it out of an existing project on PSC. That project of mine includes a bunch of bit manipulation routines -- worth checking out if you want to expand your knowledge.
Code:
Private Const MaxUnsignedLongAnd1 As Double = 4294967296#
Private Const MaxSignedLongAnd1 As Double = 2147483648#
Private Const MaxUnsignedInt As Long = 65536
Private Const MaxSignedIntAnd1 As Long = 32768
Public Function SignedIntegerToUnsigned(ByVal theValue As Integer) As Long
' function converts a signed integer to an unsigned Long
SignedIntegerToUnsigned = (theValue And &HFFFF&)
End Function
Public Function UnsignedIntegerToSigned(ByVal theValue As Long) As Integer
' function converts a Long to a signed integer
' if the passed value contains more than 16 usable bits, we can't scrunch 16+ into a 16bit variable
If theValue < 0& Or theValue > MaxUnsignedInt - 1& Then Exit Function ' overflow
If theValue < MaxSignedIntAnd1 Then
UnsignedIntegerToSigned = theValue
Else
UnsignedIntegerToSigned = theValue - MaxUnsignedInt
End If
End Function
Public Function SignedLongToUnsigned(ByVal theValue As Long) As Double
' function converts a signed long to an unsigned Double
If (theValue And &H80000000) Then
SignedLongToUnsigned = theValue + MaxUnsignedLongAnd1
Else
SignedLongToUnsigned = theValue
End If
End Function
Public Function UnsignedLongToSigned(ByVal theValue As Double) As Long
' function converts a Double to a signed Long
' if the passed value contains more than 32 usable bits, we can't scrunch 32+ into a 32bit variable
If theValue < 0# Or theValue > MaxUnsignedLongAnd1 Then Exit Function ' overflow
If theValue < MaxSignedLongAnd1 Then
UnsignedLongToSigned = theValue
Else
UnsignedLongToSigned = theValue - MaxUnsignedLongAnd1
End If
End Function
Last edited by LaVolpe; Jul 30th, 2009 at 07:02 PM.
-
Jul 30th, 2009, 07:14 PM
#8
Thread Starter
Frenzied Member
Re: How can I have unsigned Integers and Longs in VB6?
Well I still believe there must be some addon somewhere I can install that will give me the desired effect. I don't want to have to type in all that code JUST to set it up for using unsinged numbers. If I do that, every program I make I'll have to waste time typing ALL that in just for preparing data types. That time would be better spent typing in the ACTUAL program code.
-
Jul 30th, 2009, 07:21 PM
#9
Re: How can I have unsigned Integers and Longs in VB6?
All that code? Really? Ummm, if you create a class that contains the functions you want, you then only have to add the class to your new projects. If you add all that code to a module, then you'd only have to add the module to your new projects. Of course you would have to call the functions. That is one of the purposes of modules and classes -- reusability.
-
Jul 30th, 2009, 07:34 PM
#10
Hyperactive Member
Re: How can I have unsigned Integers and Longs in VB6?
why would you type all that code? you copy/paste it.
-
Jul 30th, 2009, 07:55 PM
#11
Re: How can I have unsigned Integers and Longs in VB6?
If all you are doing is writing these unsigned values to file and you don't actually want to perform any operations with them then you don't really need them as data types.
Hex is written unsigned, the illegal (for integer) x=60000 could be written legally as x=&HEA60.
Alternatively simple short functions could be used to assign values. eg..
Code:
Public Function UInt(ByVal value As Long) As Integer
UInt = value And &H7FFF&
If (value And &H8000&) Then UInt = UInt + &H8000
End Function
Edit: the same function is in Lavolpes code.
Last edited by Milk; Jul 30th, 2009 at 09:30 PM.
-
Jul 30th, 2009, 11:04 PM
#12
Re: How can I have unsigned Integers and Longs in VB6?
This post is supported by the One Liners Community International.
16 lowest bits from Long to Integer:
UInt = (Value And &H7FFF&) Or ((Value And &H8000&) <> 0 And &H8000)
Integer bits copied to Long:
Value = UInt And &HFFFF&
Internally you can handle the Long (just need to ensure you stay within valid 16 bit range). For output you do that simplish math and you can do it inline. Inline code is a lot faster than calling functions. It may not look as pretty as you wanted, but you're asking for a feature that is not natively available in any easy way.
There are some other options though. If you know ASM or C, you can use ThunderVB add-on and write unsigned math. Just remember that when you're trying to display the variable in VB it shows it signed. You can still use the methods above to workaround that issue.
-
Jul 31st, 2009, 12:14 AM
#13
Thread Starter
Frenzied Member
Re: How can I have unsigned Integers and Longs in VB6?
Originally Posted by Merri
It may not look as pretty as you wanted, but you're asking for a feature that is not natively available in any easy way.
There must be some good hacker out there who's figured out how to add this functionality into VB6 by now, as VB6 has been out for a long time. All I need is a link to this hacker's site or his email address so I can ask him to give me a hacked EXE of Visual Basic with this added functionality.
-
Jul 31st, 2009, 12:34 AM
#14
Re: How can I have unsigned Integers and Longs in VB6?
ThunderVB is your best shot and gives you the functionality.
The problem with your assumption is that nobody of us has heard of such a person who has done that. And most of us who have replied to you have been around for a pretty long time, seeing the rise and decline of VB6. Are you really sure you want to do this in VB6? Also, if you're so keen to insist on getting this functionality why you're not gaining yourself the knowledge on how to do it? Or you could always make an executable that reads through a compiled VB6 executable and changes all signed integer machine code instructions to unsigned versions :P
I've always been able to workaround the signed/unsigned issue in practical applications. Even if I have missed unsigned integers I have also missed bit shifting and many other features. VB6 wasn't meant to be a fully capable programming environment, it is first and foremost a tool that lets you do interface quickly. Personally I've been kind of hacking around some things for years and looking for improved performance, but making modifications to the executable or compiler has been out of my interest: I wanted interoperability (ie. the code I post should work in any installation of VB6 as-is).
-
Jul 31st, 2009, 08:04 AM
#15
Re: How can I have unsigned Integers and Longs in VB6?
And there are such functionalities: DLLs people have already created. Google, search PSC and other sites. If you don't want to write the necessary code, nor want to create your own module/class that can be re-used over and over again, then include/reference the DLL you find.
-
Jul 31st, 2009, 01:57 PM
#16
Thread Starter
Frenzied Member
Re: How can I have unsigned Integers and Longs in VB6?
Originally Posted by Merri
ThunderVB is your best shot and gives you the functionality.
I just checked the ThunderVB website, but can't find any download links for ThunderVB or ThunderASM. I can only find a description of it. There are links to download other stuff though. The site is not in English for the most part, so I can't really navigate it well.
Could you please provide a link to download Thunder VB and ThunderASM
-
Jul 31st, 2009, 02:07 PM
#17
Re: How can I have unsigned Integers and Longs in VB6?
I can see the site only in English. If you search for the word "download" on the page I linked to the first thing you find is a link to the download page.
Also a note on ThunderVB: it compiles ASM and C as inline code, and if you make a function that only contains ASM or C it will be compiled as inline code everywhere that function is being called from. This means you have no speed loss that you would have with similar VB6 only methods, and are able to make very simple custom math functions, bitwise handling such as bitshifting etc. - and they even provide a premade stuff that do things like that.
Last edited by Merri; Jul 31st, 2009 at 02:12 PM.
-
Aug 1st, 2009, 05:13 PM
#18
Thread Starter
Frenzied Member
Re: How can I have unsigned Integers and Longs in VB6?
Originally Posted by Merri
I can see the site only in English. If you search for the word "download" on the page I linked to the first thing you find is a link to the download page.
Also a note on ThunderVB: it compiles ASM and C as inline code, and if you make a function that only contains ASM or C it will be compiled as inline code everywhere that function is being called from. This means you have no speed loss that you would have with similar VB6 only methods, and are able to make very simple custom math functions, bitwise handling such as bitshifting etc. - and they even provide a premade stuff that do things like that.
Actually I thought ThunderASM (not ThunderVB) is what compiled ASM and C. I thought ThunderVB just made it easier to install plugins in VB. By the way, does this Thunder stuff just call actual compilers (which have to be downloaded separately), or does it do the compiling on it's own? And also, once I've defined a C or ASM function, how do I then use it in VB? Are there special commands? Or do I use it the same way I would use a VB function?
-
Aug 1st, 2009, 05:24 PM
#19
Re: How can I have unsigned Integers and Longs in VB6?
All your questions are answered within the link; I feel it unnecessary to repeat the same in different words. Also, I don't have VB6 installed at the moment (new computer) and I haven't had ThunderVB installed in two years or so.
This is the linked page as I can see it:
Code:
ThunderVB
ThunderVB is an add-in for VB6. ThunderVB let's you embed Asm and C instructions directly in you VB source programs. Furthermore ThunVB let's you create a true StdCall Dlls. Moreover ThunVB can extend VB IDE to a basic Asm/C code editor. That means it can do syntax-highlighting of Asm/C keywords and supports intelli-sense for InlineAsm code as well.
We have stopped ThunVB developing because we think the last release is quite stable and we don't have time to work on it.
Sorry, but enjoy the last release and happy Asm/C coding.
Visual Basic will live forever...
MENU
# ThunderVB
# ThunderAsm
# ThunderIDE+
# ThunderDll
# Packer
# Speed Hacks
# VB Internals
# Homepage on SF .NET
# Screenshots
# Download
# Questions about Asm/C/Dll coding
# Bugs
System requirements
# Windows 2000/XP
# Visual Basic 6 with Service Pack 6
You can get Service Pack 6 here.
ThunderVB
aka ThunVB is a core part - it's a container for plugins. ThunVB can load and unload plugins. Also it offers wide range of useful functions that can other plugins freely use. For example API hooking, to SubClass any VB IDE's window, manipulate VB IDE's window, multi-language support and many more low-level functions.
Menu
ThunderAsm
aka ThunAsm allows to write Asm and C code directly into VB code and compile it. ThunAsm supports MASM, FASM and NASM syntax.
To compile InlineAsm code you will need Masm. You can get MASM 6.14 here.
Unfortunately, the version 6.14 doesn't support SIMD but MASM 6.15 and higher does. If you want to use SIMD, then get MASM 6.15 here.
And to compile InlineC code you will need C compiler. You can get it for free here.
Hint - If you want to link smaller and faster apps, then replace linker that is shipped with VB6 with a newer linker that is shipped with VS2003.
Writting InlineAsm code is pretty straigthforward. See the code below it's a simple Asm function.
Public Function Return10() As Long
'#asm'
'#asm' mov eax, 10
'#asm' ret
'#asm'
End Function
That's a function that returns value 10. As you can see, Asm code is written straight to the VB's code and the code is prefixed by the tag '#asm'.
And now similar C function.
Public Function Return10() As Long
'#c'
'#c' long Return10() {
'#c' return 10;
'#c' }
'#c'
End Function
Again, C code is written straight to the VB's code and the code is prefixed by the tag '#c'.
Now come code samples that will explain basic Asm/C coding strategies. For example calling API from Asm/C code, declaring Asm/C variables, accessing VB arrays/strings from Asm/C code and many others important things.
Download all Asm code samples
Download all C code samples
Menu
ThunderIDE+
aka ThunIDE can highlight Asm and C code that is written in VB IDE. You can choose your own colours for Asm/C keywords. Check the screenshots to see it on your own eyes. It looks really cool.
Menu
ThunderDll
aka ThunDll can compile Dll libraries. Dll's can export functions, you can change Base-Address, change name of EntryPoint and the Dll's can contain GUI (Forms) as well. The Dll's can be called from any language (C, Asm, Delphi...VB).
To compile StdCall Dll's you will need ThunderAsm. Be shure that during linking is ThunderAsm loaded.
Download all Dll code samples
Menu
Packer
This tool can compress files after compilation. You can use your favourite packer and specify its command line that will be used for packing executable files or dll's after linking.
Menu
Speed Hacks
We've coded several InlineAsm fucntions that beat their VB's counterparts. Get fast InStr, StrComp and other string and math fucntions right here.
# Math Funtions Sqrt (FPU, SSE and 3Dnow variants)
# Long to Single and Long to Double conversion
# Integer to Single and Integer to Double conversion
# VB functions Sng, Fix, Clng, Csng and Cdbl
# Sorting Algorithms QuickSort and QSort
# SelectSort, InsertSort, BubbleSort and CombSort
# ShellSort and HeapSort
# BinarySearch
# String Functions Asc, AscW
# Chr, ChrW
# InStr
# LCase, UCase
# Left, Right
# Len (only for Strings)
# Mid
# StrReverse
# Trim, LTrim, RTrim
# Miscellaneous string functions Boyer-Moore-Horspool String Search
# Memory Functions Common string functions ObjPtr
# StrPtr
# VarPtr (only for Longs, Integers, Bytes and Strings)
# Miscellaneous memory functions CopyMemory (based on MMX and SSE)
Download all Speed Hacks
Menu
VB Internals
We have discovered some interesting things about VB...
# ThunRTMain secrets
Some basic things about ThunRTMain.
# Undocumented Memory Functions
There are 2 undocumented memory functions in msvbvm60.dll - __vbaCopyBytes and __vbaCopyBytesZero. This essay explains how they work and what for they can be used.
# Align VB Arrays
I've coded a simple routine that can align array of Long's to 16, 32, 64 and 128 byte boundaries. This can be usefull when dealing with SIMD.
Download all VB Internals articles
Menu
ThunderVB Development Team
drkIIRaziel, Libor a Readwulf
-
Aug 1st, 2009, 07:25 PM
#20
Thread Starter
Frenzied Member
Re: How can I have unsigned Integers and Longs in VB6?
Unfortunately I have to freaking download C++ 2008 Express to use the C functionality of ThunderASM. When making something like ThunderASM they really need to start including the entire C library with their own program as part of a package, so one doesn't have to make additional downloads. Besides I would NEVER use C++ or any other form of C on its own so I shouldn't have to install the entire stinking C++ software. I would ONLY use C programing through ThunderASM to use in visual basic, as VB is my primary programing language.
-
Aug 28th, 2011, 07:16 PM
#21
New Member
Re: How can I have unsigned Integers and Longs in VB6?
I have the same problem
I think the person who asked the question wants to get back a value from a Api
You all respond with conversion functions in VB to get the unsigned long variable. etc.,
But I think the question of who asked the question was the same as mine:
What data type for the Api's return values without get an overflow?
example
WmiService.ExecQuery("Select * from Win32_DiskDrive", , 48)
Class Win32_DiskDrive returns many values uint16, uint32, uint64
For example, if I declare
Public Type UInt32
MyUInt32 As Long
End Type
both are signed numbers 32 bits (4 bytes), so it should be good
Except that
UInt32 is From 0 To 4,294,967,295.
instead
Long is From -2.147.483.648 To 2.147.483.647.
The same amount of numbers, 4,294,967,295 , but in different range, if the Api returned , for example, 3.147.483.647 .The long will give Overflow..........
Can I use a larger type, which occupies more bytes?
For example, if I declare
Public Type UInt32
MyUInt32 As currency ' Currency is numer 64 bit (8 byte)
End Type
Beyond the waste of ram, MyUInt32 may contain 3.147.483.647 without giving Overflow
But the fact that UInt32 is 32 bit (4 byte) and Currency is a 64 bit (8 byte). will cause me problems?
I am very grateful for your attention
Please help me not having to throw away all my knowledge in vb6, to continue programming in VB6 I need to use the Api,
-
Aug 28th, 2011, 10:10 PM
#22
Re: How can I have unsigned Integers and Longs in VB6?
This might be better off in its own thread, you can always link to other threads you feel they are related.
If the API expects a type of 4 bytes you must give it a type of 4 bytes.
With the example you give the Long will not overflow but rather than having a value of 3'147'483'647 it will have a value of -1'147'483'649.
You can deal with this by checking if the return is negative and if so coerce it to a type such as Currency and then add 4'294'967'296 to it to get the value you want.
Code:
Dim myLong As Long, myCur As Currency
myLong = APIFunctionThatReturnsUInt32()
myCur = CCur(myLong)
If myCur < 0 Then
myCur = myCur + 4294967295@
End If
-
Aug 29th, 2011, 06:50 AM
#23
New Member
Re: How can I have unsigned Integers and Longs in VB6?
Originally Posted by Milk
This might be better off in its own thread, you can always link to other threads you feel they are related.
If the API expects a type of 4 bytes you must give it a type of 4 bytes.
With the example you give the Long will not overflow but rather than having a value of 3'147'483'647 it will have a value of -1'147'483'649.
You can deal with this by checking if the return is negative and if so coerce it to a type such as Currency and then add 4'294'967'296 to it to get the value you want.
Code:
Dim myLong As Long, myCur As Currency
myLong = APIFunctionThatReturnsUInt32()
myCur = CCur(myLong)
If myCur < 0 Then
myCur = myCur + 4294967295@
End If
Ok i started my tread if you whant take a look
http://www.vbforums.com/showthread.p...60#post4059160
i think is important for us to still support vb6 if someoneelse (Mic...t) do not do.
Thank
-
Mar 17th, 2024, 12:05 PM
#24
New Member
Re: How can I have unsigned Integers and Longs in VB6?
My code on github may be useful:
github.com/RZulu54/VBA7_ULongLong
Emulate ULongLong 64 bit unsigned integers with VBA7 (64/32 bit MsOffice) or VB6 (Visual Basic 6)
For 32-bit MsOffice VBA or VB6 we can use two Long 32-bit signed integers combined in a new datatype TBit64.
this requires functions for basic bit operations like AND, OR, XOR, NOT.
For 64-bit MsOffice VBA7 we can use the new 64-bit signed integer datatype LongLong.
basic bit operations like AND, OR, XOR, NOT do NOT need extra functions but can be used directly.
Functions available for both variants are:
SetBit64, ClearBit64, ShiftLeft64, ShiftRight64, PopCnt64 (number of bits set),
Lsb64 (position of left most bit), Rsb64 (position of left most bit) and some more.
The Ms-Excel file VBA7.xlsm shows how to use these functions for 32/64-bit MsOffice.
For 64-bit Excel there is also a simple chess demonstration how to use 64-bit chessboard logic.
-
Mar 17th, 2024, 12:26 PM
#25
Fanatic Member
Re: How can I have unsigned Integers and Longs in VB6?
Originally Posted by RZULU55
My code on github may be useful:
I'm sure it would...it's just a pity you weren't here THIRTEEN YEARS AGO when the last post before yours was posted.
-
Mar 17th, 2024, 01:30 PM
#26
Re: How can I have unsigned Integers and Longs in VB6?
Originally Posted by RZULU55
My code on github may be useful:
github.com/RZulu54/VBA7_ULongLong
Emulate ULongLong 64 bit unsigned integers with VBA7 (64/32 bit MsOffice) or VB6 (Visual Basic 6)
For 32-bit MsOffice VBA or VB6 we can use two Long 32-bit signed integers combined in a new datatype TBit64.
this requires functions for basic bit operations like AND, OR, XOR, NOT.
For 64-bit MsOffice VBA7 we can use the new 64-bit signed integer datatype LongLong.
basic bit operations like AND, OR, XOR, NOT do NOT need extra functions but can be used directly.
Functions available for both variants are:
SetBit64, ClearBit64, ShiftLeft64, ShiftRight64, PopCnt64 (number of bits set),
Lsb64 (position of left most bit), Rsb64 (position of left most bit) and some more.
The Ms-Excel file VBA7.xlsm shows how to use these functions for 32/64-bit MsOffice.
For 64-bit Excel there is also a simple chess demonstration how to use 64-bit chessboard logic.
Unfortunately not the fastest implementations. Check out single-line expressions for LShift32 and RShift32 in my recent Wheeler & Needham’s Tiny Encryption Algorithm.
Using the same idea here are RShift64 and RotR64 (which is implemented as inlined RShift64(X, n) Or LShift64(X, 64 - n))
Code:
Private Function RShift64(ByVal lX As LongLong, ByVal lN As Long) As LongLong
If lN = 0 Then
RShift64 = lX
Else
RShift64 = (lX And (-1 Xor LNG_SIGN_BIT)) \ LNG_POW2(lN) Or -(lX < 0) * LNG_POW2(63 - lN)
End If
End Function
Private Function RotR64(ByVal lX As LongLong, ByVal lN As Long) As LongLong
'--- RotR64 = RShift64(X, n) Or LShift64(X, 64 - n)
Debug.Assert lN <> 0
RotR64 = ((lX And (-1 Xor LNG_SIGN_BIT)) \ LNG_POW2(lN) Or -(lX < 0) * LNG_POW2(63 - lN)) Or _
((lX And (LNG_POW2(lN - 1) - 1)) * LNG_POW2(64 - lN) Or -((lX And LNG_POW2(lN - 1)) <> 0) * LNG_SIGN_BIT)
End Function
Being short single-line expressions is useful when you want to inline these for fastest performance like in Ascon Lightweight Authenticated Encryption & Hashing.
cheers,
</wqw>
Last edited by wqweto; Mar 17th, 2024 at 01:34 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|