Blog
Calling External DLL's From Script
Date: 2/9/2006
Today I got the Scripting Language in i.Mage to call into an external DLL. The test script was simple:
extern int MessageBoxA(HWND, LPCTSTR, LPCTSTR, UINT) in "User32.dll";

MessageBoxA(Parent, "Title", "Message", 0);
Which now runs as you'd expect. The "parent" variable is a predefined uint32 containing the handle of the script window. The other predefined variable at this point is a DOM pointer to the i.Mage application itself.

This will most likely appear in the next Scribe release in the filters, so that you can create very custom filters. By being able to define calls into external DLL's you could write some code in any language you want and call it from Scribe. Some of the tools hanging onto various menus in Scribe will most likely be rewritten in Script instead of C++ and thus Scribe will become extensible. e.g. the little utils hanging off the bottom of the Tools menu are begging to be re-written in Script.
If you liked that first snippit, then you'll love this. Check out this new working script:
extern int MessageBoxA(HWND, LPCTSTR, LPCTSTR, UINT) in "User32.dll";
extern DWORD GetTempPathA(DWORD, LPTSTR) in "Kernel32.dll";

s.length = 256;
GetTempPathA(s.length, s);
MessageBoxA(Parent, s, "Title", 0);
Variables can now have members, i.e. DOM style addressing. Assigning a value to the .length member of a variable turns it into a string of spaces of the requested length. This is useful for preallocating string buffer memory for calling C functions that expect that. Conversely getting the .length member of a string returns "strlen(c_str)".

I've kinda left room for expanding this out to use non-atomic types like structures and so on, but that isn't implemented yet. I have to implement code to parse the type definition first and then code to use allow the script to declare a variable of that type and use it. Which is a substantial feature to add.
Comments:
Ben
03/09/2006 9:00am
Very intresting, but I have a question, didn't you think about using an already existing scripting language to do the job?

I admire your work, but it will be 'another' scripting language one will have to 'learn' to write image or scribe addon.

If you would use lua for example, already know by a large number, you would have a branding to encourage people to write plugin, addon, etc.

fret
03/09/2006 10:47am
Yeah I know I thought about that and well. Instead of making it "another" scriping language I thought I'd just use the javascript syntax where ever possible. So for the most part, it's javascript "lite".

I really didn't plan this at all, it just came about from the simplest of languages for calling i.mage functions. And I kinda got carried away.

In any case it will intergrate better than a "add-on" language. I already tried intergrating a scripting language ICI but it's internal structure has some issues with how I wanted to make it work with Scribe objects.

With my own language I can fix it to work exactly the way I want. No compromises. And I get small code size to boot. All external libraries carry dupelication of function which bloats out the codebase. And they aren't necessarily as portable as code I write.

Hope that makes things a little clearer ;)
Ben
03/09/2006 4:03pm
Yep fair enough, and thanks for the explanation.

 
Reply
From:
Email (optional): (Will be HTML encoded to evade harvesting)
Message:
 
Remember username and/or email in a cookie.
Notify me of new posts in this thread via email.
BBcode:
[q]text[/q]
[url=link]description[/url]
[img]url_to_image[/img]
[pre]some_code[/pre]
[b]bold_text[/b]