Setting up a mixed C# and C++ project in Visual Studio - c#

I want to create a Windows application using a C# GUI that calls some C++ code but I have troubles setting up the project in Visual Studio.
I understood that I have to do it the following way : 3 projects (the C++ project, the C# project and a wrapper CLR project) that are linked to each others in some way. I just can't figure out how the link works.
If anyone can explain me in details what I have to do, I'd be really happy :3
Otherwise, I can use a Github link of a project already set up that I could copy.
Thanks in advance to anyone who will take some time to answer.

Related

How to go to implementation of C# code in VSCode? [duplicate]

This question already has an answer here:
Is there a way to see decompiled C# code in VS Code?
(1 answer)
Closed 5 months ago.
Prerequisites:
I use Visual Studio Code Version: 1.63.2 (Universal)
MacOS Monterey 12.03 with M1
.NET version 6.0.302
Originally I am coming from Python, but lately, I interact with C#(in particular ASP.NET Core 6) a lot.
I have been trying to find an answer to a question:
How can I go to the implementation of the method/class in a dependency package installed in my .NET project? Is it possible to do it in VSCode?
Probably, I am just struggling with how should I formulate this question, so let me provide some examples below.
If I am using PyCharm and, let's say, have an installed package flask-login. I can import the function login_user as on the screenshot below.
Then just go to its implementation and see the whole code as on the screenshot below.
This happens because both in PyCharm and in VSCode it redirects me to the files stored in the bin directory of my interpreter path. As a result, I can always go locally and check the source code of all installed dependencies.
Now coming back to C#: I want to have the same thing in my .NET project with VSCode (I don't use Visual Studio and use MacOS). As for now in VSCode, I can only go to the interface code of a dependency and when I press go to implementation it says Implementation not found.
I am not sure whether this is possible or not, since C# is a compiled language, so probably it would require a decompiler for this to work. The only thing I managed to make work was the possibility to jump into implementation during debugging session https://github.com/OmniSharp/omnisharp-vscode/wiki/Debugging-into-the-.NET-Framework-itself. At the same time, this is slightly different from what I want -> I just want a convenient way to go into the implementation source code to understand what is happening in the code LOCALLY and probably set breakpoints in this code if I think it makes sense.
Therefore, my main question stays the same: Can I do it on MacOS in VSCode?
UPD: I tried Rider from JetBrains(https://www.jetbrains.com/rider) and it works there. Still interested in making this work in VSCode.
An answer is basically here -> Is there a way to see decompiled C# code in VS Code?
There is a feature to enable decompilation in omnisharp extension for C# in VSCode.
Thanks to #UnholySheep!

How do I call windows form c# functions from c++ project?

I was working on a windows form project lately and I made some functions in that project that I want to use from another c++ project of mine. My windows form project is creating a .dll already, so I was wondering if I could call my functions thanks to it somehow.
I tried creating a CLR empty project as I know those are supposed to link C++ and C# possible but when I try to use the namespace of my C# classes in the CLR project, visual doesn't find it and tells me the name I'm trying to use must be a namespace, am I missing something?
Here are some images of what I've done:
Encrypter.cs (the C# class I'm trying to use)
The C++ file in the CLR project trying to use it (I tried several ways of getting my class, I left them all, none worked)
Both projects are next to each other in the same solution.
To sum up my questions:
Do CLR projects work both ways with C++ and C#? I find very few mentions of C++ projects using C# functions, but much more of the other way around.
Is it possible to call windows from C# functions from a C++ or CLR project, or do I have to make another C# project that creates a .dll ?
If I'm going the right way with what I've already done, how do I use my C# class in my CLR project?
EDIT: For anyone maybe coming through here, I found the solution. Turns out I did miss something in my setup, when selecting the CLR project and going in the "Project" menu on top of visual studio, you can then go to "Add Reference" and select your C# dll. Once I did this, the CLR project saw all my C# classes and functions.

Cannot access linker options in Visual Studio 2015

I created a simple C# WPF application (executable) and I cannot seem to get into the linker options. I copied a screenshot from the internet:
I want to see this window in my application but I can't find it anywhere. I know I have been in this kind of window before, I forgot how I got there and I've spend an hour now to find it and I'm going nuts. I read everywhere that I have to select my project (not solution) and then go to properties. However, it takes me here:
Can anybody explain to me in extreme detail how I get to the linker properties? I use Visual Studio 2015.
You're mixing up C++ annd C#.
Your first screenshot shows a C++ project, and your second screenshot shows a C# project.
C# doesn't let you manually configure linker options.

Compiling Allegro source code

I am trying to build a C# project (downloaded code) in Visual Studio Express 2008. I get the error (my translation):
The type or namespace name "Allegro"
couldn't be found.
for the line
using Allegro;
I know the 2D graphics library Allegro, of course, but I can't find much information on how to use it in C#. It is being used for visualization in the project I am trying to compile.
I also get the warning
This reference couldn't be resolved.
The Universal assembly couldn't be
found.
I haven't been working with C# before and and I barely know Visual Studio Express. These are newbie mistakes - but I just need a fast solution for this problem. Could someone provide me with a short step-by-step solution?
Remove old reference of Allegro.dll from project and add it again.
Allegro isn't a .NET library; it's written in traditional unmanaged C. If you downloaded code that references an Allegro C# library, then perhaps the author was using some unofficial C# bindings. If so, the solution is to find that additional library and use it.
Otherwise, there is no short, step-by-step solution. You would need to use DllImport on each function that you need, and follow the standard practices for using unmanaged C DLLs in C#.

Help creating a dll for a custom control

I'm going to ask a newbie question here. I need to use a control I found online in my code, but it was written in the wrong language. It is in C# and I am using VB.net for work. I have all of the code for the control which works beautifully in C#, but I had issues with it not working very well in VB.
The source code and a demo project are available here, but I am not sure exactly which files I should use to build the dll for VB.
It seems a lot to ask, but would someone mind taking a look and pointing me in the right direction?
Cheers
Add the project to your solution, or just build it using your version of Visual Studio. Then add a reference, either to the project in the first case, or the .dll in the second.
If the Control doesn't work well, it's not because it's written in C# as opposed to VB.Net.
You should be able to use/reference the DLL as-is from your visual basic solution. It doesn't matter whether it was written in C#, VB.NET or any other .net language.
One you compile a dll from the c# source it will work exactly the same as if it were written in vb. You simply need to create a reference to the dll in visual studio.

Categories

Resources