DLL call returning Chinese string

 

Hi,

Code is simple

MQL



#import "ExpertAdvisor.dll"
 string What();
#import

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   Alert(What());
}


C# DLL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpertAdvisor.Chart;
using System.Runtime.InteropServices;

namespace ExpertAdvisor
{
    public class Order
    {
        [DllExport]
        public static string What()
        {
            return  "123444";
        }
    }
}


This is what the alert prints when running back test. 



What do I miss?

Best Regards,

Hendrik

 
MT5 strings are Unicode, seems your c# is returning an ANSI string.
 
Alain Verleyen:
MT5 strings are Unicode, seems your c# is returning an ANSI string.

Thanks.

Found the solution.

        [DllExport]
        [return: MarshalAs(UnmanagedType.LPWStr)]
        public static string What()
        {
            return  "123444";
        }
Reason: