-
Mar 10th, 2025, 01:51 AM
#1
-
Mar 10th, 2025, 03:58 AM
#2
Re: VB6 project not working "quite" right in tB (can't find the root cause)
I've had a problem in one of my apps where TB, when reading an image from a RC collection, the image was inverted. I raised a github issue for it.
It may be entirely unrelated but the issue is here: https://github.com/twinbasic/twinbasic/issues/1939
Last edited by yereverluvinuncleber; Mar 10th, 2025 at 07:25 AM.
https://github.com/yereverluvinunclebert
Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.
By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.
-
Mar 11th, 2025, 02:45 PM
#3
Re: VB6 project not working "quite" right in tB (can't find the root cause)
The problem with the inverted image is probably related to the BITMAPINFOHEADER structure where the general consensus is the biHeight member should be negative so that the image is scanned top to bottom instead of bottom to top. So the solution is likely to be as simple as correcting the sign.
The other issue is a lot more complicated. Most WinRT methods are asynchronous in nature so they are running in their own thread and then they call back into the main thread to communicate their results. The order in which these async operations finish is non-deterministic. I am amazed how VB6 with its 30 years old COM technology is able to properly "serialize" or "queue" these callbacks so that they don't step on each other's toes. I think this has some merit to be looked into.
-
Mar 12th, 2025, 07:11 AM
#4
Junior Member
Re: VB6 project not working "quite" right in tB (can't find the root cause)
Problems like these are the reason I decided not to switch to tB. A complex and rare bug in the compiler can ruin your entire project. The main thing in a compiler is reliability and predictability, for this reason I stayed with VB6.
-
Mar 12th, 2025, 07:27 AM
#5
Re: VB6 project not working "quite" right in tB (can't find the root cause)
When nothing is more important, yeah it might make sense to avoid projects in Beta. Beta is prerelease testing; bugs are a way of life. But you should check it out again when it's released as stable; the bugs are rapidly disappearing.
With VBScript now on the way out and increasing hostility towards VBA making it more and more painful to use, it's a mistake to think that long term you won't need alternatives to VB6... and even if the compilers for other languages are more 'stable', you'd introduce far more bugs by human or AI error trying to port your project.
-
Mar 12th, 2025, 07:54 AM
#6
Re: VB6 project not working "quite" right in tB (can't find the root cause)
 Originally Posted by fafalone
*snip* you'd introduce far more bugs by human *snip* error trying to port your project.
Which boils down to insufficient knowledge in both languages: Your "source"-language and your "target"-language.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Mar 12th, 2025, 08:04 AM
#7
Re: VB6 project not working "quite" right in tB (can't find the root cause)
 Originally Posted by jangle
Problems like these are the reason I decided not to switch to tB. A complex and rare bug in the compiler can ruin your entire project. The main thing in a compiler is reliability and predictability, for this reason I stayed with VB6.
There are bugs in VB6 compiler we often hit. Just today had to deal with OOM during compilation of one of our projects. It's your codebase not big enough to feel the pain.
Btw, there are bugs in gcc and clang too. Every sufficiently large codebase has to deal with bugs in their compilers and/or 3-rd party deps -- it's inevitable.
cheers,
</wqw>
-
Mar 20th, 2025, 03:04 PM
#8
Re: VB6 project not working "quite" right in tB (can't find the root cause)
The latest tB version fixed the image orientation. Still no luck on the access violation when enumerating the metadata properties:

The VB6 version enumerates exactly 120 properties every time.
-
Mar 21st, 2025, 04:33 AM
#9
Re: VB6 project not working "quite" right in tB (can't find the root cause)
 Originally Posted by VanGoghGaming
The latest tB version fixed the image orientation. Still no luck on the access violation when enumerating the metadata properties:
The VB6 version enumerates exactly 120 properties every time.
The problem is due to this code:
Code:
Private Function GetString(This As tHSTRING, sString As String) As HRESULT
SysReAllocString VarPtr(sString), WindowsGetStringRawBuffer(This.hString, 0&)
End Function
`
This procedure is being vtable swapped for the IStringLightWeight::GetString member, defined as:
`HRESULT __stdcall GetString([out, retval] BSTR* out)`
The problem here is, that VB ByRef semantics are not a perfect match for OUT-only parameters. For an OUT parameter, the caller can legitimately give you any invalid value on input and you're not meant to use or interpret it, only overwrite it with a result. But in your implementation, by passing sString to SysReAllocString, the input value IS being used, (and freed). The thing to remember is: ByRef is equivalent to [in, out] semantics, not [out].
To correct the problem, do this:
Code:
Private Function GetString(This As tHSTRING, sString As String) As HRESULT
PutMemPtr VarPtr(sString), vbNullPtr
SysReAllocString VarPtr(sString), WindowsGetStringRawBuffer(This.hString, 0&)
End Function
`
BTW, we dealt with this exact issue a lot in the tB ActiveX implementations, as many AX controls are C++ based and will (legitimately) pass junk/uninitialized values on input to OUT-only params.
-
Mar 21st, 2025, 05:56 AM
#10
Re: VB6 project not working "quite" right in tB (can't find the root cause)
Why not just sString = vbNullString instead of calling PutMemPtr? I mean it looks like PutMemPtr leaks a BSTR or is it on purpose?
Edit: Oh, my bad. I thought it was a problem at callsite (not clearing out params before calling the method) but we are dealing with GetString *implementation* which does not clear its own [out] only parameter properly but insist on deallocating it as a BSTR whatever junk is passed in there.
Yes, this is not something any VBx implementation/devs deal with often (or at all).
cheers,
</wqw>
Last edited by wqweto; Mar 21st, 2025 at 06:00 AM.
-
Mar 21st, 2025, 12:29 PM
#11
Re: VB6 project not working "quite" right in tB (can't find the root cause)
Outstanding sleuthing, cheers Wayne, I wouldn't have figured this one out in a million years!
I'm still not clear why this works in VB6 without the additional call to "PutMemPtr" though. I was under the impression that all function parameters are initialized with zero by default so there shouldn't have been any "junk" pointer in "sString" to begin with... Maybe this is a key difference between VB6 and tB where VB6 does sanitize function parameters before using them?
In any case, I've rewritten the "GetString" function as follows in order to eliminate the overhead introduced by the additional call to "PutMemPtr":
Code:
Private Function GetString(This As tHSTRING, pStr As LongPtr) As HRESULT
pStr = SysAllocString(WindowsGetStringRawBuffer(This.hString, 0&))
End Function
It seems to work great so I'm a happy camper once again!
-
Mar 23rd, 2025, 11:26 AM
#12
-
Mar 23rd, 2025, 11:51 AM
#13
Re: [RESOLVED] VB6 project not working "quite" right in tB (can't find the root cause
It will depend on how the compiler temp variables get issued/reused as to whether the value will contain junk or not. AFAIK VB6 does not guarantee that the out-only param is zeroed at the callsite - though it may happen to do so in this particular case. Ultimately the COM contract denotes that we don't need to zero it, and so it is better not to do so, which allows for better optimization opportunities (for when we turn on LLVM optimizations fully).
FWIW, we could easily add an advanced compiler option to switch the behaviour ON/OFF for zeroing out params at the callsite.
-
Mar 23rd, 2025, 12:52 PM
#14
Re: [RESOLVED] VB6 project not working "quite" right in tB (can't find the root cause
> AFAIK VB6 does not guarantee that the out-only param is zeroed at the callsite
If it's a typelib declared interface with [out] only param AFAIR VB6 does make sure ref types (String, Variant, Object) are cleared at callsite as not to leak temp values lurking in there.
The problem is when a manually converted typelib erroneously marks these params as [in, out] in which case VB6 does not clear anything and leaks might occur.
cheers,
</wqw>
-
Mar 23rd, 2025, 01:41 PM
#15
Re: [RESOLVED] VB6 project not working "quite" right in tB (can't find the root cause
VB6 does not allow use of Implements with any interface containing an out-only parameter. That's why it's frequently changed, not by mistake. Issues from this change are rare and can be worked around, so it's not worth making a separate version for everywhere it's used.
Last edited by fafalone; Mar 23rd, 2025 at 01:55 PM.
-
Mar 23rd, 2025, 03:01 PM
#16
Re: [RESOLVED] VB6 project not working "quite" right in tB (can't find the root cause
I mean calling methods with [out] only params e.g. ID3D11Device::GetImmediateContext when it's declared to void GetImmediateContext([out] ID3D11DeviceContext **ppImmediateContext) in the typelib.
This code
Code:
Dim pDevice As ID3D11Device
Dim pContext As ID3D11DeviceContext
pDevice.GetImmediateContext pContext
. . . compiles to this
Code:
0040191E 8D 4D E4 lea ecx,[pContext]
00401921 E8 1A F8 FF FF call ___vbaFreeObj (401140h)
00401926 8D 45 E4 lea eax,[pContext]
00401929 50 push eax
0040192A 8B 45 E8 mov eax,dword ptr [pDevice]
0040192D 8B 00 mov eax,dword ptr [eax]
0040192F FF 75 E8 push dword ptr [pDevice]
00401932 FF 90 A0 00 00 00 call dword ptr [eax+0A0h]
. . . i.e. pContext receiving variable is explicitly cleared at callsite for the [out] only parameter.
cheers,
</wqw>
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
|