473,499 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a local C# Dll from Javascript!

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!
May 6 '06 #1
6 11994
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" <Ad****@nospamhotmail.com.uk> wrote in message
news:pI********************@bt.com...
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!

May 6 '06 #2
Adrian wrote:
HI
I found this in another post!
http://www.codeguru.com/csharp/cshar...cle.php/c4263/

So how do I access it from JS?


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

I'd suggest trying

microsoft.public.scripting.jscript

-cd
May 6 '06 #3
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]" <cp*****************************@mvps.org.nospam >
wrote in message news:uF**************@TK2MSFTNGP03.phx.gbl...
Adrian wrote:
HI
I found this in another post!
http://www.codeguru.com/csharp/cshar...cle.php/c4263/

So how do I access it from JS?


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

I'd suggest trying

microsoft.public.scripting.jscript

-cd

May 7 '06 #4
"Adrian" <Ad****@nospamhotmail.com.uk> wrote in message
news:CP********************@bt.com...
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!


:-)

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
May 7 '06 #5
Adrian wrote:
Isn't it funny how the JS groups say it a C# issue! and visa virsa,


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
May 7 '06 #6
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]" <cp*****************************@mvps.org.nospam >
wrote in message news:el**************@TK2MSFTNGP03.phx.gbl...
Adrian wrote:
Isn't it funny how the JS groups say it a C# issue! and visa virsa,
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

May 7 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
25833
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the...
3
3095
by: MicroMoth | last post by:
Hi, I'm trying to call a Javascript function within a foreach loop. I am loop over a series of users and I want to call the JS function which opens a new window, passing in the user id to each...
13
18655
by: monomaniac21 | last post by:
hi i want to be able to trigger a javascript style popup alert in php (i want a message displayed on the actual page) is this possible?
3
1483
by: fluxent | last post by:
(Environment: RedHat Linux recent, Python 2.3.5) We have a batch processing script that on occasion needs to send out an email. We have a sendmail running locally. Sometimes we get a socket...
5
3233
by: Newbie Coder | last post by:
Hello all I have 3 functions in a javacrip file (MyScript.js), which is added to an ASP.NET 2.0 project 1) no right-click 2) no select text (copy...) 3) History.Back()' How do I call...
6
10614
by: Ajit Goel | last post by:
Hi; We have a Javascript function which I have been tasked to move to a CSharp class. This javascript function uses Regular expression extensively. This function has a string input parameter and...
1
1661
by: susmitha | last post by:
hai iam a fresher in .net.My problem is I have one javascript sourcefile and some javascript functions in my aspx page like shown below. <script language=javascript...
2
7650
by: moni | last post by:
Hi, I wanted to call a javascript function function showAddress(address) { ..... } from the aspx.cs file from the Gridview_RowCommand function
15
4248
by: Sampat | last post by:
Hi, I wanted to know the performance of calling a function pointer v/s a normal function call in javascript in a scenario where there are multiple calls in the js to the same function. Please...
2
2206
Frinavale
by: Frinavale | last post by:
Hi! I am dynamically generating external .js JavaScript resources to be used with a Tab control I created (using VB.NET). Originally, the JavaScript was written directly into the <head> of the...
0
7130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.