Any questions from a PROFI to a SUPER PROFI - 1. - page 16

 
alsu:
This might be silly, but... Have you tried adding HTTP:// to the URL?
no. http cannot be added.
 

continue to struggle with unicode.

It got off the ground, and now error 87 is showing up instead of the wrong url. And this is even worse :)
Got it in WinHttpConnect. What can I fix? Or is absi2unicode function wrong?


#import "Winhttp.dll"
        int WinHttpOpen(string pwszUserAgent, int dwAccessType, 
                                                 string pwszProxyName, string pwszProxyBypass, int dwFlags);
        int WinHttpConnect(int hSession, /*string*/ int& pswzServerName[], int nServerPort, int dwReserved);
#import "ntdll.dll"
   int RtlGetLastWin32Error();
   int RtlSetLastWin32Error(int dwErrCode);
#import

start()
{
        int hSession=WinHttpOpen("MqlHttp", 0, "", "", 0);
        Print("hSession="+hSession);
        
        string aHost="www.mql4.com";

        RtlSetLastWin32Error(0); //сбрасываем последний код ошибки
        int wHost[100]; int n=ansi2unicode(aHost, wHost);
        int hConnect=WinHttpConnect(hSession, wHost, 80, 0);
        if (hConnect<=0) Print("-Err create Connect "+RtlGetLastWin32Error());
}

// функция преобразования строки в массив
//---------------------------------------------------------------   ansi2unicode
int ansi2unicode(string str, int &arr[])
{
        int max=ArraySize(arr); int pos=0, i=0, x;
        bool f=false;
        for (x=0; i<max; f=!f, pos++) // пока есть место в массиве
        {
                int c=StringGetChar(str, pos); if (c==0) break; // конец строки
                if (!f) x=c; else { i++; arr[i]=x+(c<<16); } // собираем символы в пары и складываем в массив
        }
        if (i>=max) { x=0; i=max-1; } else if(!f) x=0; // терминирующий ноль
        i++; arr[i]=x;
        return(i);
}
 
sergeev:

continue to struggle with unicode.

It got off the ground, and now instead of an invalid url, error 87 is showing up. And this is even worse :)
Got it in WinHttpConnect. What can I fix? Or is absi2unicode function wrong?


Attached to this post is an archive with a text document. I don't know if it helps you in any way, but take a look anyway - it's a small document. It does talk about encoding of Russian fonts, but maybe the content of the document will give you some idea. You know C++, unlike me.
Files:
hitrosti.rar  3 kb
 
See how it's done here.
 
hrenfx:
See how it's done here.
It's done via wininet.dll, so I can...
 
sergeev: or is the absi2unicode function wrong ?


seems to be wrong. Can you rewrite it in MQL yourself?

