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

  • Context: C/C++ 
  • Thread starter Thread starter CFDFEAGURU
  • Start date Start date
  • Tags Tags
    C++ Functions
Click For Summary
SUMMARY

Linking C++ functions to C# Windows Forms applications is a recommended approach due to the complexity and time consumption associated with using C++ directly for GUI development. Experienced programmers advise against using C++ for Windows Forms, suggesting that developers compile C++ code into a dynamic link library (DLL) for integration with C#. A practical example can be found at CSharpHelp, which illustrates the process of importing C++ functions into C# applications.

PREREQUISITES
  • C# programming fundamentals
  • Understanding of Windows Forms applications
  • Experience with C++ dynamic link libraries (DLLs)
  • Basic knowledge of interop services in .NET
NEXT STEPS
  • Learn how to create a C++ dynamic link library (DLL)
  • Study the P/Invoke mechanism in C# for calling unmanaged code
  • Explore Windows Forms controls and event handling in C#
  • Review examples of C++ and C# interoperability on CSharpHelp
USEFUL FOR

Software developers transitioning from C++ to C# for GUI applications, programmers seeking to integrate legacy C++ code into modern C# Windows Forms, and anyone looking to enhance their understanding of inter-language function linking.

CFDFEAGURU
Messages
781
Reaction score
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
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:

Similar threads

  • · Replies 15 ·
Replies
15
Views
8K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 133 ·
5
Replies
133
Views
13K
  • · Replies 14 ·
Replies
14
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 14 ·
Replies
14
Views
3K