Shoutbox

C# Dlls in scripts - 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: C# Dlls in scripts (/showthread.php?tid=64267)

C# Dlls in scripts by Hilikus on 07-31-2006 at 04:21 AM

How do i call a function from a dll that was written in C#? interop.Call requires the name of the function, but in C# you have namespaces and everything is object oriented. Functions are not in a global or standard namespace as you could have in c++ so the second parameter of Call() should be what??
any help would be appreciated

I saw another C# program using the dll i want to use but of course, what they did was a "using" directive and then created an instance of the class that's in the dll

i would like to do that, create an object of the class OR (since i have the source code of the dll) i can add a function that creates a local instance and gives me all i need, but again, with interop.Call i cant do that because the function is not in a global namespace so i cant call it directly

Thanks a lot


RE: C# Dlls in scripts by Mnjul on 07-31-2006 at 10:55 AM

You need to use regasm, which allows .net classes to be used like COM classes, to register your dll, and in your Javascript, just do this:

var classInstanceVar=new ActiveXObject("NamespaceName.ClassName");

to instantitate your class. Then you can manipulate the instance, object-orientedly :)


RE: C# Dlls in scripts by Hilikus on 08-01-2006 at 02:00 AM

oh ok, that worked out well after some research and testing but there is still one thing. activexObject calls the default constructor, what if i want to call a constructor with parameters?? any help would be appreciated since i havent been able to find anything


RE: C# Dlls in scripts by Adeptus on 08-01-2006 at 02:58 AM

quote:
Originally posted by Hilikus
activexObject calls the default constructor, what if i want to call a constructor with parameters??
Sorry, you can't.  Classes instantiated through COM interop must have a default (public, parameterless) constructor.

You should be able to easily work around this in most cases, by providing properties to set whatever you would have set through constructor's parameters. 

Where that isn't possible (you are using somebody else's class or it is essential to your logic to have the parameter passed at creation time), use a helper class with a public method which takes the parameters, creates the class instance passing parameters to the constructor, and returns the created object.