Error C2375: override; different connection

Error location 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 solve it?

"Error 1 error C2375: 'CAnyseeUSBTVControllerDlg :: InitCaptureDevice': override; another link c: \ Program Files \ toATS_DVS \ anysee \ anyseee30 \ anyseee30 \ anyseeUSBTVControllerDlg.cpp 122 anyseee30"

+4
source share
5 answers

You must ensure that you use the same declaration in your header file. Otherwise, it is considered as different methods.

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

See Using dllimport and dllexport in C ++ Classes

+5
source

It can happen because

  • You defined the prototype of the function in different places using different visibility ( extern vs static )
  • Same as above, but different name ( extern "C" vs extern "C++" )
  • Same as above, but different dll export ( __declspec(dllimport) vs __declspec(dllexport) ).

To solve, enable / p for files, to see how they are pre-processed (it should be in the file by file and stop generating .obj for this file), look for the .i file with the result.

Either using / displayincludes or just smoothing the code.

+2
source

You cannot specify DLLEXPORT in the .cpp file, but not in the header file (because otherwise the compiler treats these functions as different).

Make your definition also DLLEXPORT .

+1
source

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

C ++ has a special keyword to declare a function with C: extern "C" bindings. A function declared as extern "C" uses the name of the function as the name of the character, simply as a function of C. For this reason, only functions that are not members can be declared as extern "C", and they cannot be overloaded.

I believe that static members can also be extern "C" , but you cannot do what you are trying to do directly. You need to create a C-only shell interface that calls the functions of your class. You can then extern "C" wrapper and show what is outside of your dll.

+1
source
 //foo.h #pragma once #ifdef FOO_EXPORTS #define FOO_API __declspec(dllexport) #else #define FOO_API __declspec(dllimport) #endif namespace foo { class Baz { public: FOO_API static auto say_hello() -> void; }; } 

The key thing, not so much the names of the functions, or my return type of return type, is that the name of the function you want to export is indicated with the name #defined __declspec, as well as the type.

You will also do the same in the function definition:

 //foo.cpp #include "foo.h" namespace foo { FOO_API auto Baz::say_hello() -> void { do { MessageBox(nullptr, L"Seems to be working okay!", L"OK", MB_OK); exit(1); } while (0); } } 

The implementation of the function is not important, just before you put FOO_API.

0
source

All Articles