Page 1 of 1

C Struct -> Harbour Using Help!!

Posted: Mon Dec 10, 2012 5:51 pm
by oknbs
Dear All

C Struct -> Harbour Using Help!!

Harbour Function from C structure to assign a value.
The value read from the Harbour Function C struct is different.
1) passed Value: 10
2) read Value: 2

Code: Select all

/* Harbour Sample Function */

Function Main()
   ...   
   oWnd:bCommNotify = { | pParam, nValue | EventNotify( pParam, nValue ) }
   
   oThread := ThreadOn( 10, 20, oWnd:hWnd )      // Input Parameter 10, 20, oWnd:hWnd

Return nil


Function EventNotify( pParam, nValue )

   MsgInfo( GetWaitData( pParam ) )             // Return Value 2

Return nil

/*---------------------------------------------------------------------------------------*/

/* C Function Sample Source */

typedef struct thread_param
{ 
     long nParamNo;
     int  nIndexCode;  
} THREAD_PARAM, *LPTHREAD_PARAM;


HB_FUNC( THREADON )
{
    DWORD dwThreadID;
    HANDLE hThread;

    LPTHREAD_PARAM pWaitParam = ( LPTHREAD_PARAM ) hb_xgrab( sizeof( THREAD_PARAM ) );
      
    memset( ( char * )pWaitParam, 0, sizeof( THREAD_PARAM ) );
      
    pWaitParam->nParamNo = hb_parnl(1); 
    pWaitParam->nIndexCode = hb_parni(2); 
      
    CommNotifyHwnd = (HWND)hb_parnl( 3 );

    hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)WaitThread, (LPVOID)pWaitParam, 0, &dwThreadID );
    ....
}


DWORD WINAPI WaitThread( LPVOID pVoid )
{
   DWORD dwExitCode;
   LPTHREAD_PARAM pWaitParam = (LPTHREAD_PARAM)pVoid;

   SendMessage( CommNotifyHwnd, WM_COMMNOTIFY, (WPARAM)pWaitParam, (LPARAM)0 );
   ....
}


HB_FUNC( GETWAITDATA )
{
   LPTHREAD_PARAM pWaitParam = (LPTHREAD_PARAM)hb_param( 1, HB_IT_ANY );
   hb_retnl( pWaitParam->nParamNo );
}
 
Thanks

Re: C Struct -> Harbour Using Help!!

Posted: Tue Dec 11, 2012 10:32 am
by Antonio Linares
Are you returning pWaitParam to high level (PRG) ?

It is not in your code...

:-)

Re: C Struct -> Harbour Using Help!!

Posted: Thu Dec 13, 2012 3:42 am
by oknbs
Thank you for your answer Antonio. :)

oknbs.