Download MetaTrader 5

C# dll returns numbers instead of string (unmanaged exports)

To add comments, please log in or register
Do you want to learn MQL5? 300 articles will help you!
Rosen Marinchev
139
Rosen Marinchev 2014.06.30 10:44 

I have the following C# function:

 

[DllExport("Call", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.LPWStr)]
        public static string Call(
            [MarshalAs(UnmanagedType.LPWStr)]string parameters
            , [MarshalAs(UnmanagedType.LPWStr)]string host)
        {
            try
            {
		string resultValue = "some string";
                return resultValue;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

The requests are executed correctly, however the response is always a number like this: '91801944'

If I put a message box inside the dll, I can see that the returned string is accurate and displayed correctly. Somehow the string is being converted to numbers while it is passed as return value to mt4 platform. Do you have any idea how I can fix this issue ? 

qjol
3243
qjol 2014.06.30 10:59  
show the relevant MQL code please
Rosen Marinchev
139
Rosen Marinchev 2014.06.30 12:46  
#import "SST.dll"
   int Call(string, string);
#import

string strRet = Call("EURUSD;0;0;1", "somehostvalue");
Print(strRet);
Alain Verleyen
Moderator
30731
Alain Verleyen 2014.07.01 13:50  
moreevilthanyou:

   int Call(string, string);
FXEZ
14
FXEZ 2014.07.16 13:23  
moreevilthanyou:

The return type from your function "Call" is a string, not an int! See this:

#import "SST.dll"

   string Call(string parameters, string host);

#import

To add comments, please log in or register