Connecting Tech Pros Worldwide Forums | Help | Site Map

Calling a local C# Dll from Javascript!

Adrian
Guest
 
Posts: n/a
#1: May 6 '06
Hi
I want to write a simple DLL in C# that I can call from a local html
page using JavaScript. I'm looking for a very simple example!

The sort of think I'm looking for is from JS to call the DLL and it return
the date for example, or even just a string "abc".

Ideally I would like to see both the C# code and JS code!

Anyone help me!



Adrian
Guest
 
Posts: n/a
#2: May 7 '06

re: Calling a local C# Dll from Javascript!


HI
I found this in another post!
http://www.codeguru.com/csharp/cshar...cle.php/c4263/

So how do I access it from JS?

Thanks


"Adrian" <Adrian@nospamhotmail.com.uk> wrote in message
news:pI2dnTt3zrohTMHZRVnyrw@bt.com...[color=blue]
> Hi
> I want to write a simple DLL in C# that I can call from a local html
> page using JavaScript. I'm looking for a very simple example!
>
> The sort of think I'm looking for is from JS to call the DLL and it return
> the date for example, or even just a string "abc".
>
> Ideally I would like to see both the C# code and JS code!
>
> Anyone help me!
>[/color]


Carl Daniel [VC++ MVP]
Guest
 
Posts: n/a
#3: May 7 '06

re: Calling a local C# Dll from Javascript!


Adrian wrote:[color=blue]
> HI
> I found this in another post!
> http://www.codeguru.com/csharp/cshar...cle.php/c4263/
>
> So how do I access it from JS?[/color]

First, try asking in a JScript newsgroup rather than a C++ newsgroup.

I'd suggest trying

microsoft.public.scripting.jscript

-cd


Adrian
Guest
 
Posts: n/a
#4: May 7 '06

re: Calling a local C# Dll from Javascript!


Isn't it funny how the JS groups say it a C# issue! and visa virsa, but
those with the comments know not the anwsers, or choose not to share!

Surly as there is detail of how to develop this in C# and referance is made
to using it from JS, its not unresonable to ask especialy as I don't know if
the C# DLL would or would not work from JS without a way of testing it and
point is to develop a C# DLL that can be called from a local HTML page in MS
IE6 running on XP...

"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam >
wrote in message news:uFPEkWWcGHA.3484@TK2MSFTNGP03.phx.gbl...[color=blue]
> Adrian wrote:[color=green]
>> HI
>> I found this in another post!
>> http://www.codeguru.com/csharp/cshar...cle.php/c4263/
>>
>> So how do I access it from JS?[/color]
>
> First, try asking in a JScript newsgroup rather than a C++ newsgroup.
>
> I'd suggest trying
>
> microsoft.public.scripting.jscript
>
> -cd
>[/color]


William DePalo [MVP VC++]
Guest
 
Posts: n/a
#5: May 7 '06

re: Calling a local C# Dll from Javascript!


"Adrian" <Adrian@nospamhotmail.com.uk> wrote in message
news:CPGdnbONBs3alcPZRVnyhw@bt.com...[color=blue]
> Isn't it funny how the JS groups say it a C# issue! and visa virsa, but
> those with the comments know not the anwsers, or choose not to share![/color]

:-)

This is not an issue of deliberately not sharing information. It is not in
the interest of anyone from MS or any of the news group volunteers to keep
anything from you.

Rather, the pointer to another newsgroup serves to do two things. First, it
increases the likelihood that you will be put in contact with someone who
can help you. And second, it keeps the group in which the post was made "on
topic".

The fact that it often takes a knowledge of two or three technolgies to
accomplish a given task while newsgroup regulars tend to be masters of one
only further complicates matters.

That said, I have to tell you that I am not a JScript expert. But, were I
you, I would look at the JScript function ActiveXObject used like so

newObj = new ActiveXObject(servername.typename[, location])

It is described here:

http://msdn2.microsoft.com/en-US/library/6958xykx.aspx

That function allows you to create a COM object in script code.

Then what you need to do is to figure out how to make your C# class appear
to clients as a COM object. One way to do that is to use the RegAsm
(register assembly) tool to register a .Net assembly as a COM object. It is
described here:

http://msdn.microsoft.com/library/de...lRegasmexe.asp

Now, I'm neither an expert at scripting or COM - you'll find one of those
characters in another group. There may be other hurdles involved (security?)
in the solution I sketched and in fact there may be a better method. Good
luck.

Regards,
Will


Carl Daniel [VC++ MVP]
Guest
 
Posts: n/a
#6: May 7 '06

re: Calling a local C# Dll from Javascript!


Adrian wrote:[color=blue]
> Isn't it funny how the JS groups say it a C# issue! and visa virsa,[/color]

No doubt, but this is a C++ newsgroup, not C# nor JScript.

You need to expose your C# class as a COM callable object. See the
COMVisibleAttribute in the .NET documentation.

You need to regisster your C# DLL as a COM server - see regasm.exe in the
..NET framework SDK (you should already have it if you have a C# compiler).

If you're going to access your C# COM DLL from a web page (i.e. ASP), you'll
need to strong-name your assembly (see sn.exe in the .NET framework) and put
it in the GAC (see gacutil.exe in the .NET framework).

This article

http://www.codeproject.com/dotnet/cominterop.asp

contains a lot of information on COM/.NET interop, which is what you need to
understand to mix JScript and C#.

-cd


Adrian
Guest
 
Posts: n/a
#7: May 7 '06

re: Calling a local C# Dll from Javascript!


Hi
Thanks you both for your reply Sorry I have on just started looking at C#
and only done vb and vb.net till now! VC was C# opps!!!

Lots of good info I will red through thangs Carl.

I have also just found this
http://www.devhood.com/tutorials/tut...utorial_id=187

It seems to be exactly what I'm looking for...

Thanks

"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam >
wrote in message news:eltfmOgcGHA.3484@TK2MSFTNGP03.phx.gbl...[color=blue]
> Adrian wrote:[color=green]
> > Isn't it funny how the JS groups say it a C# issue! and visa virsa,[/color]
>
> No doubt, but this is a C++ newsgroup, not C# nor JScript.
>
> You need to expose your C# class as a COM callable object. See the
> COMVisibleAttribute in the .NET documentation.
>
> You need to regisster your C# DLL as a COM server - see regasm.exe in the
> .NET framework SDK (you should already have it if you have a C# compiler).
>
> If you're going to access your C# COM DLL from a web page (i.e. ASP),[/color]
you'll[color=blue]
> need to strong-name your assembly (see sn.exe in the .NET framework) and[/color]
put[color=blue]
> it in the GAC (see gacutil.exe in the .NET framework).
>
> This article
>
> http://www.codeproject.com/dotnet/cominterop.asp
>
> contains a lot of information on COM/.NET interop, which is what you need[/color]
to[color=blue]
> understand to mix JScript and C#.
>
> -cd
>
>[/color]


Closed Thread