Download MetaTrader 5
To add comments, please log in or register
One billion tasks have already been executed with MQL5 Cloud Network. Test trading robots even faster!
king63499
15
king63499 2014.06.02 16:13 
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;
}
king63499
15
king63499 2014.06.02 16:25  
I am using gcc to compile this file now.
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.06.03 00:54  
MetaQuotes has implemented something so that only authorized url can be communicated by ea.
king63499
15
king63499 2014.06.03 12:09  
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.     
gchrmt4
356
gchrmt4 2014.06.03 14:27  
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.)

gchrmt4
356
gchrmt4 2014.06.03 14:33  
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 

king63499
15
king63499 2014.06.04 13:37  
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!

/
To add comments, please log in or register