Shoutbox

Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects - 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: Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects (/showthread.php?tid=94513)

Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects by Mnjul on 05-03-2010 at 04:06 PM

Hello everyone!

I've just finished the tutorial on how to let a DLL, which is Interop.Call()ed by scripts, interface with Plus! scripting objects.

This tutorial guides script developers to have their native Win32 DLLs manipulate scripting objects (MsgPlus, Messenger, ChatWnd, Contact, PlusWnd, ...) as in JScript. We know that DLLs are crucial to implement asynchronous callbacks, which are in term crucial to subclassing non-Plus! windows (aside from machine-code-injection). However, before this tutorial, it was never (I think) disclosed how DLLs can interact with scripting objects in their native C++ codes. This is also the very technique that enables HopperLive to change Messenger's status and create a PlusWnd in its DLL.

If you're interested, please take a look! And tell me what you think about it, especially if you feel something is left unsaid, is not clear, or if you want more detail on specific topics. Requests for specific examples are welcome too!

Happy reading!


RE: Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects by Menthix on 05-04-2010 at 01:47 PM

Nice one! Thanks for sharing.


RE: Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects by Matti on 05-04-2010 at 04:01 PM

Bookmarked! I have yet to find a script project where I need to use an extra DLL to do what I need, but if I do I now have a place to start.

Thank you for this excellent write-up! :)


RE: Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects by CookieRevised on 05-04-2010 at 06:05 PM

Wow, excellent written tut (y)(y)(y).....


RE: Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects by SmokingCookie on 05-04-2010 at 07:11 PM

Nice one (Y)

Btw, shouldn't this one be sticky?


RE: Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects by matty on 05-04-2010 at 07:39 PM

It is half stickied: http://shoutbox.menthix.net/important.php


RE: Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects by Mnjul on 05-08-2010 at 04:22 PM

Hello folks,

I've updated the tutorial, briefing on how to let the DLL call back JScript function. It's in the tutorial's last section under the name of Advanced Topics. Special thanks to Eljay for shedding some light on the mechanism! ;)


I should be able to come up with a generic subclassing helper DLL sooner or later :chrongue:
RE: Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects by SmokingCookie on 05-09-2010 at 08:09 AM

Ref: C# DllExportAttribute.

Okay, I've got absolutely no idea how the above thingy supposed to work, but can this tutorial be applied to C# as well?


RE: Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects by Mnjul on 05-09-2010 at 08:30 AM

quote:
Originally posted by SmokingCookie
Ref: C# DllExportAttribute.

Okay, I've got absolutely no idea how the above thingy supposed to work, but can this tutorial be applied to C# as well?

Well, I just tried in Visual Studio to add MsgPlusLive.dll to the C# project Reference, and it refused to do so. As long as you can extract the Type Library (.tlb) from the DLL then things should be ok. You have to find a way though. Dunno if any Visual Studio-builtin command tools do this.
RE: Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects by SmokingCookie on 05-09-2010 at 08:34 AM

I remember that regasm has some command-line argument that exports a .tlb file; could that be what you're pointing at?

Doesn't Patchou have anything like a .tlb file? :P


RE: Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects by CookieRevised on 05-09-2010 at 02:34 PM

The TLB is already in MsgPlusLive.dll as a resource (resource type TYPELIB\1). You just need to extract it. You can extract type libraries resources (TLB files) in various ways.

You can use rundll32.exe for example to extract it (although it is not straitforward; also, instead of the keyword 'TypeLib' you could use 'GenerateTypeLib')

Or from Microsoft: The OLE/COM Object Viewer can extract the IDL (decompiled Type Library).
(File > View TypeLib > select MsgPlusLive.dll)

More tools from Microsoft:
http://msdn.microsoft.com/en-us/library/ms680581(VS.85).aspx

Or you can use tools like Resource Hacker or (even better, but not free) PE Explorer to extract the compiled type library.

Then there are Type Library viewers like TypeLib Viewer from iTripoli.

Note that RegAsm.exe  isn't going to work here.


-------------------------------------------------

I recommend using Resource Hacker (free) or PE Explorer (can be used for 30 days for free). Using PE explorer is the easiest way to extract a TLB imho.

In Resource Hacker:
- Open MsgPlusLive.dll
- Select the TYPELIB\1\0 resource
- From the Action menu, choose 'Save Resource as a binary file' or 'Save Resource as a *.res file'
- Rename the saved file to "MPLiveScriptingLib.tlb"

In PE Explorer:
- Open MsgPlusLive.dll
- Go to the resource viewer
- Right click on the TYPELIB\1 resource
- Choose 'Save Resource as...' (or click CTRL+SHIFT+S)
- Enter the filename "MPLiveScriptingLib.tlb"


RE: Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects by Menthix on 05-09-2010 at 04:51 PM

The super easy way to extract resources, if you have 7-Zip installed, just right-click the .dll and extract with 7-Zip.


RE: Tutorial on How to Let a Script-Callable DLL Handle Scripting Objects by SmokingCookie on 05-09-2010 at 05:10 PM

Okay, I've got the .tlb file; now what? :P
Visual Studio won't add a reference to it.

EDIT: I've got it in VS's object browser atm, and it does indeed show the members described by Mnjul.