Passing a string to a DLL Function

 

Hey all,


maybe you could help me solving this problem. I have create a simple DLL, like as described here:

https://www.mql5.com/de/articles/18


The DLL work when i use as parameter a Integer but when i switch to string, MT5 come up with the message, he couldn't find the method:

2017.11.18 11:24:35.507    Test(EURUSD,M1)    Cannot find 'testWchar_Ref' in 'Test\variableTest.dll'


This is my import in MT5:

#import "Test\variableTest.dll"
   void testInt_Ref   (int    &intTest_ref);
   void testWchar_Ref (string &wchar_tTest_Ref);
#import  



Implementation in MT5:

   string stringTest = "Hallo you...";  
   int    myInt = 0;
   
   testInt_Ref(myInt);
   Print("New INT: ", myInt );
   
   Print("PRE: " + stringTest);
   testWchar_Ref(u_stringTest);
   Print("POST: " + stringTest);


Export in DLL:

#ifdef VARIABLETEST_EXPORTS  
#define QVAR_API __declspec(dllexport)   
#else  
#define QVAR_API __declspec(dllimport)   
#endif

extern QVAR_API void testInt_Ref(int &intTest_ref);
extern QVAR_API void testWchar_Ref(wchar_t &wchar_tTest_Ptr);



DLL Function:

// Include header files
#include "stdafx.h"

using namespace std;

// add new INT value
void testInt_Ref(int &intTest_ref) {
    intTest_ref = 222;
}

// add new WCHAR_T value
void testWchar_Ref(wchar_t &wchar_tTest) {

    wchar_t *msg = L"This is cool.....";
    wchar_t *wchar_tTest_Ref = &wchar_tTest;

    //--- replace it
    memcpy(wchar_tTest_Ref, msg, wcslen(msg) * sizeof(wchar_t));
}



Result:

2017.11.18 11:24:35.507    Test(EURUSD,M1)    New INT: 222
2017.11.18 11:24:35.507    Test(EURUSD,M1)    PRE: Hallo you...
2017.11.18 11:24:35.507    Test(EURUSD,M1)    Cannot find 'testWchar_Ref' in 'Test\variableTest.dll'
2017.11.18 11:24:35.507    Test(EURUSD,M1)    unresolved import function call



it's compiled correctly. In my c++ Testprogram it works. Even when i leave the DLL Method empty it appears. It must be the parameter.


How can i pass a string to a DLL, modify it and use it back in MT5 ?


Thanks in Advanced
Datenaustausch: Erstellen einer DLL für MQL5 in 10 Minuten
Datenaustausch: Erstellen einer DLL für MQL5 in 10 Minuten
  • 2016.02.11
  • MetaQuotes
  • www.mql5.com
Tatsächlich erinnern sich nicht viele Entwickler daran, wie eine simple DLL-Bibliothek geschrieben wird und was die Merkmale der unterschiedlichen Systemanbindungen sind. Anhand mehrerer Beispiele werde ich versuchen, Ihnen den gesamten Prozess zur Erstellung einer simplen DLL in 10 Minuten zu zeigen, sowie einige technische Einzelheiten der...
 

In your C function you pass a reference to a char (1 character), but in your metatrader code, you pass a reference to a string (an array of characters).