Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes in VB5 IDE #4

Open
h3rmit-git opened this issue Jun 26, 2020 · 8 comments
Open

Crashes in VB5 IDE #4

h3rmit-git opened this issue Jun 26, 2020 · 8 comments

Comments

@h3rmit-git
Copy link

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?

@wqweto
Copy link
Owner

wqweto commented Jun 27, 2020

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.)

@h3rmit-git
Copy link
Author

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!

@wqweto
Copy link
Owner

wqweto commented Jul 3, 2020

@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.

@h3rmit-git
Copy link
Author

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.

@wqweto
Copy link
Owner

wqweto commented Jul 4, 2020

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

In commit 49b569e 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.

@h3rmit-git
Copy link
Author

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.

@wqweto
Copy link
Owner

wqweto commented Jul 6, 2020

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
Copy link
Owner

wqweto commented Jul 6, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants