在VC ++ .NET项目中包含C#文件

编程入门 行业动态 更新时间:2024-10-27 12:40:12
本文介绍了在VC ++ .NET项目中包含C#文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好,我刚刚开始尝试使用VC2005创建一个C ++ WinForms 应用。我创建了一个简单的表单,它的工作原理。现在我想添加一个C# ..cs源文件,其中包含我从CodeProject下载到我的C ++应用程序中使用的的新类。我曾尝试将C#源文件添加到我的C ++ 项目中,但设置中没有编译器选项。 IDE没有似乎能够编译.cs文件。我可以将其他 ..NET语言(如C#和VB.NET)的源文件添加到我的C ++项目中吗? 我成功创建了另一个针对同一解决方案的C#DLL的项目, 并且能够通过在我的C ++应用程序中使用#来访问C#类。但是 是否需要将每种语言的模块(如C#)放在一个单独的 模块中并一起构建?如果是这样,那就不方便了。 谢谢, David www.dcsoft

Hello, I am just starting to experiment with VC2005 to create a C++ WinForms app. I have created a simple form, and it works. Now I want to add a C# ..cs source file containing a new class that I downloaded from CodeProject to use in my C++ app. I''ve tried simply adding the C# source file to my C++ project, but there is no compiler options in the settings. The IDE doesn''t seem able to compile the .cs file. Am I able to add source files from other ..NET languages such as C# and VB.NET to my C++ project? I did succeed in creating another project for a C# DLL to the same solution, and was able to access the C# class by #using the DLL in my C++ app. But is it required that modules in each language (like C#) be placed in a separate module and be built together? If so, it is kind of inconvenient. Thanks, David www.dcsoft

推荐答案

可以转换文件。我们的Instant C ++ C#到C ++转换器演示 将一次转换100行,因此在 中一次粘贴一个方法应该有效。 (虽然你可以通过一次转换 整个文件来获得更好的转换。) - David Anton www.tangiblesoftwaresolutions 即时C#:VB.NET转C#转换器 即时VB:C#到VB.NET转换器 即时C ++:C#到C ++转换器 即时J#:VB.NET到J#转换器 " David Ching"写道: It is possible to convert the file. Our Instant C++ C# to C++ converter demo will convert 100 lines at a time, so pasting the methods one at a time in should work. (Although you will get a better conversion by converting the entire file at once). -- David Anton www.tangiblesoftwaresolutions Instant C#: VB.NET to C# Converter Instant VB: C# to VB.NET Converter Instant C++: C# to C++ Converter Instant J#: VB.NET to J# Converter "David Ching" wrote: 您好,我刚开始尝试用VC2005创建一个C ++ WinForms 应用程序。我创建了一个简单的表单,它的工作原理。现在我想添加一个C# .. cs源文件,其中包含我从CodeProject下载的新类,以便在我的C ++应用程序中使用。我曾尝试将C#源文件添加到我的C ++ 项目中,但设置中没有编译器选项。 IDE似乎无法编译.cs文件。我能否将其他 .. NET语言(如C#和VB.NET)的源文件添加到我的C ++项目中? 我成功地为C#DLL创建了另一个项目同样的解决方案,并且能够通过在我的C ++应用程序中使用#来访问C#类。但是,是否需要将每种语言的模块(如C#)放在一个单独的模块中并一起构建?如果是这样,那就不方便了。 谢谢,大卫 www.dcsoft Hello, I am just starting to experiment with VC2005 to create a C++ WinForms app. I have created a simple form, and it works. Now I want to add a C# ..cs source file containing a new class that I downloaded from CodeProject to use in my C++ app. I''ve tried simply adding the C# source file to my C++ project, but there is no compiler options in the settings. The IDE doesn''t seem able to compile the .cs file. Am I able to add source files from other ..NET languages such as C# and VB.NET to my C++ project? I did succeed in creating another project for a C# DLL to the same solution, and was able to access the C# class by #using the DLL in my C++ app. But is it required that modules in each language (like C#) be placed in a separate module and be built together? If so, it is kind of inconvenient. Thanks, David www.dcsoft

