Toute question d'un PROFI à un SUPER PROFI - 1. - page 16

 
alsu:
C'est peut-être idiot, mais... Avez-vous essayé d'ajouter HTTP:// à l'URL ?
non. http ne peut pas être ajouté.
 

continuent à se battre avec l'unicode.

Il a décollé, et maintenant au lieu d'une url invalide, c'est l'erreur 87 qui s'affiche. Et ceci est encore pire :)
Je l'ai trouvé dans WinHttpConnect. Que puis-je faire ? ou la fonction absi2unicode est-elle fausse ?


#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:

continuent à se battre avec l'unicode.

Il a décollé, et maintenant l'erreur 87 apparaît au lieu de la mauvaise url. Et ceci est encore pire :)
Je l'ai trouvé dans WinHttpConnect. Que puis-je faire ? ou la fonction absi2unicode est-elle fausse ?


Une archive contenant un document texte est jointe à ce message. Je ne sais pas si cela peut vous aider, mais jetez-y quand même un coup d'œil - c'est un petit document. Il y est question de l'encodage des polices russes, mais le contenu du document vous donnera peut-être une idée. Vous connaissez C++, contrairement à moi.
Dossiers :
hitrosti.rar  3 kb
 
Voyez comment cela se passe ici.
 
hrenfx:
Voyez comment cela se passe ici.
C'est fait via wininet.dll, donc je peux...
 
sergeev: ou la fonction absi2unicode est-elle erronée ?


semble avoir tort. Pouvez-vous le réécrire vous-même en MQL ?

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      }
 
Vous pouvez utiliser StringSetChar, sans l'int-array.
 
sergeev:

continuent à se battre avec l'unicode.

il a décollé, et maintenant, au lieu d'une url incorrecte, l'erreur 87 s'affiche. C'est encore pire :)
C'est apparu dans WinHttpConnect, bien sûr. Que puis-je faire ? ou la fonction absi2unicode est-elle incorrecte ?

Il est préférable d'utiliser les fonctions API standard pour la conversion.

Voici un exemple de 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:
C'est fait via wininet.dll, donc je peux...

Surveillez-la attentivement à partir de ce 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:

Regardez attentivement à partir de ce point :

This is due to the fact I know no clean way to cast strings
Cela signifie "J'ai fait via HttpSendRequestA car je ne sais pas comment convertir les chaînes ... à MQL"
Raison: