Imported DLL function returns chinese characters (wrong encoding?)

 

I am trying to integrate TDLib in an EA to create a Telegram message reader expert.

I have built the TDLib library (Windows 10) and included it.

It seems to work, but the response seems different encoding and so I cannot interpret it and cannot figure out how/where to convert it.

mq5:

#import "tdjson.dll"
   int      td_create_client_id();
   void     td_json_client_create();
   string   td_receive (double timeout);
   void     td_send (int client_id, string request);
#import

int OnInit(){
   int client_id = td_create_client_id();
   Print("client_id: ", client_id);
   td_json_client_create();
   string request = "{\"@type\": \"getAuthorizationState\"}";
   td_send(client_id, request);
   double timeout = 100.0;
   string receive = td_receive(timeout);
   Print("receive: ", receive);
   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason){
}

void OnTick(){
}

output:

Any ideas?

 
Strings are 16 bits in MTx.
 
William Roeder #:
Strings are 16 bits in MTx.
Can you elaborate please? Any tip how to convert so I can read it?
 
Imre #:
Can you elaborate please? Any tip how to convert so I can read it?

Never mind. I resolved it.

Essentially, if the imported DLL function (written in C++) returns char* then you'll see the weird characters that I have seen.

I was lucky enough so that the C++ library I use is open source and I could modify the C++ source code and rebuild the DLL.

In C++ I changed the function to return  wchar_t* - this way the output in MQL5 is correct.

It'd be nice if there were more data types available in MQL5 or a way to convert the weird string.