Discussion:
Definition of dllimport function not allowed.
(too old to reply)
rockdale
2010-10-11 16:11:10 UTC
Permalink
Hi, All:

I am stuck on this C2491 error when I converter a vs6.0 project into
VS2010. See extracted code below:

in .h
#ifdef MY_API_EXPORTS
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif


CString MY_API MyFunc();

in .cpp
CString MY_API MyFunc()
{
return "teststring";
}


It build successfully in vs6.0, but after convert to vs2010, I got the
erroe:
error C2481: definition of dllimport not allowed on line CString
MY_API MyFunc() in .cpp file.
I read about this error in msdn and think my usage should be correct,
obvious I am missing something, where should I start to look into?

Thanks in advance
-Rockdale
Ulrich Eckhardt
2010-10-12 07:12:55 UTC
Permalink
Post by rockdale
#ifdef MY_API_EXPORTS
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif
Well, and are we supposed to guess whether MY_API_EXPORTS is defined or not?
I guess you'll be surprised yourself.

Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
rockdale
2010-10-12 15:08:22 UTC
Permalink
I am sorry the MY_API_EXPORTS is defined.
Post by Ulrich Eckhardt
Post by rockdale
#ifdef MY_API_EXPORTS
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif
Well, and are we supposed to guess whether MY_API_EXPORTS is defined or not?
I guess you'll be surprised yourself.
Uli
--
C++ FAQ:http://parashift.com/c++-faq-lite
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
DDD
2010-10-12 14:23:23 UTC
Permalink
Post by rockdale
I am stuck on this C2491 error when I converter a vs6.0 project into
in .h
#ifdef MY_API_EXPORTS
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif
CString MY_API MyFunc();
in .cpp
CString MY_API MyFunc()
{
        return "teststring";
}
It build successfully in vs6.0, but after convert to vs2010, I got the
error C2481: definition of dllimport not allowed on line CString
MY_API MyFunc() in .cpp file.
I read about this error in msdn and think my usage should be correct,
obvious I am missing something, where should I start to look into?
Thanks in advance
-Rockdale
Reference http://msdn.microsoft.com/en-us/library/3y1sfaz2%28VS.80%29.aspx

MY_API CString MyFunc();
Post by rockdale
in .cpp
MY_API CString MyFunc()
{
return "teststring";

}
Loading...