473,524 Members | 2,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do I write code in javascript to use a function in C

14 New Member
Suppose that I have some simple function in C like the following when I want to use it in javascript code

Expand|Select|Wrap|Line Numbers
  1. int plus1(int a)
  2. {
  3.     return a+1;
  4. }
I am using visual C++2008 for my C code.

I guess that I need to start by
file->new project->class library and call it with some name
let call it classtest

Now the visual C++ give me some files

I guess that I need to add some code to the file classtest.h and to file
classtest.cpp but I am not 100% sure what I need to add and I am not 100% sure what I need to add in javascript to use the function.

If you tell me what to do in this specific case then hopefully it is going to help me to use more complex functions that I have in C in javascript.

Note that I know how to do it only with javascript
and I simply do the following steps:

1)type the following code in a new asp file

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript" RUNAT=SERVER>
  2. function plus1(a)
  3. {
  4.   return a+1;
  5. }
  6. Response.Write(plus1(5));
  7. </SCRIPT>
2)save it in as javaexample.asp

3)goto
http://****/***/javaexample.asp

4)see 6 in the screen

I replaced some letters by **** but
**** is specific to the server that I am using that is only connected to the computer that I use even when I am not connected to the interenet so it is not important.
Nov 5 '09 #1
10 3124
Dormilich
8,658 Recognized Expert Moderator Expert
you can’t* use C/C++ functions in JavaScript.

main reason: C++ => compiled in an application, JavaScript => parsed in the browser’s sandbox.

to create JavaScript you only need a text editor (although tag highlighting and all the bells and whistles make it more comfortable) to write and a simple (X)HTML page to host/execute.

btw. what makes you think JavaScript is unable to do complex tasks, or is it just the urge to re-use already written code?

* - if you want to run the JS in the browser, other host applications may provide an API you can use.

PS.
Expand|Select|Wrap|Line Numbers
  1. a++;
Nov 5 '09 #2
urib
14 New Member
one of the reasons is that I want to re-use already written code but it is not the only reason.

C is also faster and people told me that I can use something like
server.createobject and dll but I am not sure exactly what I need to do for it.

Some step by step instructions can clearly help me.

If I can see step by step instructions for a simple example it can help me to use other functions that I already have code for them.

Uri
Nov 5 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
@urib
of course it’s faster, compiled code always is (compared to parsed code).
… unless you have system interactions

@urib
never heard of that before. anyway, JavaScript does not have access to local files.

@urib
did I already mention that it’s not possible?
Nov 5 '09 #4
urib
14 New Member
There is a difference between javascript in server and java script in client side.
I write javascript in runat server(see RUNAT=SERVER in my code).
Nov 5 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
I don’t know ASP. and if you want to use the code on the server only, I don’t see the need of using JavaScript at all, which is used (in almost every case) on the client side.

maybe you’re mistaking C# for JavaScript, they have a very similar syntax.
Nov 5 '09 #6
urib
14 New Member
Thanks for your replies.
Maybe I should go to asp.net forum.

The programmer that I talked with him agree that today javascript is not the best way to code on the server(I understood that he used javescript in the past but today he is using visual studio.net).

Uri
Nov 5 '09 #7
Dormilich
8,658 Recognized Expert Moderator Expert
@urib
they should definitely know more about MS server scripting

@urib
Javascript has its strength in handling document content.

@urib
does that mean he uses JavaScript with that IDE?
Nov 5 '09 #8
Plater
7,872 Recognized Expert Expert
I believe you can use managed c++ as the backend for asP.NET pages in the same way you can use C# and VBNET. Not positive as I've never bothered with managed c++
Nov 5 '09 #9
urib
14 New Member
I asked the programmer that I talked with him again and he told me that
Today he is using vb.net that is only for server code when he use javascript for client code so I guess the right forum to ask about server coding is vb.net(I still did not decide where to ask my question)

Uri
Nov 5 '09 #10
Dormilich
8,658 Recognized Expert Moderator Expert
I could help out with PHP…
Nov 5 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1972
by: Bob Murdoch | last post by:
I have a situation where I call a COM object from ASP that is supposed to create a file. On occasion, especially during development, the output of the COM function is an error string rather than the file name. I'd like to display this error string, regardless of it's contents. Right now, depending on the error string, I get an error message...
4
2755
by: Yvan J. Gagnon | last post by:
I am encountering a strange problem in Netscape 7 with a CFM file I am trying to troubleshoot (the page is working fine in NS Communicator and IE). Below is a sample of the problematic line of javascript code. Note that in the actual file, I've surrounded the variable '#cookie.cookiename#' with CFOUTPUT tags: document.write('<input...
2
2369
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of copying/pasting everytime I change it, I figure this will be better, as I only change it once. The problem is, document.write doesn't handle multiple...
13
9590
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be assigned to a variable and output using document.write. (Note, there is no submit button or other form elements. Basically
2
2913
by: Eric Mitchell | last post by:
Hello all, I am using the document.write() method to create new content on the same page, however... I need to create a new button using this method (button in HTML). Complicating the matter worse, I have a javascript function that needs to be called in the onClick event of the button. Is there any way of doing this? Here is my code, which...
2
5751
by: bissatch | last post by:
Hi, I am trying to use JavaScript to write a table column on a web page. The code is as follows: <html> <head> <script> function displaycount() {
4
4143
by: Filip De Backer | last post by:
Hi everyone, string script = ""; script += "<script language='javascript'>"; script += "window.open('showdoc.aspx');"; script += "</script>"; Response.Write(script); After the execution of this code, the layout of my aspx page changes: the font gets bigger, the datagrid (font, grid) gets bigger, ...
2
1886
by: jonniethecodeprince | last post by:
Hi all, I was wondering if anyone could help me display the HTML in a javascript that displays a table of data of prototype cinema listings. This code brings up a Syntax error: Object doesn't support this property or method on line 99 Any ideas, folks? Jonnie
6
20497
by: Bassem | last post by:
Hello everybody, I know it is an ordinary question, I tried a lot and searched but got nothing. I request another page (Default2.aspx) using JavaScript from (Default.aspx), get a response Response.Write() as a JavaScript then using document.write() to update the page. <script language="javascript" type="text/javascript"> var...
0
7327
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7223
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7599
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5168
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4810
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3308
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
873
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
537
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.