Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8281389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:01:05+00:00 2026-06-08T10:01:05+00:00

Possible Duplicate: Windows & C++: extern & __declspec(dllimport) Why/when is __declspec( dllimport ) not

  • 0

Possible Duplicate:
Windows & C++: extern & __declspec(dllimport)
Why/when is __declspec( dllimport ) not needed?

I want to write a DLL project. This project include several DLLs. They are dependent. I define some macros like follow :

#ifdef  MYDLL_DECL1
    #define  DLL_DECL __declspec(dllexport)
#else
    #define DLL_DECL __declspec(dllimport)
#endif

I defined MYDLL_DECL1…MYDLL_DECLn for each modules. Because I thought if i define the same macro that it wouldn’t work . But I really want to define only one macro, and i wrote a testbed. I have two modules. In the second moudle’s source file. I write code like follow:

#define  MYDLL_DECL
#include "moudle1.h"
#include "moudle2.h"

If I use the same macro name “MYDLL_DECL” ,for modle1’s head file I have defined “MYDLL_DECL”, so “DLL_DECL” is equal to ‘__declspec(dllexport)’. Actually in module2 it should be equal to “__declspec(dllimport)”, Because module2 import module1. But I found it worked when I just define a same macro for two module. And I also find that the OpenCV also use this methold to its library

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:01:06+00:00Added an answer on June 8, 2026 at 10:01 am

    First, think about what you need without the macro. If a class or
    function is defined in module1, you need to declare it
    __declspec(dllexport) in module1, and __declspec(dllimport) in all
    of the other modules. Including in the header file where it is
    declared.

    Since you don’t want to maintain two different header files, and you
    don’t what conditional compilation all over the place, the best solution
    is use a conditionally defined macro, e.g.:

    #ifdef MODULE1
    #define MODULE1_DECL __declspec(dllexport)
    #else
    #define MODULE1_DECL __declspec(dllimport)
    #endif
    

    When invoking the compiler, you only define MODULE1 in the project
    module1; you don’t define it in any other project. So when compiling
    module1, MODULE1_DECL expands to __declspec(dllexport), and when
    compiling any other module, it expands to __declspec(dllimport).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Writing a Windows system tray application with .NET I want to develop
Possible Duplicate: iPhone development on Windows I want to build apps for the iPhone
Possible Duplicate: Windows API and .net languages I want to call native Windows API
Possible Duplicate: adding media element in windows phone 7? I Want Details Explanation and
Possible Duplicate: jQuery .load method not firing on IE9 In IE7 and IE8 this
Possible Duplicate: How to detect Windows 64 bit platform with .net? I'm using this
Possible Duplicate: Objective C for Windows I know there are several posts about this
Possible Duplicate: Random variable not changing in “for” loop in windows batch file I
Possible Duplicate: Set up Python on Windows to not type python in cmd When
Possible Duplicate: Allow access permission to write in Program Files of Windows 7 okay,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.