Why new VS2013 project projects are not resolved when linking if the file is .cpp, but fine if the file is .c

So, I link all the native libraries with the .dlls that are used in the WPF application.

I did this with other projects that were compiled into libs, but the latter does not work anyway, although everything seems to be the same. I liked it:

.h:

#ifndef MYHEADER_H_
#define MYHEADER_H_

#ifdef __cplusplus
extern "C" {   
#endif

void  MySetLoginResultCallback(int(*Callback)(int Ok, const char *UserName));


#ifdef __cplusplus
} // end of extern "C"
#endif
#endif // MYHEADER_H_

.cpp

typedef int(*LoginResultCB_t)(int IsOk, const char *UserName);
LoginResultCB_t             gLoginResultCB;

void MySetLoginResultCallback(LoginResultCB_t pCB)
{
    gLoginResultCB = pCB;
}

extern "C" __declspec(dllexport) int MyLoginResultCB(int Ok, cons char *UserName)
{
   if (gLoginResultCB)
       return gLoginResultCB(Ok, UserName);

   return -1;
}

MyLoginResultCB is imported into WPF exe and called from there. Upon initialization, MySetLoginResultCallback is called from the C file in native.dll.

In .dll linking I get an unresolved error from MySetLoginResultCallback (which is called in the .c file). If I leave the title exactly the same and rename .cpp → .c and delete extern "C". The .dll utility failed. What am I missing here?

a call from aini.c

MySetLoginResultCallback(XpAfterLoginCB);

Mistake:

1 > aini.obj: LNK2019: _MySetLoginResultCallback, _InitNoAKit

+4
2

.cpp MySetLoginResultCallback ++. , MySetLoginResultCallback C, .h.

C- .cpp:

extern "C" {

typedef int(*LoginResultCB_t)(int IsOk, const char *UserName);
LoginResultCB_t             gLoginResultCB;

void MySetLoginResultCallback(LoginResultCB_t pCB)
{
    gLoginResultCB = pCB;
}

}

, , , typedef LoginResultCB_t C- .cpp, .h.

+5

, "", .h , /, , .cpp . @molbdnilo, !

0

Source: https://habr.com/ru/post/1623227/


All Articles