can't use #define on __declspec error C2491

Started by
8 comments, last by Cibressus 19 years, 10 months ago
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.
| Member of UBAAG (Unban aftermath Association of Gamedev)
Advertisement
Hmm... what error are you getting?
Not giving is not stealing.
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
| Member of UBAAG (Unban aftermath Association of Gamedev)
Are you sure that the #DEFINE is generating the error?
Not giving is not stealing.
it says definition of dllimport function not allowed. not sure what else it would mean.
| Member of UBAAG (Unban aftermath Association of Gamedev)
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.
Not giving is not stealing.
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()
{

}
| Member of UBAAG (Unban aftermath Association of Gamedev)
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.
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); 
I found it out. i have to use mfc to use classes in dll''s. thier called extended dll''s.
| Member of UBAAG (Unban aftermath Association of Gamedev)

This topic is closed to new replies.

Advertisement