VbAsyncSocket icon indicating copy to clipboard operation
VbAsyncSocket copied to clipboard

Crashes in VB5 IDE

Open h3rmit-git opened this issue 4 years ago • 8 comments

I've tried out your VbAsyncSocket class in a VB5 project and the IDE crashes whenever trying to listen, connect, send or receive data. I tried the same project under the VB6 IDE and they seem to work fine. I suspect your thunks are not compatible with the VB5 IDE.

Could you please add support for VB5?

h3rmit-git avatar Jun 26 '20 23:06 h3rmit-git

Does it work when compiled? If it does try setting MST_NO_IDE_PROTECTION = 1 in conditional compilation options in the IDE.

Did you change these lines

        aParams(9) = GetProcAddress(GetModuleHandle("vba6"), "EbMode")
        aParams(10) = GetProcAddress(GetModuleHandle("vba6"), "EbIsResetting")

. . . to vba5? Don't. . . as there is no EbIsResetting in vba5.dll so the notify thunk calls on a NULL pointer and obviously crashes. EbMode function pointer is explicitly checked for NULL but EbIsResetting pointer is not checked.

Will fix it soon so you can get IDE protection in VB5 too.

Other than this on first glance it seems to work (without IDE protection) in VB5 just fine, even the TLS implementation is working ok.

(Had to replace all As Byte() functions to As Variant.)

wqweto avatar Jun 27 '20 15:06 wqweto

Oh, so that's why EbIsResetting felt unfamiliar.

I actually changed these two lines to try both vba5 and vba6, and use whatever is already loaded.

	Dim vbModuleHandle  As Long

	vbModuleHandle = GetModuleHandle("vba5")
	If vbModuleHandle = 0 Then
		vbModuleHandle = GetModuleHandle("vba6")
	End If
	
	aParams(9) = GetProcAddress(vbModuleHandle, "EbMode")
	aParams(10) = GetProcAddress(vbModuleHandle, "EbIsResetting")

I also replaced all As Byte() to As Variant, and the declarations of ArrPtr and vbaObjSetAddref to point to msvbvm50.dll.

Yes, the program works fine after being compiled.

Thanks in advance, I'll be waiting for updates!

h3rmit-git avatar Jul 01 '20 21:07 h3rmit-git

@h3rmit-git Just pushed all VB5 fixes to a new vb5 branch in the repo with most of the samples working now.

You can check it out and report any problems here.

wqweto avatar Jul 03 '20 09:07 wqweto

Thank you! The vb5 branch seems to work fine in VB5 now.

The cAsyncSocket.cls class can no longer be compiled by itself, as it now requires mdVb5Comp.bas to be included in the project. Instead, I added a private function Replace in it, since that's the only thing it needs.

h3rmit-git avatar Jul 03 '20 18:07 h3rmit-git

I added a private function Replace in it, since that's the only thing it needs.

In commit 49b569e817e3998191da87a9e864e86f2b644172 I pushed a regex based find&replace in cAsyncSocket to get rid of the two Replace calls and then inlined Replace, Split and Join implementations as private functions for each module that used these to get rid of mdVb5Comp.bas module dependency at all.

wqweto avatar Jul 04 '20 11:07 wqweto

I'm quite reluctant to use the CreateObject("VBScript.RegExp") part. It relies on an extra external dependency, and it is late bound, so it could be an potential factor of instability, depending on the system of the end user.

Instead, I'm quite comfortable with just adding you previous implementation of Replace as a private function in cAsyncSocket.cls.

h3rmit-git avatar Jul 05 '20 19:07 h3rmit-git

VBScript.RegExp object is present since IE4 so it's very compatible. If it gets broken then IE will start malfunctioning. I've been using it in similar helper functions since NT4 and in a fairly popular VB6 application not a single report of it misbehaving has been submitted.

Previous Replace implementation was completely inefficient using Split and Join and I'm sure the RegExp based one will be orders of magnitude faster on moderately sized input.

Here is a somewhat better Replace implementation by Francesco Balena that will also be dog-slow on anything but tiny inputs.

Writing and debugging a decent pure VB5 implementation will be time-consuming and the risk of not achieving anything compared to the RegExp one is very high, so I'll pass on this one.

wqweto avatar Jul 06 '20 08:07 wqweto

Btw, in commit aa8b241c037681891e6588912292a3ab40be14a4 I just completely removed new-lines replacement as it turned out to be unnecessary in cAsyncSocket class.

wqweto avatar Jul 06 '20 08:07 wqweto