I've agreed to help out a friend with getting their website off the ground. Previously, someone else helped out by writing a data access layer dll in C#, which I luckily have access to the code. Not any means to change and recompile though, as C# has never been one of my primary languages.
Problem is, I have no idea how I'm supposed to call it. In HTML, I tried out
<form action='dll/MyLib.dll' method='GET'>'
But I've no understanding how to call a specific function out of the DLL nor how to pass parameters. I'm not even sure if I managed to load it. For example, if I have an HTML form to add a new user to a MySQL database, I want to call the DLL's connection and addUser functions.
I found a 2005 article on DLLs and HTML, but trying out their code doesn't seem to work in actual practice:
http://msdn.microsoft.com/en-us/library/3s0d4hwc%28v=vs.80%29.aspx
Anyone with any experience in this? I'm tempted to rewrite the DLL in a PHP script...
I think you're doing it wrong. While there "may" be a way to do what you're saying, there are much MUCH better/easier ways to go about this, one of which is using an IDE that understands .NET and can work with your C# code. I would recommend getting Visual Studio 2010 or WebMatrix if you can't afford VS2010 and learning how ASP.NET works.
It may take longer in the short run than whatever hacks people may or may not suggest here, but it will be a huge payoff in the long run, and who knows, maybe you'll really like programming in it :)
Do not call dll from html, please.
If you already have C#-related project, try ASP .NET.
Related
I have a web application that requires scripting capabilities to be able to run business logic without need to recompile the application.
So my idea is to use a Javascript engine and load the script from files or database and run an entity by the BL in order to validate things, do logic, etc.
Ive been searching for many questions here and I couldnt find one that works for NET1.1.
Anyone knows one that I can use?
I found JINT which seems great but is NET2.0+.
Another option I had was using Boo (I added a question here to know its speed as an interpreter only), but the developers already know JS so it will be more familiar and faster for them.
Thanks
I just found LuaInterface 1.3.0 which is the last version that supports NET1.1 (LuaInterface is already in 2.x) that runs on Lua5.0.
So I'm going with it.
I would've loved to do Javascript, but is not possible to make it run in NET1.1 and my app just will not be upgraded in the near future to NET2.0.
Does any one know of a Delphi to .NET converter (either C# or VB.NET)? I've inherited a bunch of Delphi code, never seen Pascal before and rather than learn it, I'd rather just try to use an automated converter, if available, and clean up the code after that. Can't seem to find this kind of tool anyway I search - maybe that's because one doesn't exist - so I thought someone here may know.
Spare your time.. If you want to convert code because you don't understand or like the original language, my advice is: "Don't bother" (believe me, I've made numerous attempts to convert code). Especially if you're planning to just make a couple of small changes to the existing code.
You won't be able to convert the code and have it compile, let alone run flawlessly.
You might be able to translate portions into something that is syntactically correct, but you won't have the libraries or frameworks (RTL/VCL) that the software relies on.
You're going to have to go back to the Delphi code and be able to understand what's happening to fix parts that are not working. It's going to take more time to fix bugs in the generated code than it would take to study the existing code and rewrite it entirely.
And if you have the time to rewrite software in another language, you might as well just roll up your sleeves, learn the original language, and change what you need to change in the existing code.
I have no experience using these tools, but here are a couple:
Delphi2CS
TurnSharp
A similar question was asked:
What tools exist to convert a Delphi 7 application to C# and the .Net framework?
Our internal HR application is developed by the vendor, but I've been given a requirement to change the behaviour of a certain piece of functionality without their assistance (which I don't want to do, but am investigating...). The functionality in question is an .ashx page which does a number of database lookups, and is called via javascript functions on a web page. We want to add one further database lookup.
We have control over the javascript code, so that's not a problem, but the code for the .ashx page is held in a compiled assembly. I've found where it is, and looked into it using .Net Reflector. Reimplementing the methods involved wouldn't be difficult, if it were technically feasible.
Can I create a new assembly, paste the source taken using Reflector into it, make my modifications, add the DLL to the application, and then set up a new .ashx to refer to it?
The bits I'm worried about not being possible are:
The code refers to some vendor classes held in other assemblies; can I just add references to those assemblies in Visual Studio to allow it to compile, and then when it's compiled and put on the server it'll all work?
Will I have trouble getting the web application to accept the new DLL, given that generally this application is not something we make changes to ourselves?
EDIT:
Some clarification: I'm not actually planning to replace the vendor's DLL with one of my own, that does sound like going a bit too far. Instead, I would make a new DLL with just the one function in it I need (based on stuff taken from the existing DLL using Reflector). I'd need that code to reference other utility vendor code so that it can get at classes needed to access the framework. I'd make a brand new .ashx page to serve up the code in the new DLL.
Luckily after all this I'm off the hook, because my customer agrees that things aren't desperate enough for us to attempt all this! But thanks for the assistance, which is definitely useful.
See my comment about the risk of the approach you're considering.
I really don't recommend the overall approach, but yes, it is possible to reference assemblies you don't have the source for; just add references to the project which will use them.
Replacing the code-behind for the .ashx may be possible depending on whether it's precompiled. If it's not, then I believe replacing the DLL in the BIN folder should do the trick. (Assuming no other assemblies are referencing it.) (DISCLAIMER: I've never tried this, and I don't recommend it.)
If you are just looking to get some additional data, I'd just implement my own lookup and call it from Javascript, rather than messing with reflector. Is there any reason that you can't do that?
Currently I'm involved in a project using c# . I know some of the features of this project can be easily implemented using Javascript (I have been a js developer for some time, but totally new to c#). so I'm very eager to know if it is possible to reuse the available js code in the project, or put it another way, embeded js into c# .
thanks in advance.
I think you're asking if it is possible to run JavaScript on the CLR. Similar to Java 6's JVM script engine.
EcmaScript.net could be your best bet - http://code.google.com/p/ecmascript-net/ - see also this question - Are there any .NET CLR/DLR implementations of ECMAScript?
There is an extensive article written on how to embed Javascript within C# here. Is that what you are looking for?
Are you referring to ClientScriptManager RegisterClientScriptBlock Method
There is no reason you cant continue to use existing client side javascript code.
There is a still a clear distinction to whats required on the client and what can be called by the client.
Various possibilities include: calling web services, making ajax calls to WebMethods and injecting javascript code into pages.
The way you write it it sounds like a giant cop-out of learning C# properly. Unless you actually mean that you want to use JavaScript for client-side control of your project, this is a no-go (and it doesn’t sounds like you meant client-side scripting).
That said, .NET actually allows you to mix assemblies from different languages effortlessly, but this only applies to .NET languages which can be compiled to .NET IL (bytecode) and I’m not aware of a JS-to-IL-compiler.
Javascript runs in the browser, as long as it is a web project there is no problblem combining. C# code will run on the server, javascript code in the browser.
http://msdn.microsoft.com/en-us/library/aa479011.aspx
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have the task of developing an application to pull data from remote REST services and generating Excel reports. This application will be used by a handful of users at the company (10-15). The data load can reach 10,000-200,000 records. I have been debating whether to use Python or C#...
The only reason I am considering Python is because I am familiar with it and it would be less of a risk.
Personally I want to try use C# since this would be a good opportunity to learn it. The application is not too complicated so the overhead of learning it won't be too much... I think.
Are there any issues with C# that I should be concerned about for this type of program? The users run Windows XP... would users not having .NET installed be a major concern?
Thanks in advance.
EDIT:
I guess I need to stress the fact that the end users should be able to run the application without installing additional libraries/frameworks.
Why not IronPython which merges the two worlds together?
If you want to learn C# and you don't have such a limited time constraint, now might be a good time to try it. Also, though I haven't done Excel work with either Python or C#, I would expect it to be easier to work with Excel files with a Microsoft product rather than Python. If you're just dumping data in CSV format to a file, though, either Python or C# will work fine.
If you want to try something even crazier, you can use IronPython such that you'll have .NET resources available but you can still write in Python.
I would normally say, use what you know.
However, here you may have some performance issues using an interpreted language. I, myself, would use C#. If you want to learn it, now is as good of a time as any.
However, if your own cost/benefit analysis reveals that you would be better off in python, use that.
.NET will be required for C# on windows, but you can use the .NET Client Profile to make the install pretty painless.
I realize this is an old post but I guess I have some pertinent information for anyone coming across this in more recent times, as I have.
The Python library, Openpyxl has worked well for me for manipulating and creating excel files in my desktop based automation scripts.
http://openpyxl.readthedocs.io/en/default/usage.html
It is accessing the file directly from my understanding, unlike the Interop technique in c#. So wherever it runs, you wouldn't need Excel installed. If you're trying to get something on a server it might be an issue getting a licensed copy of Excel or ensuring it exists if your user is running this locally.
Using C# you have the full features of visual studio to help code, such as the code completion, debugging tools and error highlighting. However you can get most of that with Python in Visual Studio, though I've found it more complicated trying to get the right version of python tied to the project and whatnot.
In C# you can easily compile an executable whereas I believe you'll need to mess with loading some Python libraries to get close to a similar local executable with dependencies comparable to the C# output.
If the users have to install a C# client then not having .NET installed would be an issue. You can package the installer so it downloads the .NET runtime, but depending on what features you use it could be quite a big download.
If your application is web based then all the C# code runs on the server and just delivers HTML to the browser so whether .NET is installed or not shouldn't matter.
Integration with Excel will almost certainly be simpler from C#. Given the requirements "Windows only" and "Integrates with Excel", it would seem a simple choice that C# is better suited to this individual problem.
And, no, users' not having .NET is not a concern compared with Python as the alternative. The Dot Net framework is a standard part of Microsoft Update. In contrast, Python will almost certainly not be there on the average end users' machine. In your case, with an internal app, that last point might not matter of course.
If you are doing any kind of HTTP work with C# make sure you take a look at the new HttpClient library that is in WCF REST Starter Preview2. Ignore the name of that download, the HttpClient part can be used independently of WCF.
It is a WAY better client than just using HttpWebRequest.
If you do a web based application not having installed .NET in the client machine wont be a problem .. but I suppose you dont want to try both C# and web development at the same time
It is easy with Python to pull data from a web server, parse the JSON or XML, and generate some kind of report. If you need really good Excel integration (for example, your output is supposed to be an Excel spreadsheet that includes numerous graphs) C# might be better, but Python is still possible; there is PyExcelerator for writing rich spreadsheet files, and there is Python support for COM if you want to use COM to talk to Excel.
With Python it is also very easy to make a stand-alone executable, for example with py2exe.
This sounds like a batch tool, one that won't have a GUI; I think I would write it in Python if I were you, unless I really wanted a fun project to help me learn C#. But anything with a GUI, C# is probably better. (I haven't done GUI development with Python, but I have seen comments here and elsewhere that the performance of Python GUIs tend to be slow.)
The answer probably has more to do with the circumstances than the question of which is the better language for the task at hand.
If you have no prior C# experience, it's probably not a good idea to jump into it now and learn it as you go along. Syntax differences are trivial to learn, mastery is defined by knowing the dirty details and how to use the language's strengths to get the job done.
If you have plenty of time and starting over a lot is NOT an issue, or you have experience with a language that is paradigmatically very similar to C# (say, Java or C++), you could probably afford to take the risk and adapt to the new language very quickly.
If you don't care about efficiency (e.g. it's a pet project, you don't care much about your job or efficiency simply isn't important), try C# just to learn something new (always a good thing) or stick to Python to make sure you won't have to adjust your thinking too much (always a source of vulnerabilities and misunderstandings).
If you definitely want to use C#, you should play around with it in your "free time" (not necessarily at home, but preferably at work when there's nothing else to do) and thus build a skillset you can use once you have to start with the actual project. This way you'll already be familiar with the paradigm (to use the term loosely) and encounter less problems where they count.