how can i create a DLL of a program written in c program..?
-
how can i create a DLL of a program written in c program..?(am using turbo c compiler) the same program i could use with c# or VB program as- DLL reference.. http://support.microsoft.com/kb/106553 check out this link(i didn't understand this..)
-
Answer:
Do not use Turbo C and compile with Visual C++ since we have to use Win32 calling conventions. Suppose math.h is your library. #include <math.h> extern "C" { __declspec(dllexport) double __stdcall MyPow(double, double); } extern double __stdcall MyPow(double x, double y) { return pow(x, y); } And then import it in your C# application, using DllImport. class Program { [DllImport("MyLibrary.dll")] extern static double MyPow(double x, double y); static void Main(string[] args) { Console.WriteLine(MyPow(2.0, 5.0)); Console.ReadKey(); } } This makes your code exteremly unmanaged. A Better approach would be creating a Managed C++ wrapper. To do so, create a new Visual C++ Dynamic Library project, enable Common Language RunTime Support (OldSyntax) under Project Properties > Configuration Properties > C/C++ > General and disable C++ Exceptions in Project Properties > Configuration Properties > C/C++ > Code Generation. Build for release target. extern "C" { #include <math.h> } namespace Wrapper { public __gc class MyClass { public: static double MyPow(double x, double y) { return pow(x, y); } }; }; Then create a new Visual C# project, reference the .DLL file we just made and in Project Properties > Build, check Allow unsafe code if you're using pointers in your original library and need to modify them in your C# application. class Program { static void Main(string[] args) { Console.WriteLine(Wrapper.MyClass.MyPow(2.0, 5.0)); Console.ReadKey(); } }
pvaju896 at Stack Overflow Visit the source
Other answers
Turbo C (last release in 1989) is a DOS based program. It cannot create Win32 DLLs. Since you are already using Visual Studio for C#, I would strongly suggest using Visual C++ for your DLL. Visual C++ is self explanatory (hint: Win32 DLL is the project type you want).
Yann Ramin
Related Q & A:
- How can i create a mobile application server?Best solution by Stack Overflow
- In Visual Studio 2012 or 2013, how can I register a DLL file on Windows 7 64-bit computer using a Custom Action command?Best solution by Stack Overflow
- How can i create a new blog?Best solution by Yahoo! Answers
- How can I create a new font?Best solution by Yahoo! Answers
- How can I create a cute, artsy, unique facebook profile?Best solution by Quora
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.