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.
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
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.
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?
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:
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?
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
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.
12547
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
113708
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:
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.
12547
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
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?
12547
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
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:
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?
12547
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