Shoutbox

multithreaded dll - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: multithreaded dll (/showthread.php?tid=75142)

multithreaded dll by cooldude_i06 on 06-07-2007 at 03:04 PM

I need to use a C++ Dll in my script using Interop.Call, however the function this Dll contains runs an infinite loop in the background, which ofcourse freezes WLM because the function does not return anything. I know that VB6 does not support multithreading so calling it through an ActiveX dll won't help. So I'm looking for suggestions.

If I wanted to run this dll in a new thread how would I do that? Can I run a specific function inside the C++ Dll in a new thread? If so how?

Thanks
CD


RE: multithreaded dll by Volv on 06-07-2007 at 03:26 PM

You could create a timer in MsgPlus to call the function every X milliseconds instead of using an infinite loop.


RE: multithreaded dll by cooldude_i06 on 06-07-2007 at 03:29 PM

No the infinite loop is part of the C++ dll and that cannot be changed due to functionality reasons. The only thing I can do is run it in a separate thread so the main function does not wait for it to end and returns a value so that Plus can get going with the script.


RE: multithreaded dll by Mnjul on 06-07-2007 at 04:19 PM

You can call CreateThread, or alternatively, _bginthread if you're using Visual C++, in your C++ DLL.

But note: any cross-thread reference to the scripting objects will become invalid.


RE: multithreaded dll by CookieRevised on 06-07-2007 at 09:51 PM

Multithreading is somewhat possible in VB though (for example with ActiveX, but it depends on what you exactly want to do... (Though doing it in C++ would be easier)

Anyways, out of curiosity, can I ask why the DLL needs an infinite loop? Because in most cases you could always develop a method without inifinate loops (infinite loops are to be avoided as much as possible). So the solution might not be to find a way to make your DLL multithreaded to run an infinite loop, but to improve the code so it doesn't need an infinite loop to start with.

;)


RE: multithreaded dll by cooldude_i06 on 06-08-2007 at 01:42 AM

Well I'm trying to use the Winpcap library, and as far as I have seen the only way to retrieve packetcapture events is using a loop.

The multithreaded problem has been fixed by the use of CreateThread api, thanks.