Page 1 of 1

returning a wchar_t variable back to harbour function

PostPosted: Wed May 24, 2023 12:08 am
by reinaldocrespo
Hello everyone!

Inside a harbour wrapper function I need to declared a variable as wchar_t or HB_WCHAR but I don't know how to return that variable back to calling harbour function. I tried using hb_retc as with any other string but that won't return wide strings. Is there another vm return function I can use to return HB_WCHAR variables?

Thank you,

Reinaldo.

Re: returning a wchar_t variable back to harbour function

PostPosted: Wed May 24, 2023 3:19 am
by nageswaragunupudi
This is how FWH returns Wide Strings.

Code: Select all  Expand view
//also include
#include <fwh.h>  // fwh\include folder
//
LPWSTR cWideStr;
//
//
fw_retWide( cWideStr );
//
 

Re: returning a wchar_t variable back to harbour function

PostPosted: Wed May 24, 2023 12:17 pm
by reinaldocrespo
Hello Mr. Rao and everyone else;

Your information is valuable to me but this is a different situation.

I'm sorry I should have been more specific. I'm trying to return a c wchar_t variable type from a VM Harbour wrapper c function back to the calling Harbour (clipper) code.

Code: Select all  Expand view

HB_FUNC( OCRFROMFILEUSINGTRANSYM )
{
   TOCRJOBINFO_EG    JobInfo_EG;
   TOCRRESULTSEX_EG* Results = 0;
   long            Status;
   long            JobNo = 0;
   byte            OptionsMask = HB_ISNUM( 3 ) ? hb_parnl( 3 ) : 0x00000000 ;
   long            Orientation = HB_ISNUM( 4 ) ? hb_parnl( 4 ) : TOCRJOBORIENT_AUTO;
   long            ErrorMode   = HB_ISNUM( 5 ) ? hb_parnl( 5 ) : TOCRERRORMODE_LOG ;
   HB_WCHAR        Msg[10240];      //<==Wide string that I later want to return
   char * InputFile = ( char * ) hb_parcx( 1 );   //parm 1 is input file
   FILE*          logfile ;
   time_t         currentTime;
   char timeString[100];


...

   hb_retc( Msg ) ; //  <== this won't work as hb_retc only returns static char * types.    
 


So either the VM has another way to return a wide string back to Harbour or I will have to convert that wide string but that is something I rather not do. On all my wrappers I had ignored wide strings. But now I realize I will have to fix that but wide strings a new to me.

Thank you.

Re: returning a wchar_t variable back to harbour function

PostPosted: Wed May 24, 2023 1:15 pm
by nageswaragunupudi
Even in this case
Code: Select all  Expand view
fw_retWide( cMsg )

will work, as long as we are working with Windows OS.
Please try.
You need to include "<fwh.h>"
Or please give me some sample that we can try at our end to test.

Re: returning a wchar_t variable back to harbour function

PostPosted: Wed May 24, 2023 8:33 pm
by reinaldocrespo
Yes, Mr. Rao, it does work.

I followed the header file down into getfile.c and saw how it is being done and why it works. It is a good learning experience for me.

Thank you very much,