Calling C++ DLL by pushing a button in C# GUI -
I have a DLL with the following C ++ export function:
extern "C "__declspec (dllexport) Zero * OPS_FDD (constant four * char_Address, constant integer int_NumChann, constant integer int_SamplingFreq) {FDD * FDD_Ptr_Object = zero; If (FDD_Ptr_Object == zero) {// if the condition to avoid memory leakage FDD_Ptr_Object = new FDD (char_Address, int_NumChann, int_SamplingFreq); } (FDD_Ptr_Object == zero) {// if throw "FDD object indicator can be allocated to memory: can not be done"; // __declspec can not throw in (dllexport) marked deportation 'C' std :: court & lt; & Lt; "Error: Allocate memory to FDD object pointer:" & lt; & Lt; '\ N'; System ("pause"); } FDD_Ptr_Object; // De-lock the pointer to be removed; FDD_Ptr_Object = NULL to avoid memory leak; // Set the indicator for NULL return; } Now I want to call this DLL by pressing the button in my C # GUI. To add the code to the code, what are the lines of code written in the following lines? By the way, my DLL name is using the name "FDD_DLL"
; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Linq; Using System.Text; Using System.Windows.Forms; Name Location Call DLL {Public Partial Class} Form 1: Form {Public Form 1 () {Initial Group (); } Private Zero Button 1_Click (Object Sender, EventArgse E) {// How to call lines of code by pressing the C # GUI button to call my C ++ DLL // ??? // by the way "itemprop =" text "> You can use the P / P / Invoke, would like to use something like this: [DllImport ("FDD.DLL")] Private Static Execution IntPtr OPS_FDD ([MarshallAs (UnmanagedType.LPStr)] String char_Address, Int int_NumChann , Int int_SamplingFreq);
You can call more or less like any other method. Now this is how you declare a split, it all depends on what the various logic is. For example, in this case, char_Address can be passed in many ways to C ++ DLL - there are several different ways to represent the string, if it means to be a string , So it is. The MarshalsS attribute is used to specify what you want. Without my knowledge this is my best guess. More information is available.
Comments
Post a Comment