News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

wcslen on MinGW-w64

Started by dimmed, June 28, 2025, 05:56:18 AM

Previous topic - Next topic

dimmed

I'm the groggily user on Github. I tried to use a library named libutf in the past:

https://github.com/holepunchto/libutf/issues/1

https://github.com/holepunchto/libutf/issues/2

The developer was not easy to work with. In the end the thread closed without anything settled.

I still think I was right about wcslen on MinGW-w64.

Vortex

#1
Hi dimmed,

Could you be more specific as your question is not directly related to Pelles C ?
Code it... That's all...

TimoVJL

#2
#include <stdio.h>
#include <wchar.h>

int main(void)
{
    const char* str = "\x41\x00\xa9\x03\x03\x26\x2d\x4e\x3d\xd8\x02\xde";
    printf("wcslen(str) = %zu\n", wcslen((wchar_t*)str));
    return 0;
}

x86
wcslen(str) = 15x64
wcslen(str) = 9
This version using -Ze gives 6 in both cases
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <wchar.h>

#pragma comment(lib, "user32.lib")

int main(void)
{
    const char* str = "\x41\x00\xa9\x03\x03\x26\x2d\x4e\x3d\xd8\x02\xde";
    printf("wcslen(str) = %zu\n", wcslen((wchar_t*)str));
MessageBoxW(0, (wchar_t*)str, L"test", MB_OK);
    return 0;
}
May the source be with you

Pelle

When using:
wcslen((wchar_t*)str))
at the very least, make sure str is a properly terminated wide string (ignoring all other problems with this approach for now).

Append one (or two) '\0' to str, like so:
const char* str = "\x41\x00\xa9\x03\x03\x26\x2d\x4e\x3d\xd8\x02\xde\0";
/Pelle

Vortex

Hi dimmed,

Any chance to learn why specifically you selected this string?
Code it... That's all...