MetaTrader 4 Client Terminal build 604 - page 5

 

I found problem with function ChartID();

After running EA for a longer time, this function returns ID of other probably first chart not current;

I use ChartSetSymbolPeriod() in this EA.

 
micclly:

StringToCharArray does not correctly convert Unicode string to ANSI string.

code:

result in DebugView:


Used DLL is attached.


From the above, ansiString2 is perfect converted by twice call of WideCharToMultiByte.

StringToCharArray may be buggy.

Not reproduced. Too complicate way to check your message

1. Use '\n' at the end of string output with OutputDebugString

2. Write converted string to binary file and see what is written

3. Try to make backward conversion CharArrayToString and print it

 
Hi, https://www.mql5.com/en/code/9358 this renkochart offline ea failed to run on build 600 and 603 after compile via build 600 and 603, it gets back to ok after compile via build 509.
 
It was replied here on your thread
 
stringo:

Not reproduced. Too complicate way to check your message

1. Use '\n' at the end of string output with OutputDebugString

2. Write converted string to binary file and see what is written

3. Try to make backward conversion CharArrayToString and print it



Thanks for response, I've tried that.


Tried code:

#property strict

#import "kernel32.dll"
    int lstrlenA(const char& ansiString[]);
    void OutputDebugStringA(char& str[]);
    void OutputDebugStringW(string str);
#import

#import "UnicodeString.dll"
    int getAnsiStringLength(const string unicodeString);
    int convertUnicodeToAnsi(const string unicodeString, char& ansiString[], int ansiLength);
#import

void appendLFtoAnsiString(const uchar& org[], uchar& dst[])
{
    int orgLength = lstrlenA(org);

    ArrayResize(dst, orgLength + 1 + 1);
    ArrayCopy(dst, org, 0, 0, orgLength);
    dst[orgLength + 0] = (uchar)0x0a;
    dst[orgLength + 1] = (uchar)0x00;
}

void OnStart()
{
    // Russian string
    string unicodeString = "Здравствуйте, меня зовут Ольга. Я живу во Владивостоке.";

    string acpBinaryFilename = "acp.txt";
    string unicodeBinaryFilename = "unicode.txt";

    int acpBinaryHandle = FileOpen(acpBinaryFilename, FILE_WRITE|FILE_BIN);
    if (acpBinaryHandle == INVALID_HANDLE) {
        Alert("ACP binary file cannot be opened. error=" + IntegerToString(GetLastError()));
        return;
    }

    int unicodeBinaryHandle = FileOpen(unicodeBinaryFilename, FILE_WRITE|FILE_BIN);
    if (unicodeBinaryHandle == INVALID_HANDLE) {
        Alert("Unicode binary file cannot be opened. error=" + IntegerToString(GetLastError()));
        return;
    }    

    // Unicode to ANSI Method 1: Convert Unicode string to ANSI string by StringToCharArray
    uchar ansiString1[];
    StringToCharArray(unicodeString, ansiString1);

    OutputDebugStringW("***** ansiString1:\n");
    //OutputDebugStringA(ansiString1);

    uchar ansiString1WithLF[];
    appendLFtoAnsiString(ansiString1, ansiString1WithLF); 

    OutputDebugStringA(ansiString1WithLF);
    FileWriteArray(acpBinaryHandle, ansiString1WithLF);

    // Unicode to ANSI Method 2: Convert Unicode string to ANSI string by WideCharToMultiByte in DLL
    int ansiLength2 = getAnsiStringLength(unicodeString);
    uchar ansiString2[];
    ArrayResize(ansiString2, ansiLength2);
    convertUnicodeToAnsi(unicodeString, ansiString2, ansiLength2);

    OutputDebugStringW("***** ansiString2:\n");
    //OutputDebugStringA(ansiString2);

    uchar ansiString2WithLF[];
    appendLFtoAnsiString(ansiString2, ansiString2WithLF); 

    OutputDebugStringA(ansiString2WithLF);
    FileWriteArray(acpBinaryHandle, ansiString2WithLF);

    // Backward 1; convert ansiString1 back to Unicode
    string unicodeString1 = CharArrayToString(ansiString1);
    OutputDebugStringW("***** unicodeString1:\n");
    OutputDebugStringW(unicodeString1 + "\n");
    
    ushort unicodeString1Array[];
    StringToShortArray(unicodeString1 + "\n", unicodeString1Array);
    FileWriteArray(unicodeBinaryHandle, unicodeString1Array);

    // Backward 2; convert ansiString2 back to Unicode
    string unicodeString2 = CharArrayToString(ansiString2);
    OutputDebugStringW("***** unicodeString2:\n");
    OutputDebugStringW(unicodeString2 + "\n");

    ushort unicodeString2Array[];
    StringToShortArray(unicodeString2 + "\n", unicodeString2Array);
    FileWriteArray(unicodeBinaryHandle, unicodeString2Array);

    FileFlush(acpBinaryHandle);
    FileClose(acpBinaryHandle);
    FileFlush(unicodeBinaryHandle);
    FileClose(unicodeBinaryHandle);
}

Result is in image:


Log files (and source code) is attached.


EDIT: My computer locale is CP932, so acp.txt contains CP932(Shift_JIS) encoding string.

Files:
 
micclly:

Thanks for response, I've tried that.


Tried code:

Result is in image:


Log files (and source code) is attached.


EDIT: My computer locale is CP932, so acp.txt contains CP932(Shift_JIS) encoding string.


Ok. We changed CharArrayToString and StringToCharArray.

Please try conversions with your CodePage in the file functions. I suspect we need make the same changes

 
stringo:

Ok. We changed CharArrayToString and StringToCharArray.

Please try conversions with your CodePage in the file functions. I suspect we need make the same changes


Ok, what codepage should I convert it to?

I think you requested the "binary" output of StringToCharArray, so I did it.

I can convert it to any codepage, but it'll be different from "binary", won't it?

 
micclly:

Ok, what codepage should I convert it to?

I think you requested the "binary" output of StringToCharArray, so I did it.

I can convert it to any codepage, but it'll be different from "binary", won't it?

There are specifical MultiByte from 1 to 4 bytes for 1 character - for example yours. Russian MultiByte is simple - 1 byte for 1 character always.

Try to write string to the file opened with FILE_ANSI flag. Then read string from this file.

Just use file functions instead of StringToCharArray and CharArrayToString

 
stringo:

There are specifical MultiByte from 1 to 4 bytes for 1 character - for example yours. Russian MultiByte is simple - 1 byte for 1 character always.

Try to write string to the file opened with FILE_ANSI flag. Then read string from this file.

Just use file functions instead of StringToCharArray and CharArrayToString




Mmm, I'm confusing the purpose of that. You'd previously requested me as:

stringo:

1. Use '\n' at the end of string output with OutputDebugString

2. Write converted string to binary file and see what is written

3. Try to make backward conversion CharArrayToString and print it

I had believed that you need materials to investigate the problem.

Now, you respond me that "write string to the file opened with FILE_ANSI flag. Then read string from this file".

You mean this is the solution for this problem? or way to get the materials to investigate the problem?

 
micclly:
You mean this is the solution for this problem? or way to get the materials to investigate the problem?

No solution. Possible bug.

Way to get suspictions. And you can check it quickly now and after new build release. We'll check it too. but 2 checkers better than 1

PS We just need your answer. Is there bug in the file functions or not

Reason: