Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Cibressus

can't use #define on __declspec error C2491

This topic is 5223 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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()
{

}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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);

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!