views:

104

answers:

3

Error place in api:

#define DLLEXPORT extern "C" __declspec(dllexport)
DLLEXPORT int CAnyseeUSBTVControllerDlg::InitCaptureDevice()
{

In my .h library class and function definition:

class CAnyseeUSBTVControllerDlg : public CDialog
{
// Construction
public:
    int InitCaptureDevice(void);

Any idea how to resolve it?

"Error 1 error C2375: 'CAnyseeUSBTVControllerDlg::InitCaptureDevice' : redefinition; different linkage c:\Program Files\toATS_DVS\anysee\anyseee30\anyseee30\anyseeUSBTVControllerDlg.cpp 122 anyseee30"

+2  A: 

You have to make sure you use the same declaration in your header file. Otherwise it is seen as different methods.

class CAnyseeUSBTVControllerDlg : public CDialog
{
// Construction
public:
    int InitCaptureDevice(void);
    DLLEXPORT int CaptureDevice(void);

See Using dllimport and dllexport in C++ Classes

Rod
error C2144: syntax error : 'int' should be preceded by ';'
Carolus89
Can someone correct the macro in this case? I think I have the intent right. Maybe the extern "C" cannot be used on member methods?
Rod
A: 

You can't have DLLEXPORT stated in .cpp file, but not in a header file (because otherwise compiler treats these functions as different ones).

Make your definition also DLLEXPORT.

HardCoder1986
A: 

From http://tldp.org/HOWTO/C++-dlopen/thesolution.html

C++ has a special keyword to declare a function with C bindings: extern "C". A function declared as extern "C" uses the function name as symbol name, just as a C function. For that reason, only non-member functions can be declared as extern "C", and they cannot be overloaded.

I believe static members may also be possible to extern "C", but you can't do what you're trying to do directly. You'll need to make a C-only wrapper interface that calls your class member functions. You can then extern "C" the wrappers and expose that outside your DLL.

Mark B