Generate a DLL Base Address

Every ActiveX OCX file and DLL are supposed to have their own DLL Base Address which specifies a location in the memory where it can be loaded. If a program has the same DLL Base Address, windows will move your application to a different location, which obviously damages performance as your app loads up. That is why you should always change it from its default base address by going to Project|Properties|Compile. Once you are there, however, you need to know a valid value to enter! The code below will generate a random base address for you. Read the comments to find out how!

'// 65536 * 256
'// DLL Base Addresses must be a multiple of 64K (65536)
'// LowerBound = 16777216 (which is 64K * 256)
'// UpperBound = 2147483648 (which is 64K * 32768)
'// 1) Generate Random Number between 256 and 32768
'// 2) Multiply by 64K
'// 3) Convert generated value to a Long value
'// 4) Convert generated value to Hex
'// 5) Convert generated string to lowercase (so that the letters are lower case)
'// 6) Add &H in front of string
Randomize
Debug.Print = "DLL Base Address: &H" & LCase(Hex(CLng((32768 - 256 + 1) * Rnd + 256) * 65536))

You might also like...

Comments

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” - Martin Fowler