I am trying to output text from a C++ function to a textbox in WPF, but when I click the button it outputs nothing. In the C# Console it worked.
Here the code from the C# console:
namespace ConsoleApp1
{
class Program
{
const string dllfile = "C:\\...";
[DllImport(dllfile, EntryPoint = "main", CallingConvention = CallingConvention.Cdecl)]
private static extern string text_output();
static void Main(string[] args)
{
text_output();
}
}
}
Here the code from the C++ DLL:
using namespace std;
void text_output();
void text_output()
{
cout << "something" << endl;
}
extern "C" __declspec(dllexport) int main()
{
text_output();
return 0;
}
Here the code from the C# WPF page:
namespace application
{
public partial class Page1 : Page
{
const string dllfile = "C:\\...";
[DllImport(dllfile, EntryPoint = "main", CallingConvention = CallingConvention.Cdecl)]
private static extern string text_output();
public Page1()
{
InitializeComponent();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
txtBox.Text += text_output();
}
}
}
What do I have to do so that the text from the text_output() function is output to the textbox when I click the button?