C# with C++ Functions - Learn How to Link Together

In summary, two experienced programmers advised the speaker not to use C++ for windows forms applications due to its time and complexity. They suggested using C# and linking C++ functions. The speaker asked for an example of how to link the two languages together and was directed to a website and a book for guidance.
  • #1
CFDFEAGURU
783
10
Hello all,

All of my C++ programming experience is in the coding of console applications and I have recently been asked to re-code some of my console applications as windows forms applications. I asked two highly experienced programmers (one a physicist and the other a financial/business relations expert) about C++ for windows forms applications and they told me never to use C++ for windows forms applications. The main reason being, simply too much time and complexity.

However, they did instruct me to use C# for the windows forms and link the needed C++ functions. Neither of them directed me as to how you link the C++ functions to the C# forms.

I have a good deal of experience with forms, controls, and events in VBA for Excel and Access so I am not totally green with form applications.

So I have two questions;

1. Are they correct about "never use C++ for windows form applications"?

2. Does anyone have a simple example of how to link the two languages together?

Thanks
Matt
 
Technology news on Phys.org
  • #3
CFDFEAGURU said:
So I have two questions;

1. Are they correct about "never use C++ for windows form applications"?

Yes, I always give the same advice.

2. Does anyone have a simple example of how to link the two languages together?

Thanks
Matt

Compile the C++ into a dynamic library (dll), then you can import the function. Heres an example

http://www.csharphelp.com/archives/archive52.html
 
Last edited by a moderator:

Related to C# with C++ Functions - Learn How to Link Together

What is C#?

C# is a modern, object-oriented programming language developed by Microsoft. It is widely used for building applications for the Windows platform and the .NET framework.

What is C++?

C++ is a high-level, general-purpose programming language that was developed as an extension of the C language. It is widely used for developing system and application software, game development, and more.

What are functions in programming?

Functions are a set of instructions that perform a specific task or calculation. They allow for code reusability and help to make programs more organized and efficient.

How do you link C# with C++ functions?

To link C# with C++ functions, you can use a technique called "Platform Invocation Services" (P/Invoke). This allows you to call C++ functions from your C# code by specifying the function's name, parameters, and return type.

Why would you need to link C# with C++ functions?

There are a few reasons why you might need to link C# with C++ functions. One reason could be to leverage existing C++ code in a C# project. Another reason could be to take advantage of C++ performance for certain tasks that are not as efficient in C#.

Similar threads

  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
15
Views
5K
  • Programming and Computer Science
Replies
22
Views
2K
  • Programming and Computer Science
Replies
14
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
453
  • Programming and Computer Science
Replies
9
Views
4K
  • Programming and Computer Science
Replies
8
Views
893
  • Programming and Computer Science
Replies
1
Views
943
  • Programming and Computer Science
Replies
8
Views
258
  • Programming and Computer Science
Replies
11
Views
1K
Back
Top