August 11, 2022, 05:14:34 AM


IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!

Problems with unicode strings

Started by sapero, May 31, 2007, 10:55:37 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


Hello, I have some small problems with unicode strings in Aurora.
Let say, i want to create a string with embedded quotes, like name.exe "%1"
If I do it in this way, it will be incorrect (syntax error):
wstring *pwsz = L"name.exe \"%1\""

2. escape characters.
- L"\\" produces two back-slashes.
- L"\aaaaa\aaaa" is working without warnings.
- L"\x00" isn't working as expected: '\',  'x' and '00' is added to string.
- no way to add small 'T' after '\', so  L"\\t" won't work.

3. alignment, the one with I spend much time to find a bug. When mixing multibyte and unicode strings, any api that uses unicode string can fail, if the string is not aligned on 2-byte boundary
string *s = "ab";
wstring *w = L".text";
RegOpenKetExW(HKEY_CLASSES_ROOT, w, ...) // will fail here

I have two fixes for this. extend the string s with extra NULL character: s = "ab\x00"; or insert a dummy string pointer before the unicode string:
string *s = "ab"; // 3 bytes in .data section
string *dummy = ""; // 1 byte in .data
wstring *w = L".text";
RegOpenKetExW(HKEY_CLASSES_ROOT, w, ...) // ok!

The second hack : redefine 'db' to 'dw' in assembly code, to force all strings to be WORD aligned:

sub this_is_last_sub_in_module()

#emit %define db dw

I know the parser uses "segment .data use32 align=4" but the last token is ignored, here is nothing aligned, maybe the first label is. I have also a extra macro to force all subroutines to be aligned on DWORD boundary:%macro .ef 0
align 4
Everytime a subroutine ends, here is a local '.ef' label that forces the next label to be propertly aligned.


I've found another problem in aurora rc1 parser.
Already finished converting fmod headers and started with examples. The first was 3d. Strange! The first api FMOD_System_Create crashes the app.
sub main()
    FMOD_SYSTEM     *system;
    result = FMOD_System_Create(&system);

The problem was (found in assembly output):
   push dword [__imp_system]
   call [__imp_FMOD_System_Create]

So instead pointer to local variable named 'system', a pointer to crt api system(char*) was passed. The include file was also included.
Problem solved - renamed variable system.

Ionic Wind Support Team

Because there is a SYSTEM command, which takes precedence.
Ionic Wind Support Team