
Wed, 02/26/2025 - 05:28
Hello!
I'm having trouble with OCC version 7.8 with reading STEP files, specifically with reading folder paths with Japanese characters in them.
For example if I have the following C++ code snippet:
CString file = "C:\Users\jgregory\Desktop\新しいフォルダー\stepfile.stp"
Standard_CString FileName = (Standard_CString)(LPCTSTR)file;
STEPControl_Reader Reader;
IFSelect_ReturnStatus status = aReader.ReadFile(FileName);
If I run the above, then I always get the error code "IFSelect_RetError". However, if I run the above with a filepath with only english characters,
("C:\Users\jgregory\Desktop\test\stepfile.stp") then I never see this issue and the step file is opened properly. All of this is done on a Japanese Windows 10 machine.
Are there any ideas that I could try? I did not have this issue formerly with OCD 6.5.3 but only noticed that it happens with OCC 7.8
Any help would be appreciated, I've tried lots of things to no avail.
Wed, 02/26/2025 - 08:32
I suppose that
CString
is a class from MFC. In that case:Standard_CString
orTCollection_AsciiString
) or UTF-16 (TCollection_ExtendedString
). Make sure to implement a proper conversion between MFCCString
and OCCT strings - you may examine MFC sample coming with OCCT as a reference.L""
oru8""
). In general, it is better to avoid hard-coding Unicode string into C++ source code to avoid portability issues.Wed, 02/26/2025 - 19:45
Thank you for your assistance. When I try to convert the character set to use unicode in out mfc application, I get lots of compiler errors. To use MFC Unicode, I switched this setting "Character Set" to "Use Unicode Character Set".
Is there a workaround to still use MFC multibyte while also still being able to use the STEPControl_Reader with OCC 7.8?
Wed, 02/26/2025 - 20:24
Hello. If you are having trouble with path string, then you can use "iostream" to read by open stream instead.
But originally, UTF-8 must to be work without issues. You can use as a bridge TCollection_ExtendedString then create AsciiString. Or use constructor, which takes pointer and length.
Best regards, Dmitrii.
Wed, 02/26/2025 - 20:38
Hi,
you could try to convert CString to Unicode via MultiByteToWideChar and CP_ACP as codepage parameter to wchar_t.
Then create a TCollection_AsciiString as shown above:
TCollection_AsciiString aFileUtf8 ((const wchar_t* )theFile);
Greets,
Patrik
Wed, 02/26/2025 - 21:13
John gregory wrote:
You may convert string from locale codepage into UTF-8 using
NCollection_Utf8String
fromNCollection_UtfString.hxx
:Wed, 02/26/2025 - 08:35
OCCT 7.5.3 introduced handling of Unicode file paths in STEP reader (UTF-8 strings are expected since that).