Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C++ Libraries / October 2004

Tip: Looking for answers? Try searching our database.

'Redefinition; Different type of modifiers'

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sm - 13 Oct 2004 12:09 GMT
Hi All,

I am trying to build a dll from a lib file.

On compilation, I get errors stating 'redefinition; different type of
modifiers', though the dll export statement in the cpp file and the prototype
in the header have no specified modifiers.

The dll export statement looks like this
__declspec(dllexport) DWORD Functionname(Datatype Parameter1);

and the function declaration in the header file is as follows
DWORD WINAPI Functionname(Datatype Parameter1);

Does anybody know how to get over this issue?

Regards
David Lowndes - 14 Oct 2004 11:13 GMT
>I am trying to build a dll from a lib file.
>
[quoted text clipped - 7 lines]
>and the function declaration in the header file is as follows
>DWORD WINAPI Functionname(Datatype Parameter1);

You need to have WINAPI in both places (if that's what you really
want), and the declaration should also have __declspec(dllimport).
Have a look at the topic titled "Importing into an Application Using
__declspec(dllimport)" for an example of how to use a single macro in
the 2 circumstances.

Dave
sm - 16 Oct 2004 09:49 GMT
Thanks David for your response.

I observed that when WINAPI is used, I won't be able to use
__declspec(dllexport) to export the functions of my dll; since WINAPI uses
__stdcall and dllexport cannot be used with __stdcall.

Is there a workaround to export WINAPI functions?

Thanks once again.

                           

> >I am trying to build a dll from a lib file.
> >
[quoted text clipped - 15 lines]
>
> Dave
David Lowndes - 16 Oct 2004 09:59 GMT
>I observed that when WINAPI is used, I won't be able to use
>__declspec(dllexport) to export the functions of my dll; since WINAPI uses
>__stdcall and dllexport cannot be used with __stdcall.

I'm not sure why you think that - you can:

DWORD __declspec (dllexport) __stdcall Functionname(Datatype
Parameter1);

Dave
Signature

MVP VC++ FAQ: http://www.mvps.org/vcfaq

sm - 16 Oct 2004 11:31 GMT
Declaring the export function as follows:

DWORD __declspec (dllexport) __stdcall FunctionName(Datatype
Parameter1);

gives the following error on compilation:
d:\testproj\test.cpp(23): error C2375: 'FunctionName' : redefinition;
different linkage

How to get over this error?

Regards.

> >I observed that when WINAPI is used, I won't be able to use
> >__declspec(dllexport) to export the functions of my dll; since WINAPI uses
[quoted text clipped - 6 lines]
>
> Dave
David Lowndes - 16 Oct 2004 23:37 GMT
>Declaring the export function as follows:
>
[quoted text clipped - 6 lines]
>
>How to get over this error?

This is where we came in isn't it?

The definition in the header file needs to be the same.

Dave
Signature

MVP VC++ FAQ: http://www.mvps.org/vcfaq

sm - 17 Oct 2004 06:19 GMT
Thanks again for your response.

Do you mean that when the export statement is
DWORD __declspec (dllexport) __stdcall FunctionName(Datatype
Parameter1);

the function declaration in the header file needs to be
DWORD __declspec Functionname(Datatype Parameter1);

But won't such a declaration still give linker errors, since the lib file
would be using __stdcall calling convention in the definition of the function?

So, the question again is, how to export functions which use __stdcall
calling convention?

Regards.

> >Declaring the export function as follows:
> >
[quoted text clipped - 12 lines]
>
> Dave
David Lowndes - 17 Oct 2004 09:36 GMT
>Do you mean that when the export statement is
>DWORD __declspec (dllexport) __stdcall FunctionName(Datatype
>Parameter1);
>
>the function declaration in the header file needs to be
>DWORD __declspec Functionname(Datatype Parameter1);

No.

When you build your DLL, the header & source file needs to be the
same:

DWORD __declspec (dllexport) __stdcall FunctionName(Datatype
Parameter1);

otherwise you'll get that redefinition error you are seeing.

When you use the header file from the project where you'll call the
function, it needs to be:

DWORD __declspec (dllimport) __stdcall FunctionName(Datatype
Parameter1);

Have a look at that MSDN topic I referred you to originally, that
shows how to use a preprocessor definition to get the correct form of
declspec (dllexport/dllimport) in both circumstances.

Dave
Signature

MVP VC++ FAQ: http://www.mvps.org/vcfaq

sm - 19 Oct 2004 06:39 GMT
I'll try that.

Thanks.

> >Do you mean that when the export statement is
> >DWORD __declspec (dllexport) __stdcall FunctionName(Datatype
[quoted text clipped - 24 lines]
>
> Dave

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.