将C#代码转换为C代码 [英] Converting C# code to C code

查看:372
本文介绍了将C#代码转换为C代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有C#代码初始化力反馈操纵杆并播放效果文件(振动操纵杆)。我已经将控制台应用程序转换为库代码来制作一个dll,以便我可以在LabVIEW中使用它。我在LabVIEW中找不到关于如何使用该DLL的任何内容。我只知道我需要使用属性,构造函数和调用节点。我知道有人可以用C写的dll帮我怎么做。



是否可以将C#代码转换为C代码?我的朋友说了一些关于C包装的东西。我看到你可以将C转换为C ++,但是我没有看到C#到C.如果你能做到这一点,转换它是否很难?

I have C# code that initializes a force feedback joystick and plays an effect file(vibrates the joystick). I have turn the console application into library code to make a dll so that I can use it in LabVIEW. I couldn't find anything about how to use that dll in LabVIEW. I just know that I need to use property, constructor, and invoke node. I know someone who can help me how to do it with a dll written with C.

Is it possible to convert C# code into C code? My friend said something about C wrapper. I saw that you can convert C to C++ but I haven't seen C# to C. If you can do this, is it hard to convert it?

推荐答案

那里不是转换这样的东西。不仅平台,而且平台的类型非常不同,范例和许多想法,水平,都是不同的。您可以使用C作为参考来编写C#代码,但相反......只是忘了它,从头开始写。



-SA
There is no such thing as "convert". Not only the platforms, but the types of platforms are very different, paradigms and many ideas, level, all is different. You can write C# code using C as reference, but the opposite… just forget it, write all from scratch.

—SA


我建​​议你采用这种方法:集成LabVIEW和C#1 [ ^ ]?
May I suggest you this approach: "Integrating LabVIEW and C# 1"[^]?


请参阅我对解决方案1的评论。



这个想法本身很好,但是错误的声明(我解释)破坏了一切。同时,您可以创建一个C#类库并对其进行修改(使用可以构建的外部工具)将某些托管方法导出为非托管方法。这很棘手但也适合你。



我自己在CodeProject找到了一些文章,并试了一下。请参阅我过去的参考资料并找到这些文章:

如何在Visual Basic 6.0中使用Visual Basic 2008中创建的dll [ ^ ],

调用托管DLL编写在C#中来自Unmanged Code VC ++ [ ^ ],

.Net中的API:托管代码或非托管代码 [ ^ ]。







在我批评解决方案1后,让我解释一下它的理性部分。这个想法很简单:不是在C中编写你的DLL代码(我真的很抱歉,如果你必须:-)),而是使它成为混合模式(托管+非托管)C ++ / CLI DLL。您可以导出非托管部分并在其中包装C#调用。由于这也是一个常规的.NET程序集,你可以通过正常引用它来使用用C#编写的程序集。



最有可能的是,这种方法对你来说最简单。这不算解决方案3,这可能是最好的,但我从未尝试过。



-SA
Please see my comment to Solution 1.

The idea itself is good, but the false claim (I explain) spoils everything. At the same time, you can create a C# class library and modify it (with outside tool you can build) to export some managed method to unmanaged. This is tricky but can work for you, too.

I found some articles in CodeProject myself, and tried it out. Please see my past reference and find those articles:
How can I use a dll created in Visual Basic 2008 in Visual Basic 6.0[^],
Call Managed DLL written in C# from Unmanged Code VC++[^],
API's in .Net: Managed or UnManaged Code[^].



After I criticized Solution 1, let me explain what is the rational part of it. The idea is simple: instead of writing your DLL code for LabVIEW (I'm really sorry if you have to :-)) in C, but make it mixed-mode (managed+unmanaged) C++/CLI DLL. You can export unmanaged part and wrap you C# calls in it. As this is also a regular .NET assembly, you can use the assembly written in C# by normal referencing it.

Most likely, this approach would be the easiest for you. This is not counting Solution 3, which might be the very best, but I never tried it.

—SA


这篇关于将C#代码转换为C代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