On Fri, 22 May 2009, Mindaugas Kavaliauskas wrote:

Hi,

> a few questions just to make a C knowledge better...
> 1)
> typedef HRESULT   ( CALLBACK * PHB_AX_GETCTRL )( HWND, IUnknown** );
> ptr = ( PHB_AX_GETCTRL ) GetProcAddress( s_hLib, "AtlAxGetControl" );
> Can function pointer type be casted without definition of new type?

Yes:
      ptr = ( HRESULT ( CALLBACK * )( HWND, IUnknown** ) )
            GetProcAddress( s_hLib, HBTEXT( "AtlAxGetControl" ) );

I defined new types only for readability for people who are not very
familiar with C code.
I.e. most of people with some C knowledge should understand this code:

   typedef void (*sighandler_t)(int);
   sighandler_t signal(int signum, sighandler_t handler);

but this one may be to enigmatic for them ;-):

   void (*signal(int signum, void (*handler)(int)))(int);

> 2)
> -  pSink->lpVtbl = &ISink_Vtbl;
> +  pSink->lpVtbl = ( IDispatchVtbl * ) &ISink_Vtbl;
> Why compiler generated an error here? ISink_Vtbl has IDispatchVtbl type.

It was add only to pacify the warning.
pSink->lpVtbl is declared as 'IDispatchVtbl *' not 'const IDispatchVtbl *'
so compiler warn that 'const' qualifier is discarded by assignment.
Real fix should be done in C header files and const added (I believe it's
really constant otherwise we may expect GPFs if above table is stored
in readonly memory segments) and my modification is only workaround for
wrong declaration outside Harbour code.

best regards,
Przemek
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to