I see a problem when call function from dll file which compiled in C++, dll file with functions code as follow:
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <string.h>
char* str;
int _stdcall inputt(char* str_)
{
str=str_;
return 1;
}
int _stdcall Shooow()
{
MessageBoxA(NULL,str,"Message...",MB_OK);
return 0;
}
In this, I export two function inputt() and Shooow(). Dll file named "TestCCCC.dll". Then I call them in C# code as follow:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
namespace muWrapper
{
public partial class WndSample : Form
{
[DllImport("TestCCCC.dll")]
private static extern int inputt(string FuncName);
[DllImport("TestCCCC.dll")]
private static extern int Shooow();
public WndSample()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int ret = inputt("aaaaaa");
ret = Shooow();
}
}
}
When I run it, click the button with the first time, it show a message box with strange characters, not "aaaaaa" !!!? Continue to click with the second time, it show truly with "aaaaaa", and continue...and show truly and truly....
Tell me what was happen in this problem? How to code two function inputt() and Shooow() to show truly at the first time? Thanks.
What I have tried:
I try and try to think about this but not success !