David Ching写道: David Ching wrote: 您好,我刚刚开始尝试使用VC2005来创建一个C ++ WinForms应用程序。我创建了一个简单的表单,它的工作原理。现在我想添加一个C#.cs源文件,其中包含我从CodeProject下载的新类,以便在我的C ++应用程序中使用。我试过简单地将C#源文件添加到我的C ++项目中,但设置中没有编译器选项。 IDE似乎无法编译 .cs文件。我是否能够将其他.NET语言(如C#和VB.NET)的源文件添加到我的C ++项目中?我确实成功地为C#DLL创建了另一个项目。解决方案,并能够通过#using C ++应用程序中的DLL来访问C#类。但是,是否需要将每种语言的模块(如C#)放在一个单独的模块中并一起构建?如果是这样,那就不方便了。 Hello, I am just starting to experiment with VC2005 to create a C++ WinForms app. I have created a simple form, and it works. Now I want to add a C# .cs source file containing a new class that I downloaded from CodeProject to use in my C++ app. I''ve tried simply adding the C# source file to my C++ project, but there is no compiler options in the settings. The IDE doesn''t seem able to compile the .cs file. Am I able to add source files from other .NET languages such as C# and VB.NET to my C++ project? I did succeed in creating another project for a C# DLL to the same solution, and was able to access the C# class by #using the DLL in my C++ app. But is it required that modules in each language (like C#) be placed in a separate module and be built together? If so, it is kind of inconvenient.

是的,这是一个要求。你不能用混合 语言构建一个DLL或EXE。 但是,您应该可以从中访问您的C#类C ++ winforms 项目,包含相应的项目引用和#using指令。确保 确保该类在C#源代码中是公开的! -cd

Yes, that''s a requirement. You can''t build a single DLL or EXE from a mix of languages. You should, however, be able to access your C# class from the C++ winforms project with the appropriate project references and #using directive. Make sure that the class is public in the C# source code! -cd

大卫...我不认为你可以从C ++ / cli netmodule中调用C#netmodule中的代码,至少我无法解决这个问题。但你可以使用csc / target:netmodule MyCSCode.cs和C ++中的cl / clr / LN MyCPPCode.cpp之类的东西在C#中编译一个netmodule。而你 应该能够创建一个类似cl / clr MyCSCodemodule MyCPPCodemodule MoreCPPCode.cpp的程序集。它将C# 和C ++ / cli纯生成的代码混合到一个程序集中。你可以通过 使用ildasm查看IL来证明这一点。 " David Ching"写道: David... I don''t think you can call code in a C# netmodule from a C++/cli netmodule, at least I have not been able to figure this out. But you can compile a netmodule in C# using something like csc /target:netmodule MyCSCode.cs and something like cl /clr /LN MyCPPCode.cpp in C++. And you should be able to create an assembly with something like cl /clr MyCSCodemodule MyCPPCodemodule MoreCPPCode.cpp. which mixes the C# and C++/cli pure generated code into a single assembly. You can prove this by looking at the IL using the ildasm. "David Ching" wrote: 您好,我刚开始尝试用VC2005创建一个C ++ WinForms 应用程序。我创建了一个简单的表单,它的工作原理。现在我想添加一个C# .. cs源文件,其中包含我从CodeProject下载的新类,以便在我的C ++应用程序中使用。我曾尝试将C#源文件添加到我的C ++ 项目中,但设置中没有编译器选项。 IDE似乎无法编译.cs文件。我能否将其他 .. NET语言(如C#和VB.NET)的源文件添加到我的C ++项目中? 我成功地为C#DLL创建了另一个项目同样的解决方案,并且能够通过在我的C ++应用程序中使用#来访问C#类。但是,是否需要将每种语言的模块(如C#)放在一个单独的模块中并一起构建?如果是这样,那就不方便了。 谢谢,大卫 www.dcsoft Hello, I am just starting to experiment with VC2005 to create a C++ WinForms app. I have created a simple form, and it works. Now I want to add a C# ..cs source file containing a new class that I downloaded from CodeProject to use in my C++ app. I''ve tried simply adding the C# source file to my C++ project, but there is no compiler options in the settings. The IDE doesn''t seem able to compile the .cs file. Am I able to add source files from other ..NET languages such as C# and VB.NET to my C++ project? I did succeed in creating another project for a C# DLL to the same solution, and was able to access the C# class by #using the DLL in my C++ app. But is it required that modules in each language (like C#) be placed in a separate module and be built together? If so, it is kind of inconvenient. Thanks, David www.dcsoft

更多推荐

在VC ++ .NET项目中包含C#文件

本文发布于:2023-11-17 06:23:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609139.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   项目   VC   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!