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

 
Zhunko:

Looked at WinHttpConnect(). It has no implementation for multibyte encoding.

Can I use a DLL to shell and convert it?


No. I don't need it in a DLL. I know it's an option, but it's wrong...

wininet.dll, for example, all its functions work, but Winhttp has such a silly bug...

If you could call GetLastError from Kernel32, but mql4 is harmful and does not allow to make functions with identical names, even with different parameters...


By the way, have you tried to run this script on your machine? maybe it's just my problem ?

 
sergeev:

I understand that it's an option, but it's not the same...

For example, all its functions work with wininet.dll, but in Winhttp there is such a silly stall...

If you could call GetLastError from Kernel32, but mql4 is harmful and does not allow to make functions with identical names, even with different parameters...


By the way, have you tried to run this script on your machine? maybe it's just my problem ?

What if you insert an intermediate dll between GetLastError_2 and Kernel32? Wouldn't that work?
 
sergeev:

I understand that it's an option, but it doesn't work that way.

wininet.dll, for example, all its functions work, but Winhttp has such a stupid stoppage...

If you could call GetLastError from Kernel32, but mql4 is harmful and does not allow to make functions with identical names, even with different parameters...

GetLastError() should be called low-level --> RtlGetLastWin32Error(). Ilnur suggested it in his time. Here are some examples of how to use it.

WinHttpConnect() will not work in MQL4.

 
Zhunko:


Nothing will work with WinHttpConnect() in MQL4.

Why? Because of Unsigned integer?
 

You could try converting.

If I have time, I'll try to make an example. Otherwise... This C++ code should be converted to MQL4:

        bool MultiByte2Unicode(const std::string& mb, std::wstring& un, UINT CodePage)
        {
                DWORD wideSize = ::MultiByteToWideChar(CodePage, 0, (LPCSTR)mb.c_str(), -1, 0, 0);

                if(wideSize != 0)
                {
                        un.reserve(wideSize);
                        std::vector<TCHAR> result(wideSize, _T('\0'));

                        bool bSucceeded = (0 != ::MultiByteToWideChar(CodePage, 0, (LPCSTR)mb.c_str(), -1, &result[0], wideSize));
                        if (bSucceeded)
                        {
                                un = &result[0];
                        }

                        return bSucceeded;
                }

                return false;
        }
wstring should be replaced with an array of ints and this should be taken into account when recalculating the size.
 
TheXpert:

You could try converting.

If I have time, I'll try to make an example. Otherwise... This C++ code should be converted to MQL4:

The wstring needs to be replaced with an array of ints and take that into account when recalculating the size.

I've got it like this:

    inline std::wstring AnsiToUnicode(const std::string &sSourceA, // Строка для преобразования.
                                      const int         nCodePage) // Кодовая страница может быть одним из значений:
                                                                   //  CP_ACP         Системное умолчание Windows кодовых страниц ANSI.
                                                                          //  CP_OEMCP       Нынешняя система OEM кода страницы.
                                                                   //  CP_MACCP       Нынешняя система Macintosh код страницы.
                                                                   //  CP_SYMBOL      Символ кода страницы (42).
                                                                   //  CP_THREAD_ACP  Код Windows ANSI страницы для текущего потока. 
                                                                   //  CP_UTF7        UTF-7. Используйте это значение только тогда, когда вынужден от транспортного механизма 7-бит. Использование UTF-8 является предпочтительным.
     {                                                             //  CP_UTF8        UTF-8.
      int          nLength = 0;
      std::wstring sStringW = L"";
      if (sSourceA.size() == 0) return(sStringW);
      if ((nLength = ::MultiByteToWideChar(nCodePage, 0, sSourceA.c_str(), -1, NULL, 0)) == 0) throw(_T("Ошибка в функции \"Utils::StringSTL::AnsiToUnicode()\". В строке отсутствуют символы."));
      sStringW.resize(nLength - 1);
      if ((nLength = ::MultiByteToWideChar(nCodePage, 0, sSourceA.c_str(), -1, LPWSTR(sStringW.c_str()), nLength)) == 0) throw(_T("Ошибка в функции \"Utils::StringSTL::AnsiToUnicode()\". Строка не преобразована."));
      return(sStringW);
           }
 
Zhunko:

I have this:

EMNIP, the standard does not guarantee the location of the string in a continuous block of memory, so using the &sStringW[0] construct is fraught.

Basically the same eggs. But mine is 100% according to standard :)

 
TheXpert:

EMP, the standard does not guarantee string location in a contiguous memory block, so using &sStringW[0] construct is fraught with danger.

Same eggs in general. But mine is 100% according to standard :)

Didn't know...
 
Zhunko:
I didn't know...
Well, it seems that all (probably all) of the Microsoft implementations are OK with this, I can't vouch for the others.
 
TheXpert:
Well, it seems that all (probably all) of Microsoft's implementations are OK with this, I can't vouch for the others.
So far I haven't had any problems. I have corrected my code to the standard.