Download MetaTrader 5
To add comments, please log in or register
Have you developed a profitable strategy? Share it with millions of traders via Signals!
qjol
3243
qjol 2014.07.17 04:42  
try the service desk
FXEZ
14
FXEZ 2014.07.17 17:06  

Make sure (within the DLL) that you marshall the string specifically. Build 600+ broke a lot of DLLs that pass strings. Your MQL4 code may not change at all from the original, but the DLL code will need to specifically marshall the strings as the correct type.

 In .NET this can be done as:

[MarshalAs(UnmanagedType.LPWStr)] 

 something like this for C#:

  [return: MarshalAs(UnmanagedType.LPWStr)]  

 string GV_GetNamedString([MarshalAs(UnmanagedType.LPWStr)] string StrName, [MarshalAs(UnmanagedType.LPWStr)] string Error);

 See this code for more complete examples in C# and the other side in MQL4:

http://vb6-to-csharp.blogspot.com/2014/05/code-to-export-c-dll-to-metatrader.html 

 Also, see this topic:

https://forum.mql4.com/60905 

Kashif Javed
826
Kashif Javed 2014.07.20 03:53  
FXEZ:

Make sure (within the DLL) that you marshall the string specifically. Build 600+ broke a lot of DLLs that pass strings. Your MQL4 code may not change at all from the original, but the DLL code will need to specifically marshall the strings as the correct type.

 In .NET this can be done as:

[MarshalAs(UnmanagedType.LPWStr)] 

 something like this for C#:

  [return: MarshalAs(UnmanagedType.LPWStr)]  

 string GV_GetNamedString([MarshalAs(UnmanagedType.LPWStr)] string StrName, [MarshalAs(UnmanagedType.LPWStr)] string Error);

 See this code for more complete examples in C# and the other side in MQL4:

http://vb6-to-csharp.blogspot.com/2014/05/code-to-export-c-dll-to-metatrader.html 

 Also, see this topic:

https://forum.mql4.com/60905 

Thanks, its an old DLL file for which I dont have code so I cannot change any code in DLL.
whroeder1
13947
whroeder1 2014.07.20 11:26  
kjaved8: its an old DLL file for which I dont have code so I cannot change any code in DLL.
  1. Then you'll have to ask the owner of the DLL to modify it for you
  2. Or, create a new DLL as a shim.
qjol
3243
qjol 2014.07.20 15:27  
try version 2.3 maybe it suits your needs (didn't checked)
Hongliang Liu
1203
Hongliang Liu 2014.07.21 07:01  
kjaved8:

Following code works fine in old builds but not in 600+ builds. In new builds it only passes and get back first letter of the strings. Any one here to tell how to fix this for new builds??

i have wrote a dll which could pass string to mq4(Version 670),you could have a try like the following in your dll:

dll: 

wchar_t* GV_GetNamedString(wchar_t* StrName, wchar_t* Error); 

 

import in mq4 as you do:

string GV_GetNamedString(string StrName, string Error); 

Halley
198
Halley 2014.07.21 16:35  
Moggy:

i have wrote a dll which could pass string to mq4(Version 670),you could have a try like the following in your dll:

dll: 

wchar_t* GV_GetNamedString(wchar_t* StrName, wchar_t* Error); 

 

import in mq4 as you do:

string GV_GetNamedString(string StrName, string Error); 

 


Is it a memory-safe way to avoid leaks? I am not a DLL expert, I just wonder if the string created in the DLL gets properly disposed.
/ /12
To add comments, please log in or register