Test.h
#ifndef TEST_H
#define TEST_H
#ifdef BUILDING_MY_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" {
#endif
DLL_EXPORT void f();
#ifdef __cplusplus
}
#endif
#endif
Test.c
#include "Test.h"
#include "myfunc.h"
void f()
{
g();
}
In your C project you have to add BUILDING_MY_DLL
to
Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions
The only real change is that I added the toggle between __declspec(dllexport)
and __declspec(dllimport)
. Changes required:
- Moved
f
's body toTest.c
because functions imported with__declspec(dllimport)
cannot have a definition already.
Other changes:
- Do never write
extern "C"
without an#ifdef __cplusplus
guard, or many C compilers will not compile your code.