How to Compile a c++ program using .NET Framework libraries - c++-cli

i want comile a my c++ program using .NETFRAMEWORK libraries only at command prompt.how can i do this ??

Download the free Visual C++ Express tools from Microsoft and use the C++/CLI language (based on C++ but allows access to the whole .Net Framework) and go from there.

Basically, you're talking about Visual C++. As for using the command prompt, once you have a working program you should just be able to use something like:
cl MyProgram.cs /clr
with any other relevant options, and be up and running. If that doesn't help, give a more specific question.

Related

C++/CLI Support in .Net Core

Our project structure is like,
native.dll :- This contains pure native code written in c\c++.
This native.dll exposes some functions using *def file.
Wrapper Library(wrapper.dll compiled with .Net framework v4.0) :-
In order to use functionality of native.dll, a Wrapper lib(wrapper.dll)
is written in C++\CLI using :clr\oldsyntax. This wrapper has all
code of Interoperability and Marshalling.
Application(Console App v4.0) directly uses wrapper.dll to use functionality provided
by native.dll.
Now this project needs to run in .Net Core. This means we will have an
.Net Core application that will reference wrapper.dll that in turn will refer
native.dll.
I know this will not directly work. But the issue is whether .Net Core(CoreCLR) supports
C++\CLI (clr\oldsyntax) runtime environment ?
If no, what can be the possible solutions to this application work ?
whether .Net Core(CoreCLR) supports C++\CLI (clr\oldsyntax) runtime environment ?
As far as I know there is no plan to support C++/CLI with .NET Core.
If no, what can be the possible solutions to this application work ?
You can (should) provide a C API. Mono e. g. supports P/Invoke and .NET Core also supports P/Invoke (see also this Stack overflow question and this DllMap related ticket).
Update (2022-09-02): This answer is from 2016. See the other answers (e.g., this) for what is possible with recent .Net Core versions.
Officially announced eventually...
(next wish... support linux # .Net 5 ^^)
https://devblogs.microsoft.com/cppblog/the-future-of-cpp-cli-and-dotnet-core-3/
C++/CLI will have full IDE support for targeting .NET Core 3.1 and higher. This support will include projects, IntelliSense, and mixed-mode debugging (IJW) on Windows. We don’t currently have plans for C++/CLI for targeting macOS or Linux. Additionally, compiling with “/clr:pure” and “/clr:safe” won’t be supported for .NET Core.
The first public previews for C++/CLI are right around the corner. Visual Studio 2019 16.4 Preview 1 includes an updated compiler with “/clr:netcore”
Updat: From replied of origin url:
"We are still working on the IDE and MSBuild integration, so I can’t share a sample project quite yet. Once it’s available, likely with 16.4 Preview 2 or 3"
(16.4 Preview1 cannot create C++/CLI with .NetCore project.)
191015
16.4 Preview2 Released.
I'v tried asp.net core 3.1 with c++/CLI dll, it works.
(need set plateform to x64 both asp.net core and c++/CLI dll)
.net Core team will only commit (now?) to supporting C++/CLI for Windows only.
The intention was to deliver it for .net Core 3.0. While I haven't found explicit mention of it yet in the release notes, C++/CLI support was a prerequisite for delivering WPF (windows-only), which is now supported in .net Core 3.0.
Support mixed-mode assemblies on Windows - #18013
This issue (#18013) will track progress toward supporting loading and running
mixed-mode assemblies on CoreCLR. The main goal is to provide support
for WPF and other existing C++/CLI code on .NET Core. Some of the work
will be dependent on updates to the MSVC compiler.
The github issue (#659) mentioned above by #Tomas-Kubes, Will CoreCLR support C++/CLI crossplat? - #659, is about cross-platform C++/CLI.
BTW, I am getting compiler warnings on "clr\oldsyntax" with VS2017/.net-4.7. So this compiler flag is already deprecated.
UPDATE: This isn't coming till .Net Core 3.1
Another potential solution (though obviously quite a difficult task) if you want to stick with C++ (i.e. expose an OO interface to .NET) might be to have a look at CppSharp from the mono project. It is able to expose native C++ code through an automatically generated C# wrapper. It supports Windows, Linux as well as OSX. However, I don't know if the generated code can be compiled to a .NET standard target (didn't try to). I can only suppose it would because the generated code does not use any fancy API (it is basically interop and marshalling code); and, by the way, it is also possible to customize the generation process (although, once again, probably not an easy task).
For those who are looking at this for general .Net Core stuff without specific clr parameters (as this is a high result on google) Microsoft have written a guide on how to port C++/CLI to .Net Core:
https://learn.microsoft.com/en-us/dotnet/core/porting/cpp-cli
Port a C++/CLI project
To port a C++/CLI project to .NET Core, make the following changes to the .vcxproj file. These migration steps differ from the steps needed for other project types because C++/CLI projects don't use SDK-style project files.
Replace <CLRSupport>true</CLRSupport> properties with <CLRSupport>NetCore</CLRSupport>. This property is often in configuration-specific property groups, so you may need to replace it in multiple places.
Replace <TargetFrameworkVersion> properties with <TargetFramework>netcoreapp3.1</TargetFramework>.
Remove any .NET Framework references (like <Reference Include="System" />). .NET Core SDK assemblies are automatically referenced when using <CLRSupport>NetCore</CLRSupport>.
Update API usage in .cpp files, as necessary, to remove APIs unavailable to .NET Core. Because C++/CLI projects tend to be fairly thin interop layers, there are often not many changes needed. You can use the .NET Portability Analyzer to identify unsupported .NET APIs used by C++/CLI binaries just as with purely managed binaries.
Build without MSBuild
It's also possible to build C++/CLI projects without using MSBuild. Follow these steps to build a C++/CLI project for .NET Core directly with cl.exe and link.exe:
When compiling, pass -clr:netcore to cl.exe.
Reference necessary .NET Core reference assemblies.
When linking, provide the .NET Core app host directory as a LibPath (so that ijwhost.lib can be found).
Copy ijwhost.dll (from the .NET Core app host directory) to the project's output directory.
Make sure a runtimeconfig.json file exists for the first component of the application that will run managed code. If the application has a managed entry point, a runtime.config file will be created and copied automatically. If the application has a native entry point, though, you need to create a runtimeconfig.json file for the first C++/CLI library to use the .NET Core runtime.
There are some more nuances but these are the actual steps to port

VB -When a compiler compiles the code, does it include the libraries that were imported?

I'm really sorry about this basic question but I couldn't find anything on MSDN except an overview of the import function. I'm using Visual Studio 2013 and I've imported the System and System.IO libraries. I'm wondering if this would make the program unusable if they didn't have the libraries preloaded on their machine or if the compiler actually includes the files needed so the application is truly standalone. Thank you!
System and System.IO are part of the Microsoft .NET Framework. Without the Framework, your program won't execute at all. Most modern Windows machines already have some version of the Framework installed.

Does monodis tool from mono work against Microsoft .NET assemblies?

I know the monodis tool does the same thing for Mono that ILDASM does for Microsoft .NET. But is the monodis tool compatible with .NET in that it would work against a Microsoft .NET assembly because it works to the same file layout as Microsoft?
Yes, it does. Also, it's trivial to check, why did you even bother asking this?

VS2008 non.NET Application

How can I create a VB application in VS2008 without requiring the application be run on a computer with a .NET framework in place?
You can't create a non-managed VB application in VS 2008.
You would have to use C/C++ or go back to VS 6.
You can look at the question below for more information on .NET linkers. That is technically an option, but if I were starting a new application that I didn't want to depend on the .NET framework I would not use a managed language.
Running .net based application without .net framework
You'll need to use a 3rd party .NET linker, Visual Studio itself doesn't support what you're after but a number of tools allow it to be done.
A couple of tools:
Remotesoft Salamander .NET Linker
Xenocode app virtualization
Another, non-VS, option is to use Mono to build a "Bundle" which combines both the runtime and your application into a single executable:
Mono:Runtime - Bundles
You can't. You would need to go back to Visual Studio 6 and create a VB6 app.
You can't. VB is .net based, there isn't a non .net VB anymore.
The best you can do is include the .net redistributable with your application's installation.

How to create DLL library on Windows with WxWidgets?

I'm looking for a simple example how to create a DLL library on Windows with WxWidgets.
I need use some wxWidgets API on DLL and it'll called from Delphi.
There is the "dll" sample showing how to do it in your wxWidgets directory or you can view it online at https://github.com/wxWidgets/wxWidgets/tree/v3.1.0/samples/dll
I think the easiest way is to install the free Visual C++ Express Edition, compile the DLL with that (Visual Studio project files are provided with WxWidgets). If it still works like in the old days, then you will also have to import the library for use in delphi with with the implib command.