473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

14
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 3115
Dormilich
8,658 Expert Mod 8TB
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
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 Expert Mod 8TB
@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
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 Expert Mod 8TB
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
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 Expert Mod 8TB
@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 Expert 4TB
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
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 Expert Mod 8TB
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
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...
4
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...
2
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...
13
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...
2
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...
2
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
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...
2
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...

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.