简体   繁体   English

如何在 C# 中使用 C-Library

[英]How to use C-Library in C#

i´ve downloaded a BACnet-Stack from http://sourceforge.net/projects/bacnet/ but it is written in c and i want to use it in c#.我已经从http://sourceforge.net/projects/bacnet/下载了一个 BACnet-Stack,但它是用 c 编写的,我想在 c# 中使用它。

I´ve been reading for 4 hours now about how to get it done but i´m not any further.我已经阅读了 4 个小时来了解如何完成它,但我不会再读下去了。 Most answers are to write the code anew in c# but i have no clue of c .大多数答案是在 c# 中重新编写代码,但我对 c 一无所知。 I opened a workspace in Code::Blocks to look into the code and compiled a library into a a.-file.我在 Code::Blocks 中打开了一个工作区来查看代码并将一个库编译成一个 a.-file。 But how can i use it?但是我怎样才能使用它?

Greetings,问候,

Stefan斯特凡

To address alike situation, Microsoft provides attributes, assembly, and marshaling to offer interoperability between managed-unmanaged code(not .net aware/running outside the clr boundaries) and managed-legacy COM.为了解决类似的情况,Microsoft 提供了属性、程序集和封送处理,以提供托管非托管代码(不支持 .net 感知/在 clr 边界之外运行)和托管遗留 COM 之间的互操作性。
Investigate the use of dynamics and the (Dynamic language runtime- DLR) which should be more than fine.研究动态和(动态语言运行时-DLR)的使用,这应该很好。
code example (using kernel32.dll) as an example of calling unmanaged code from a managed context代码示例(使用 kernel32.dll)作为从托管上下文调用非托管代码的示例

[DllImport("kernel32.dll", EntryPoint="MoveFile",
ExactSpelling=false, CharSet=CharSet.Unicode,
SetLastError=true)]
static extern bool MoveFile(string sourceFile, string destinationFile);

//calling the function
static void Main()
{
    MoveFile("sheet.xls", @"c:\sheet.xls");
}

check this pdf also: http://www.nag.com/IndustryArticles/Calling_C_Library_DLLs_from_C_Sharp.pdf也检查这个pdf: http : //www.nag.com/IndustryArticles/Calling_C_Library_DLLs_from_C_Sharp.pdf

Just as an aside;顺便说一句; the BACsharp project has the beginnings/artistic fuel to draw from - you'd have/be best to replace the use Winform timers though with generic ones, but I had spotted a C# NuGet package about a year back; BACsharp 项目具有可以借鉴的开端/艺术燃料-您最好/最好将使用 Winform 计时器替换为通用计时器,但大约一年前我发现了一个 C# NuGet 包; you might want to take a glance at that one too (?).你可能也想看一眼那个(?)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM