如何为c#.net制作DLL [英] how to make DLL for c# .net
问题描述
朋友们,
我有一些用c语言编写的函数代码。
i希望在我的c#中使用这些函数.net项目,没有在c#.net中再次编写该逻辑。我可以制作一个c代码并在我的c#.net项目中使用它吗?如果是的话请告诉我。那个c代码是四个文件中的两个.h和两个.c extension.i试图通过将扩展名从.c更改为.cpp来创建dll,并在.net中创建一个dll usin c ++但是它不起作用。请建议一种方法来做到这一点。
谢谢你。
在我看来,你应该编译有效的Win32 DLL的C代码。这意味着,您要调用的函数必须为此做好准备。 (我不是C的专家,但可能类似于extern关键字)。这应该只是对实际代码的一个小改动。
之后,您可以在.NET项目中使用此DLL。请参阅本教程: http://msdn.microsoft.com/en-us/magazine/cc164123.aspx [ ^ ]
我希望,我的回答有点帮助:)。
你不需要改变<$的扩展名c $ c> .c 文件以生成DLL。看看这篇文章 [ ^ ]解释了如何创建一个简单的DLL,以及 macika123 的链接[ ^ ]提供了如何使用的P / Invoke。假设您有某个版本的Visual Studio或Visual C ++ Express,那么您将找到可以使用的DLL模板项目,只需将代码添加到相关位置。
试试这个
http://www.codeproject.com/Articles/619858/Creating -DLL-in-csharp [ ^ ]
hi friends,
I have a code of some functions written in c language.
i want to use that functions in my c# .net project,without writing that logic again in c# .net . can i make a dll of that c code and use it in my c# .net project ? if yes tell me the way . that c code are in four files two of .h and two of .c extension.i tried to make the dll by change the extension from .c to .cpp, and make a dll usin c++ in .net but it does't work . please suggest a way to do this .
Thankyou .
In my opinion, you should compile the C-code to a valid Win32 DLL. This means, that the functions you want call must be prepared for this. ( I'm not an expert in C, but propably something like extern keyword ). This should be only a minor change to the actual code.
After that, you can use this DLL in your .NET projects. See this tutorial: http://msdn.microsoft.com/en-us/magazine/cc164123.aspx[^]
I hope, that my answer at leat a bit helpful :) .
You do not need to change the extension of the .c
files in order to make a DLL. Take a look at this article[^] which explains how to create a simple DLL, and also the link that macika123[^] provided on how to use P/Invoke. Assuming that you have some version of Visual Studio or Visual C++ Express then you will find a template project for DLLs which you can use, just add your code into the relevant places.
try this
http://www.codeproject.com/Articles/619858/Creating-DLL-in-csharp[^]
这篇关于如何为c#.net制作DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!