01      function cp1251_to_utf8 ($txt)  {
02          $in_arr = array (
03              chr(208), chr(192), chr(193), chr(194),
04              chr(195), chr(196), chr(197), chr(168),
05              chr(198), chr(199), chr(200), chr(201),
06              chr(202), chr(203), chr(204), chr(205),
07              chr(206), chr(207), chr(209), chr(210),
08              chr(211), chr(212), chr(213), chr(214),
09              chr(215), chr(216), chr(217), chr(218),
10              chr(219), chr(220), chr(221), chr(222),
11              chr(223), chr(224), chr(225), chr(226),
12              chr(227), chr(228), chr(229), chr(184),
13              chr(230), chr(231), chr(232), chr(233),
14              chr(234), chr(235), chr(236), chr(237),
15              chr(238), chr(239), chr(240), chr(241),
16              chr(242), chr(243), chr(244), chr(245),
17              chr(246), chr(247), chr(248), chr(249),
18              chr(250), chr(251), chr(252), chr(253),
19              chr(254), chr(255)
20          );  
21       
22          $out_arr = array (
23              chr(208).chr(160), chr(208).chr(144), chr(208).chr(145),
24              chr(208).chr(146), chr(208).chr(147), chr(208).chr(148),
25              chr(208).chr(149), chr(208).chr(129), chr(208).chr(150),
26              chr(208).chr(151), chr(208).chr(152), chr(208).chr(153),
27              chr(208).chr(154), chr(208).chr(155), chr(208).chr(156),
28              chr(208).chr(157), chr(208).chr(158), chr(208).chr(159),
29              chr(208).chr(161), chr(208).chr(162), chr(208).chr(163),
30              chr(208).chr(164), chr(208).chr(165), chr(208).chr(166),
31              chr(208).chr(167), chr(208).chr(168), chr(208).chr(169),
32              chr(208).chr(170), chr(208).chr(171), chr(208).chr(172),
33              chr(208).chr(173), chr(208).chr(174), chr(208).chr(175),
34              chr(208).chr(176), chr(208).chr(177), chr(208).chr(178),
35              chr(208).chr(179), chr(208).chr(180), chr(208).chr(181),
36              chr(209).chr(145), chr(208).chr(182), chr(208).chr(183),
37              chr(208).chr(184), chr(208).chr(185), chr(208).chr(186),
38              chr(208).chr(187), chr(208).chr(188), chr(208).chr(189),
39              chr(208).chr(190), chr(208).chr(191), chr(209).chr(128),
40              chr(209).chr(129), chr(209).chr(130), chr(209).chr(131),
41              chr(209).chr(132), chr(209).chr(133), chr(209).chr(134),
42              chr(209).chr(135), chr(209).chr(136), chr(209).chr(137),
43              chr(209).chr(138), chr(209).chr(139), chr(209).chr(140),
44              chr(209).chr(141), chr(209).chr(142), chr(209).chr(143)
45          );  
46       
47          $txt = str_replace($in_arr,$out_arr,$txt);
48          return $txt;
49      }
 
You can use StringSetChar, without the int-array.
 
sergeev:

continue to struggle with unicode.

it got off the ground, and now instead of the wrong url, error 87 pops up. This is even worse :)
Came up in WinHttpConnect, of course. What can I fix? Or is absi2unicode function wrong ?

It's better to use standard API functions for conversion.

Here's a sample code:

#import "kernel32.dll"
   int MultiByteToWideChar(int CodePage, int dwFlags, string lpMultiByteStr, int cbMultiByte, int& lpWideCharStr[], int cchWideChar);
#import "Winhttp.dll"
   int WinHttpOpen(int pwszUserAgent[], int dwAccessType, string pwszProxyName, string pwszProxyBypass, int dwFlags);
   int WinHttpConnect(int hSession, int pswzServerName[], int nServerPort, int dwReserved);
   int WinHttpCloseHandle(int hInternet);
#import

void start()
{
   int lpWideCharStr[];
   
   L("MqlHttp", lpWideCharStr);
   int hInternet = WinHttpOpen(lpWideCharStr, 0, "", "", 0);
   
   if (hInternet > 0)
   {
      L("www.mql4.com", lpWideCharStr);
      int hConnect = WinHttpConnect(hInternet, lpWideCharStr, 80, 0);
      
      if (hConnect > 0)
      {
         
         WinHttpCloseHandle(hConnect);
      }
      
      WinHttpCloseHandle(hInternet);
   }
}


int L(string lpMultiByteStr, int& lpWideCharStr[])
{
   int cchWideChar = MultiByteToWideChar(0, 0, lpMultiByteStr, -1, lpWideCharStr, 0);
   
   ArrayResize(lpWideCharStr, 1 + cchWideChar / 2);
   
   MultiByteToWideChar(0, 0, lpMultiByteStr, -1, lpWideCharStr, cchWideChar);
   
   return (cchWideChar);
}
 
alsu:
It's done via wininet.dll, so I can...

Watch it carefully from this point:

// Re-reads saved POST data byte-to-byte from file in the pseudo-character array
//  we need to send with HttpSendRequestA. This is due to the fact I know no clean
//  way to cast strings _plus_ binary file contents to a character array in MQL.
//  If you know how to do it properly feel free to contact me. 
 
hrenfx:

Watch carefully there from this point:

This is due to the fact I know no clean way to cast strings
It means "I did via HttpSendRequestA as I don't know how to convert strings ... to MQL"