VbAsyncSocket
VbAsyncSocket copied to clipboard
Crashes in VB5 IDE
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?
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
.)
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 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.
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.
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.
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
.
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.
Btw, in commit aa8b241c037681891e6588912292a3ab40be14a4 I just completely removed new-lines replacement as it turned out to be unnecessary in cAsyncSocket class.