how to create a DLL for all language [closed] - c#

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
how to create a file DLL, so all language dev can used it
i think, if use C++ to created , then language .Net can used it.
however, how about JAVA ??? and a few other language

The only guaranteed way to make a DLL that is consumable by other platforms and languages is to write it a language/platform that exports static C functions; the easiest way is to write in C and C++ directly, though other languages can too. That way you can call it from C, C++, .NET/C#/VB (using DllImport P/Invoke), and Java (using JNI). Other languages also support importing C functions.
(Generally) you cannot export classes or other types. If your C functions use structs then you must document those in a header file or other definition for your DLL's consumers to use.
There are other approaches, including COM (which supports exporting interfaces and other types) and the new WinRT Metadata format, but this is new and has not seen wide deployment. And COM is an exercise in pain.

Java and other languages other than C#, C, and C++ can't use dlls made as C code. They're completely different languages, with Java using a Java Virtual Machine to run just-in-time bytecode, and Ruby/Python/other scripting languages using an interpreter. In fact, dlls themselves are only part of C/C++/C#. C# only is able to use C/C++ dlls because Microsoft intended compatibility.
On the other hand, you might try creating wrappers so other languages can use the code you created.

Related

Running native Delphi code in dot net environment with c sharp [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have a Delphi program consisting of mostly Visual Interface(Buttons, TextBoxes etc.) and a little bit business logic.
The business logic is mostly included in Pl-Sql of Oracle Database running by Delphi.
I want to carry the project in Delphi to C Sharp but i want to do this part by part.
What i think is to create a C Sharp project in Visual Studio and to run it with Delphi code(including Visual Interfaces) and part by part replace the code and the Visual Interface in Delphi with C Sharp.
Is it possible?
Mixing Delphi and C# GUI in the same application is possible, but hard to achieve. You'll need to set up a whole infrastructure to organise interop between the two languages. You'll end up creating a huge amount of interop code that you will subsequently abandon. Even worse, the interop code will need to be two way. You'll sometimes have C# visual code talking to Delphi non-visual. And vice-versa. The idea of converting the code module by module sounds good, but I predict it will entail vast amounts of interop scaffolding.
It would be easier to slice it along the visual/non-visual divide, but that's not what you are proposing. So frankly I think your current plan is far from optimal. I would not entertain it. I think a clean port is the best option.
Remobjects Hydra seems to be exactly what you are looking for.

How Do REPL Interpreters For Compiled Languages Work? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I cant even begin to understand how they work, its a very broad question i guess. How is it possible that one could take a language such as C# which is compiled to IL for the CLR, then further JIT compiled into machine code at run time, and write an Interpreter or REPL for it as implemented in the mono project. How did they get that right?
What is the issue? Machine code is just some data (laying in virtual memory pages which are executable). You can produce that data, then, since it is also code, run it.
You can produce machine code in memory in various ways. For example, you could use LLVM or libjit or many other libraries (or even make your own).
Some implementations of some langauges (I was thinking of the SBCL implementation of Common Lisp) are even able to translate to machine code every line you are interactively typing. And this is not new, some 1957 computers did it (e.g. the French CAB500 for PAF).
You can even generate some source code (e.g. in C), fork a compilation process, then dynamically load that code, e.g. with dlopen(3). Current compilers and processors are fast enough to make that compatible with delays for user-friendly interaction. My MELT domain specific language (to extend GCC) does that successfully.
AS commented by millimoose, Mono is free software, so you can study its code.
The equivalence of code and data is a fundamental property of computers. Likewise the equivalence of numbers and demonstrations in a fundamental insight of Gödel and Turing (and when you hear your favorite MP3 music, you use that too).

Converting a C# engine into C++ for speed [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
So this is the situation right now:
I have a C# GUI project combined with a C# Engine project in the same solution. The GUI allows interaction with the user, some high level stuff etc. The functionality of the Engine is to communicate with another third-party application. The Engine has sockets that connect to the third-party application as well has methods to convert a message into an object, send it to the third-party application, and listen for a response from the third-party application and react accordingly. Data to be communicated between the Engine and the Third-party application are packaged into objects.
The problem with the C# engine is that it's too slow. So the idea is to convert the engine to unmanaged C++ for speed.
This is my plan of attack:
Translate the entire C# engine by hand into C++ (which is already pretty daunting because the C# engine includes threads and hashtables)
Have the following to substitute for constructors, accessors, and mutators in C++:
void* CreateInstance()
{
MyClass* p = new MyClass();
return p;
}
void ReleaseInstance(void* pInstance)
{
MyClass* p = (MyClass*)pInstance;
delete p;
}
int GetData(void* pInstance)
{
MyClass* p = (MyClass*)pInstance;
return p->GetData();
}
void SetData(void* pInstance, value)
{
MyClass* p = (MyClass*)pInstance;
p->SetData(value);
}
(The reason why I can't use real classes in C++ is because you can't instantiate C++ objects in C#)
Then build a C++ unmanaged DLL, use P/Invoke within the C# GUI project ([DllImport etc.]) to access all the C++ methods, and use that to replace the C# engine. Objects will be simulated using methods and passed back and forth between the C# GUI and C++ Engine.
Before I embark on this time-consuming task, is there any C# code that would be impossible to translate into C++ and then re-imported back into the C# GUI through this method?
There's not going to be any C# code that's impossible to translate into C++. You might want to look into if there are any library functions in .NET that aren't covered by the C++ libraries you'll be working with, though. Make sure you aren't getting stuck with any wheels to reinvent.
That said, in my practical experience real-world C++ code is not naturally faster than real-world C# code. It's true that a C++ programmer has more available tricks that can allow them to get better performance, but the effort involved in getting to that point can often be quite formidable. Consider the famous case of the competition between Rico Mariani and Raymond Chen. The advantage Chen's final version enjoyed over Rico's was ultimately down to just the time the .NET run-time needed to bootstrap itself. That's a bit of overhead that's negligible for a longer-running process.
So I would strongly encourage you to try spending some time with a performance profiler to see why the C# code is slow first, and what you can do to speed it up. It may very well be that by going that route you can get the code running fast enough for your needs with a fraction of the effort. It's amazing how impressive you can look just selecting better data structures.

Combining C# with C++ in a single project [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I am assigned a project in which there are two parts :
Database Programming
Game Programming
I am incharge of Database programming and my partner the later. But I am friendly with C-sharp Database programming as it is very efficient using Visual Studio. But he has a Game experience in C++.
Our target system is Windows 7,database will be Sql Server Database, and game can be in C or C++.
We will have a link in Windows forms that starts the Game.
How do we solve this problem without changing our partners?
From a technical point of view it is possible to write a project in multiple languages. From a practical standpoint it is not a good idea.
If this is a small project that will not be enhanced and will be write once and forget then it is fine, otherwise not.
You don't necessarily need to change partners, one of you just needs to step up and say they will jump the learning curve. As a programmer you need to be able to work in whatever language is required.
There are many factors that decide which language/library to use. Write them down with the pros and cons and decide which makes the most sense for your application. Agree that once this is settled then the topic will not come back up. Maybe find an neutral arbitrator that you can both elect to decide for you.
A partner is more than their ability to write code in a given language. The coding part is a small part of the project.
I suggest looking at Managed c++ and the /clr compilation switch for c++. Using managed c++ you can expose what you need to the .net world using .net objects where appropriate, but use native c/c++ code internally.
Managed c++ also have alot of ways to integrate efficiently with .net, such as object pinning (no relocation by the gc)
c++ compiled with /clr can be consumed from any .net language like a regular .net assembly. c++ code compiled this way can also consume any .net assembly much like the other .net languages do.
You haven't provided much details about this game but can't you Process.Start the Game from your WinForms application and passing it the necessary parameters that you fetched from the database?
Another option would be to wrap the database in a COM object developed in .NET that the game, if written in C++ can consume.
I am working on a project right now (and recently completed a similar one) that combined C#, and C++ libraries using C++/CLI. The data collection and signal processing were all written in C++ (your game piece) and the forms, xml and plotting was all done in C# (your db piece). C++/CLI handled the impedance mismatch between the two languages. I actually ended up writing little more than a mediator class in C++/CLI (I find it much more pleasant to write in C#). I think this would work for you too. The only issue is that C++/CLI is not C++. In fact I would suggest that the C# programmer learn C++/CLI rather than the C++ programmer. My reasoning is that syntactical differences between the languages are rather trivial and the C# programmer can probably learn those faster than the the C++ programmer coming to grips to what managed code and .NET is all about. That said, if you both took responsibility for the C++/CLI piece you would have all the skill sets needed to tackle it with the minimum amount of pain.

Is c# code or script? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
Let's define languages like c,c++,java as code
Python,PHP as script.
Is c# code or script, and reason?
The most similar language to C# from your list is Java, so if you think Java is "code" then I guess C# is too.
But the idea that languages can be divided into "code" or "script" is a huge oversimplification in my opinion. For example, PHP can be either interpreted or compiled. Java can be compiled to bytecode which is then interpreted, or it can be compiled directly to native code. Python can be useful for small "scripting" tasks, but it can also be used to write enterprise class web applications.
C# is a compiled language like java, C, and C++. C# is code
C# is code, compiled and strongly typed, very similar to Java in that respect.
C# is compiled to an intermediate language (MSIL), which in turn is compiled to machine code on a just-in-time basis.
By that definition, it's "code" - as it's compiled, where as PHP / Python are interpreted at run time.
Code - you compile C# code into binary executable files.
C# is code (along with C, C++, Java, etc.). It gets compiled to CIL and then JIT compiled to machine code when you run the application.
Scripting languages are interpreted as they run. Think of Javascript running in the browser. As it is executed, it is interpreted by the Javascript engine that is executing it.
Code.
Scripts can be interpreted (compiled) on the fly at runtime. C# can't (well, that can and may change one day).
C# is a .NET programming language, quite similar to Java.
I don't understand the purpose of your question.
C# would be closer to Java than C or C++. But it's not a script language that is run through an interpreter like PHP. But it's not a purely compiled language either, like C/C++ typically are. C/C++ are compiled down to machine code that is executed directly by the CPU it's compiled for. C# and Java are compiled down to an intermediate language (MSIL and Java byte code respectively) and are then run by a VM which usually JIT compiles it to the final CPU code.

Categories