Solved

Export from DLL overloaded operator new

Posted on 2001-07-23
11
960 Views
Last Modified: 2008-02-20
I overload "operator new" in a AdllA.dll
now I am trying to export it, so I can use
the "overloaded new" in BdllB.dll

I get this errors when I build AdllA.dll:
_________________________________________________________
Registry.cpp
udtmemalloc.h(19) : error C2375: 'new' : redefinition; different linkage
: see declaration of 'new'

udtmemalloc.h(21) : error C2375: 'delete' : redefinition; different linkage
: see declaration of 'delete'

Registry.cpp(38) : error C2264: 'new' : error in function definition or declaration; function not called

Registry.cpp(43) : error C2264: 'new' : error in function definition or declaration; function not called
----------------------------------------------------------

How do you export an overloaded new operator?

Thank you very much,

Rob H.
0
Comment
Question by:rssh
11 Comments
 

Expert Comment

by:rtenhove
ID: 6310460
You have to use import and export declarations.  This can done using the .DEF file, or in code:

You usually use a #define to keep things straight:

#define DLL_DECL __declspec( dllexport )
or
#define DLL_DECL __declspec( dllimport )

class DLL_DECL MyClass : public TObject { ...


You use the export form when building the DLL; you use the import form for modules that use (import) the DLL.
0
 

Author Comment

by:rssh
ID: 6310573
My question is regarding overloading global new
---------------------
so by doing this:
#ifdef EXPORTNEW_EXPORTS
#define EXPORTNEW_API __declspec(dllexport)
#else
#define EXPORTNEW_API __declspec(dllimport)
#endif

EXPORTNEW_API  void* operator new(unsigned int x);
-----------------------------------------------
I get this error:
exportnew.h(9) : error C2375: 'new' : redefinition; different linkage
-----------------------------------------------
????????????????????????
0
 

Expert Comment

by:rtenhove
ID: 6311121
How are you setting EXPORTNEW_EXPORTS?

-Ron
0
 

Author Comment

by:rssh
ID: 6311279
it's defined with the project...
in project setting, there is a preprocessor definitions
section where EXPORTNEW_EXPORTS is one of...
0
 

Expert Comment

by:rtenhove
ID: 6313351
You need to make sure that it is set differently when you are compiling the DLL, versus compiling the importer of the DLL.  You must tell the compiler you are exporting the class when you are compiling the DLL; likewise, you must tell the compiler you are importing the class when you are compiling "clients" that use the DLL.

Does this help?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:rssh
ID: 6313755
Well, that's not the problem... all I am trying to do is export the new operator... and I keep getting the errors above... see new is already imported from some .lib file... the compiler comlains about some redefinition...
The problem you mentioned is already solved with the code above... thanx
0
 

Expert Comment

by:rtenhove
ID: 6314128
Are you using the __declspec( dllexport ) on the new operator only?  

Perhaps you should post some snippet of your code, rather than just compiler error messages...

0
 

Expert Comment

by:rtenhove
ID: 6349857
have you figured out what the problem was yet?
0
 

Author Comment

by:rssh
ID: 6352013
Acually I did ...
malloc and free can not go into a dll unless you take out the dependency on the lib file they're in... I think it's called msvctrd.lib or something similar...
You can make it work by adding them to a static linked library... but that gives 'different linkage' warings...
thanx anyway...
0
 
LVL 11

Expert Comment

by:griessh
ID: 6833133
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and PAQ at zero points since you found your own answer.

The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 6853135
Per recommendation points refunded and question closed.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now