Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1529

Typelib to add LongPtr type to VB6 for universal codebases

$
0
0
VB6LongPtr.tlb - Add LongPtr to VB6


This is just a dead simple typedef but I didn't see anything like it readily available, so thought I'd post the one I made.

While you can (and must) use compiler constants to declare APIs differently, it gets to be unwieldy fast when you want to have the rest of your code be compatible when you have variables and Type members that also must be LongPtr. So to create universal codebases, I made a simple typelib that adds a LongPtr alias for Long in VB6. You can declare variables, Type members, arguments, etc, as LongPtr, and VB6 will treat them identically to a Long, with which they're also interchangeable- you can pass a LongPtr variable to a function expecting a Long, and a Long to a function expecting a LongPtr.

Add this only to your VB6 projects, not to VBA or twinBASIC projects.


Code:

//VB6LongPtr by fafalone
//Simply uses an alias to make LongPtr a usable type in VB6 in order
//to create universal codebases for VB6/VBA/twinBASIC. Include this
//typelib **only** with VB6 projects, as VBA/tB have a native LongPtr.
//(Since VB6 is 32bit only, LongPtr *always* would resolve to Long)
[
    uuid(D8EE61B0-8778-4A43-8F98-E7E1C2C08AD4),
    version(1.00),
    helpstring("VB6 LongPtr Support"),
    lcid(0x0)
]
library VB6LongPtr {

importlib("stdole2.tlb");

typedef [public] long LongPtr;
};

Attached Files

Viewing all articles
Browse latest Browse all 1529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>