How to return a Wide string from c to harbour

133 views
Skip to first unread message

Reinaldo Crespo

unread,
May 24, 2023, 5:59:47 PM5/24/23
to Harbour Developers
Hello.

I'm not reporting a bug.  

I write here because I have not found an answer on the harbour's users group.   I'm looking to return a wchar_t variable type from c to Harbour.   I typically use hb_retc to return strings but here I want to return a wchar_t so hb_retc won't work.

I found an answer on the fivewin forum but it is specific to windows.  I suppose I could imitate what the fivewin function does with generic c, but I'm hoping Harbour developers have already solved that and there is no need to write my own.

Is there a vm function to return a wchar_t?

Thank you.


Lailton Fernando Mariano

unread,
May 24, 2023, 7:17:57 PM5/24/23
to Harbour Developers
Try something like:

#include <hbapi.h>
#include <wchar.h>

HB_FUNC( HB_TEST_WCHAR ) {
wchar_t my_wchar[] = L"Hello, World!";
int length = wcslen(my_wchar);
char * buffer = (char*) hb_xgrab( length + 1 * sizeof(wchar_t) );
if (buffer != NULL) {
wcstombs(buffer, my_wchar, length + 1);
hb_retc( buffer );
hb_xfree( buffer );
} else {
hb_retc_null();
}
}

Reinaldo Crespo

unread,
May 25, 2023, 2:06:44 AM5/25/23
to harbou...@googlegroups.com
Got it.  Yes.  wcstombs works.   Thank you, Laiton.

BTW— are you interested on creating an implementation of FastReports for Harbour?  Something like what Sergi Spirin had with FRH?

I think we need this in the harbour community.

Reinaldo Crespo-Bazán



--
You received this message because you are subscribed to a topic in the Google Groups "Harbour Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/harbour-devel/SHZB3nkCqJk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to harbour-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-devel/e5f68aa0-eefc-4280-904a-46e89a9dec33n%40googlegroups.com.

Przemyslaw Czerpak

unread,
May 25, 2023, 3:28:20 AM5/25/23
to harbou...@googlegroups.com

Hi,

    hb_retstr_u16( HB_CDP_ENDIAN_NATIVE, wstr );

best regards,
Przemek

W dniu 24.05.2023 o 23:59, Reinaldo Crespo pisze:
--
You received this message because you are subscribed to the Google Groups "Harbour Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-devel/b453800a-65c8-4745-8c6b-a9ffc0041d58n%40googlegroups.com.


Reinaldo Crespo

unread,
May 27, 2023, 2:54:49 AM5/27/23
to Harbour Developers
It was exactly what I was looking for and it works great!

Thank you.

Reply all
Reply to author
Forward
0 new messages