can't use #define on __declspec error C2491
everywere tells me to go
#ifndef X_API
#define X_API __declspec(dllimport)
#endif
but this generates a error for me. is thier a work around.
c:\xander\xander 1 3\engine.cpp(17) : error C2491: ''xEngine_Init'' : definition of dllimport function not allowed
c:\xander\xander 1 3\engine.cpp(22) : error C2491: ''xEngine_DeInit'' : definition of dllimport function not allowed
c:\xander\xander 1 3\engine.cpp(22) : error C2491: ''xEngine_DeInit'' : definition of dllimport function not allowed
quote:Original post by Cibressus
it says definition of dllimport function not allowed. not sure what else it would mean.
No no, I am saying, do those line numbers match?
I am asking this because I can''t imagine that the #define itself is generating that error, but more likely something else as a result of the #define.
no, this is the file.
engine.cpp
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#ifndef X_API
#define X_API __declspec(dllimport)
#endif
#include "Engine.h"
#include "InDLL.h"
#include <windows.h>
void X_API xEngine_Init()
{
}
void X_API xEngine_DeInit()
{
}
engine.cpp
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#ifndef X_API
#define X_API __declspec(dllimport)
#endif
#include "Engine.h"
#include "InDLL.h"
#include <windows.h>
void X_API xEngine_Init()
{
}
void X_API xEngine_DeInit()
{
}
It looks like you''re changing the linkage specifier on the function in its implementation from how it was defined in the header declaration. This is non-kosher. The __declspec specifier belongs in the function declaration in the header.
Furthermore, what you''re doing is totally inconsistent. When you name a function as __declspec(dllimport), you''re saying that you plan to import that function from a DLL. So trying to provide a function definition makes no sense.
Furthermore, what you''re doing is totally inconsistent. When you name a function as __declspec(dllimport), you''re saying that you plan to import that function from a DLL. So trying to provide a function definition makes no sense.
Isn''t it supposed to be:
__declspec(dllexport) return_type function_name(parameters);__declspec(dllexport) void MyFunction(int nParameter1);__declspec(dllimport) void MyFunction(int nParameter1);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement