http response become unreadable codes on mt4 version 4.00 buid 646

 
Hey guys

I use a dll to request a url and receive response, it works when I didn't  update mt4 version,

 when I update it to buid 646, I always get unreadable codes from http response. 
can someone take a look at it? 
if the code is ok, should I use other compile tools? 
thank you very much!
source code:
#include <iostream>
#include <string>
#include <curl/curl.h>

using namespace std;

string contents;

CURL* curl;

size_t handle_data(void *ptr, size_t size, size_t nmemb, void *stream){

    int numbytes = size*nmemb;
    // The data is not null-terminated, so get the last character, and replace
    // it with '\0'.
    char lastchar = *((char *) ptr + numbytes - 1);
    *((char *) ptr + numbytes - 1) = '\0';
    contents.append((char *)ptr);
    contents.append(1,lastchar);
    *((char *) ptr + numbytes - 1) = lastchar;  // Might not be necessary.
    return size*nmemb;
}

extern "C" __declspec(dllexport) const char*  Hello(char* say){

        contents = "";
        const char* err = "ERR";
        //string url =  string(say) + ".com";
        string url =  "http://127.0.0.1/index.php?" + string(say);
        
        if(NULL == curl){
                curl = curl_easy_init();
                // Tell libcurl what function to call when it has data
                curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,handle_data);
        }
    if(curl){
                // Tell libcurl the URL
                curl_easy_setopt(curl,CURLOPT_URL, url.c_str());
                // Do it!
                CURLcode res = curl_easy_perform(curl);
                //curl_easy_cleanup(curl);
                if (res == 0){
                        return contents.c_str();
                }
    }
        curl = NULL;
        return err;
}

int main(void)
{
        return 0;
}
 
I am using gcc to compile this file now.
 
MetaQuotes has implemented something so that only authorized url can be communicated by ea.
 
deysmacro:
MetaQuotes has implemented something so that only authorized url can be communicated by ea.

thank you for your reply, but where can I find the explanation about this rule , because of political reason I can't use google in recent days in china.     
 
deysmacro:
MetaQuotes has implemented something so that only authorized url can be communicated by ea.

Don't think so. The Hello() function is returning Ansi text (char*) when it needs to be returning Unicode. It looks as though king63499 has just upgraded to build 646 from build <= 509. In other words, it's another of the same questions which was asked 100000 times back in February when build 600 was released.

(And my understanding is that the "authorized URL" only applies if you use the new built-in WebRequest. It doesn't apply if you continue to use any of the old DLL-based method for reading URLs. The point of WebRequest is that you can now write EAs and indicators which read data from the web still satisfying the no-DLLs rule for listing in the Market.)

 
king63499:

thank you for your reply, but where can I find the explanation about this rule , because of political reason I can't use google in recent days in china.     

The issue is that on MT4 build >= 600 you cannot return Ansi text (char*) from a DLL. You need to modify your code to return Unicode text - or you need to do some relatively complex manipulation on the Ansi text in order to make it usable.

For example, see https://www.mql5.com/en/forum/149412 

 
gchrmt4:

The issue is that on MT4 build >= 600 you cannot return Ansi text (char*) from a DLL. You need to modify your code to return Unicode text - or you need to do some relatively complex manipulation on the Ansi text in order to make it usable.

For example, see https://www.mql5.com/en/forum/149412 


Hey gchrmt4

I have resolved the problem according to  your explanation. the dll is working again. Very very  thank you for your help!!

best wishes to you!