LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

__fastcall

Hi everybody,
   I'm working on a project that should be c++ (drivers developed for CHARON-11 emulator, are meant to be written in c++), and I'm using LabWindows, since I hope C code can do it.  I don't expect you to know what Charon is, and you can live a happy life without knowing it. A happier one, maybe.....

   A problem I encountered was in header chapi.h, that defines functions to be implemented.  I found this:
  
   #ifndef __CHAPI_H__
#define __CHAPI_H__

/*-----------------------------------------------------------------------------
 * C H A P I -- CHaron API
 *
 *
 *
 *
 *
 *
 *-----------------------------------------------------------------------------
 */

#ifdef __cplusplus
extern "C" {
#endif

#ifdef _WIN32
#ifdef _M_ALPHA
#define CHAPI
#else
#define CHAPI     __fastcall
#endif
#define DLLENTRY __cdecl
#else
#define CHAPI
#define DLLENTRY
#endif   

#ifndef __CHARON_H__
typedef    void    (CHAPI* sst_fun)(void* arg1, int arg2);
typedef void    (CHAPI* ast_handler)(void*);
typedef void    (CHAPI* irq_fun)(int arg);
#endif
***

The __fastcall MS C++ directive, in red line,  is not recognized in CVI, so compiler gives error at green line.  I can solve this by empty definition of CHAPI macro, but I was wondering if there was a CVI equivalent for __fastcall. 

I know register c-keyword should be equivalent, but..... I would also preserve the definition as

    typedef void (__fastcall* st_fun) etc..

and with register I should write
  
    typedef register void .....

Thanks!!!!

graziano




0 Kudos
Message 1 of 3
(3,080 Views)

I do not think using the "register" keyword is the correct solution. In my opinion, the correct solution is to create a very thin wrapper DLL in Visual C++ to wrap and export these functions with C linkage and using either __cdecl or __stdcall calling conventions. For example, if you had the following C++ functions:

void __fastcall Foo(int);

int __fastcall Bar(char *);

Wrap them as:

extern "C" {

void __stdcall FooWrapper(int a) { Foo(a); }

int __stdcall BarWrapper(char *a) { return Bar(a); }

}

in a C++ source file and export them from the VC++ DLL. Now call the wrapper DLL from C, instead of calling the original C++ library.
Message 2 of 3
(3,067 Views)
Hi Mohan!

    Thank you for your help!!!

    Of course, I can do so, but.... as __fastcall statement seems to be the only difference between my project and the VC++ project, I think I will keep programming on CVI, I hope this will work.......

    Anyway, my opinion is that __fastcall is not really necessary, in fact it is a directive that specify a preference for compiling, not a "must". 

   At the moment, my dummy-driver, created in the mean-time, seems to work...

    Thanks again, and have a nice week-end!

graziano
0 Kudos
Message 3 of 3
(3,061 Views)