Shoutbox

Function dll C# in scripts ( Msg+ ) - 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: Function dll C# in scripts ( Msg+ ) (/showthread.php?tid=82058)

Function dll C# in scripts ( Msg+ ) by melliott on 03-02-2008 at 01:40 PM

Hi,

I have problem. How can I use function dll written in C# to writting scripts ( to Msg+ ) in JS?

Namespace dll:
testdll
Class:
connect
Function:
polacz


RE: Function dll C# in scripts ( Msg+ ) by Spunky on 03-02-2008 at 05:43 PM

You want to take a look at Interop.Call:

quote:
The Interop::Call function allows scripts to call functions located in external libraries. For example, it can be used to call functions from the Windows API.



code:
[number] Interop.Call(
    [string] DllName,
    [string] FunctionName,
    [var, optional] Param1,
    [var, optional] Param2,
    [var, optional] Param3,
    [var, optional] Param4,
    [var, optional] Param5,
    [var, optional] Param6,
    [var, optional] Param7,
    [var, optional] Param8,
    [var, optional] Param9,
    [var, optional] Param10,
    [var, optional] Param11,
    [var, optional] Param12
);


The return value is whatever the function returns. Example:

code:
    var value = Interop.Call("User32","EnableWindow", hWnd, false);


RE: Function dll C# in scripts ( Msg+ ) by ShawnZ on 03-02-2008 at 07:43 PM

quote:
Originally posted by SpunkyLoveMuff
You want to take a look at Interop.Call:

no, he doesn't.
RE: Function dll C# in scripts ( Msg+ ) by roflmao456 on 03-02-2008 at 10:38 PM

isn't it Interop.Call2 ?

quote:
The Interop::Call2 function allows scripts to call functions located in custom made external libraries and return a string. It acts exactly like Call except that it expects a BSTR as return value.

RE: Function dll C# in scripts ( Msg+ ) by deAd on 03-02-2008 at 10:48 PM

Interop::Call can also call from custom libraries, the only difference is that Interop::Call2 returns a string.

Melliott, you will need to make sure the function you want to call is exported from the dll. Then just put the path of the library, name of the export, and the parameters you want into Interop::Call or Interop::Call2 (depending on if the function returns a string or not).

EDIT: From a quick google search, it looks like you cannot export with C# (I may be wrong, I do not use C#) but you can create a library which can be registered to use with COM.


RE: Function dll C# in scripts ( Msg+ ) by ShawnZ on 03-02-2008 at 10:53 PM

quote:
Originally posted by roflmao456
isn't it Interop.Call2 ?

no, because neither of them work on .NET libraries. besides, call and call2 do the same thing, except call2 is for functions that return a string.
RE: Function dll C# in scripts ( Msg+ ) by vikke on 03-02-2008 at 11:40 PM

C# is dotNet, which means that the executable-format is way different. It doesn't have anything such as exports, so you cannot use any Interop method to call it. DotNet is managed code, so you there's not a chance you can call it just like it would be native, but of course, there are workarounds. They're dirty, bad and they're called COM.
Oh, and they don't work well on Vista. :(