Using The Native Functions in VBs Runtime DLL

Category:
System/API
Type:
Snippets
Difficulty:
Advanced
Author:
Voodoo Attack!!

Version Compatibility: Visual Basic 6, Visual Basic 5

More information:
These are native undocumented APIs. The author recommends you study the topic of pointers/memory addresses before using this. THE FUNCTIONS: While I was exploring in the VB runtime (using depends), I discovered some functions in there. Though totally undocumented, I found them most useful while programming my own apps. I found two functions that grabbed my attention instantly, VbaObjSet and vbaObjSetAddref. After experimenting for 3 weeks, I figured out the functions' parameters and attributes, and used them in my applications. I think it’s time to share my discovery. Below are the functions and what you can do with them. vbaObjSet: Works pretty much like a Set y = x statement in Visual Basic, which doesn't increment the reference counters for the object. Note: This can be hazardous as it can cause your application to crash if used excessively, and can sometimes crash your application after a single use if used improperly. vbaObjSetAddref: This is the magic wand. It can be described as the most useful function I've ever found as you can pass a 32Bit long, and it will give you an object in return. This is amazing, because you can call a windows API, for example a timer function, and pass the ObjPtr of an object, and when the function returns, it should give you the pointer which can be used to reproduce the existing object. I've tried a similar approach using "CopyMemory" to write the object pointer into the object variable, which is resembled as a 32Bit long in memory or 4 Bytes, but I got stuck because this method does not increase the reference counter, thus crashing the application. This is the safest way to "copy" an object per say. I've included a simple VB example below, with the declarations.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: