473,830 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C4251 Compiler Warning: How Do I Remediate?

I have a class that is intended to be exported in a DLL that uses another
class that is in a static library. All clients that use the DLL will also
link with the same static library. In summary, the following condition
exists:

class A {} ; // Instantiated in the static library and specified
// in a header included by all clients.

//
// This is the class using A that is exported by a DLL.
//
class __declspec( dllexport ) B
{
public :
B( const A & ) ;

const A &
value( void ) const ;

private :
A _a ;
} ;

Of course, the implementation of class B is not shown, and class A
has other members, so the entire example is greatly simplified, however,
compilation of code similar to this always results in a C4251 warning
being issued on any line where a type of class A is referenced by a class
using the dllexport attribute.

The question to be posed is how does one eliminate the C4251 warning without
re-declaring class A using the dllexport directive. The intent is not to
export
this class in any DLL since it is to be resolved at link-time, not
run-time -- that
is: all clients using class A must use the appropriate header and link with
the
static library.

NOTE: This message was posted to both the dotnet.language s.vc and
vc.language newsgroups.

--
=============== =============== =============== =============== ==========
=============== =============== =============== =============== ==========
==
== Bob Riedel
== Beckman Coulter, Incorporated
== PO Box 8000 W-529
== 200 S Kraemer Blvd
== Brea CA 92822-8000
==
== Email 1: ra******@beckma n.com
== Email 2: ra******@mindsp ring.com
==
==
== The opinions expressed are my own, and do not necessarily represent
== those of Beckman Coulter, Inc.
==
=============== =============== =============== =============== ==========
=============== =============== =============== =============== ==========
==
== "Effective education is the key to successful democracy."
==
== "Criticizin g the actions of others offers so little risk, and
== requires so little effort that it is, without exception, the tool
== of the lazy and of the foolish -- who have neither the intelligence
== to discover, nor the discipline to pursue, a realistic
== alternative."
==
=============== =============== =============== =============== ==========
=============== =============== =============== =============== ==========
Nov 16 '05 #1
5 6448
Robert,

When I ran into this is was completely harmless. I turned it off and back
on with a pragma.

#pragma warning( disable : 4251)
#include "foobar.h"
#pragma warning( default : 4251)

Cheers,
dan

"Robert A Riedel" <ra**********@b eckman.com> wrote in message
news:#F******** *****@TK2MSFTNG P09.phx.gbl...
I have a class that is intended to be exported in a DLL that uses another
class that is in a static library. All clients that use the DLL will also
link with the same static library. In summary, the following condition
exists:

class A {} ; // Instantiated in the static library and specified
// in a header included by all clients.

//
// This is the class using A that is exported by a DLL.
//
class __declspec( dllexport ) B
{
public :
B( const A & ) ;

const A &
value( void ) const ;

private :
A _a ;
} ;

Of course, the implementation of class B is not shown, and class A
has other members, so the entire example is greatly simplified, however,
compilation of code similar to this always results in a C4251 warning
being issued on any line where a type of class A is referenced by a class
using the dllexport attribute.

The question to be posed is how does one eliminate the C4251 warning without re-declaring class A using the dllexport directive. The intent is not to
export
this class in any DLL since it is to be resolved at link-time, not
run-time -- that
is: all clients using class A must use the appropriate header and link with the
static library.

NOTE: This message was posted to both the dotnet.language s.vc and
vc.language newsgroups.

--
=============== =============== =============== =============== ==========
=============== =============== =============== =============== ==========
==
== Bob Riedel
== Beckman Coulter, Incorporated
== PO Box 8000 W-529
== 200 S Kraemer Blvd
== Brea CA 92822-8000
==
== Email 1: ra******@beckma n.com
== Email 2: ra******@mindsp ring.com
==
==
== The opinions expressed are my own, and do not necessarily represent
== those of Beckman Coulter, Inc.
==
=============== =============== =============== =============== ==========
=============== =============== =============== =============== ==========
==
== "Effective education is the key to successful democracy."
==
== "Criticizin g the actions of others offers so little risk, and
== requires so little effort that it is, without exception, the tool
== of the lazy and of the foolish -- who have neither the intelligence
== to discover, nor the discipline to pursue, a realistic
== alternative."
==
=============== =============== =============== =============== ==========
=============== =============== =============== =============== ==========

Nov 16 '05 #2
Hello Robert,

Thanks for your email.

From MSDN, we could see that:

The dllexport and dllimport storage-class attributes are Microsoft-specific
extensions to the C and C++ languages. They enable you to export and import
functions, data, and objects to and from a DLL.

These attributes explicitly define the DLL's interface to its client, which
can be the executable file or another DLL. Declaring functions as dllexport
eliminates the need for a module-definition (.DEF) file, at least with
respect to the specification of exported functions. Note that dllexport
replaces the __export keyword.

If a class is marked declspec(dllexp ort), any specializations of class
templates in the class hierarchy are implicitly marked as
declspec(dllexp ort).

The declaration of dllexport and dllimport must use extended attribute
syntax and the __declspec keyword.

Based on my experience, dllexport is there to avoid def files. When you
dllexport a __stdcall function it is exported alongwith the name
decoration. Thats the @ stuff after your function name.

For functions that you export via dllexport and import via dllimport and if
both use the same compiler you shouldn't have problems with the decoration.
With a def, the export happens with the name you provided in the def which
happens to be without name adornation. You could check the difference by
using Depency tool in Visual Studio 6.0 -> Tools.

Does that answer your question?

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Reply-To: "Robert A Riedel" <ra******@beckm an.com>
!From: "Robert A Riedel" <ra**********@b eckman.com>
!Subject: C4251 Compiler Warning: How Do I Remediate?
!Date: Tue, 23 Sep 2003 15:37:22 -0700
!Lines: 73
!Organization: Beckman Coulter
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <#F************ *@TK2MSFTNGP09. phx.gbl>
!Newsgroups:
microsoft.publi c.dotnet.langua ges.vc,microsof t.public.vc.lan guage
!NNTP-Posting-Host: 64-162-186-125.ded.pacbell .net 64.162.186.125
!Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
!Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.vc.language:1 98187
microsoft.publi c.dotnet.langua ges.vc:28638
!X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vc
!
!I have a class that is intended to be exported in a DLL that uses another
!class that is in a static library. All clients that use the DLL will also
!link with the same static library. In summary, the following condition
!exists:
!
!class A {} ; // Instantiated in the static library and specified
! // in a header included by all clients.
!
!//
!// This is the class using A that is exported by a DLL.
!//
!class __declspec( dllexport ) B
!{
! public :
! B( const A & ) ;
!
! const A &
! value( void ) const ;
!
! private :
! A _a ;
!} ;
!
!Of course, the implementation of class B is not shown, and class A
!has other members, so the entire example is greatly simplified, however,
!compilation of code similar to this always results in a C4251 warning
!being issued on any line where a type of class A is referenced by a class
!using the dllexport attribute.
!
!The question to be posed is how does one eliminate the C4251 warning
without
!re-declaring class A using the dllexport directive. The intent is not to
!export
!this class in any DLL since it is to be resolved at link-time, not
!run-time -- that
!is: all clients using class A must use the appropriate header and link with
!the
!static library.
!
!NOTE: This message was posted to both the dotnet.language s.vc and
!vc.language newsgroups.
!
!--
!============== =============== =============== =============== ===========
!============== =============== =============== =============== ===========
!==
!== Bob Riedel
!== Beckman Coulter, Incorporated
!== PO Box 8000 W-529
!== 200 S Kraemer Blvd
!== Brea CA 92822-8000
!==
!== Email 1: ra******@beckma n.com
!== Email 2: ra******@mindsp ring.com
!==
!==
!== The opinions expressed are my own, and do not necessarily represent
!== those of Beckman Coulter, Inc.
!==
!============== =============== =============== =============== ===========
!============== =============== =============== =============== ===========
!==
!== "Effective education is the key to successful democracy."
!==
!== "Criticizin g the actions of others offers so little risk, and
!== requires so little effort that it is, without exception, the tool
!== of the lazy and of the foolish -- who have neither the intelligence
!== to discover, nor the discipline to pursue, a realistic
!== alternative."
!==
!============== =============== =============== =============== ===========
!============== =============== =============== =============== ===========
!
!
!

Nov 16 '05 #3
Your reply contains only a partial explanation.

The use of dllexport is described with reasonable clarity in the Microsoft
writings, however, dllimport is not, nor have you really addressed its use
in your reply. What is really problematic is that I cannot find a reasonalbe
explanation of its use anywhere. For example, the VC.NET 2003 help file
states the following:

"As a reference, search through the Win32 WINBASE.H header file. It contains
examples of __declspec(dlli mport) usage"

However, WINBASE.H contains no such examples.

An explanation of dllimport and examples would be appreciated.

Thanks.

"Yan-Hong Huang[MSFT]" <yh*****@online .microsoft.com> wrote in message
news:0s******** ******@cpmsftng xa06.phx.gbl...
Hello Robert,

Thanks for your email.

From MSDN, we could see that:

The dllexport and dllimport storage-class attributes are Microsoft-specific extensions to the C and C++ languages. They enable you to export and import functions, data, and objects to and from a DLL.

These attributes explicitly define the DLL's interface to its client, which can be the executable file or another DLL. Declaring functions as dllexport eliminates the need for a module-definition (.DEF) file, at least with
respect to the specification of exported functions. Note that dllexport
replaces the __export keyword.

If a class is marked declspec(dllexp ort), any specializations of class
templates in the class hierarchy are implicitly marked as
declspec(dllexp ort).

The declaration of dllexport and dllimport must use extended attribute
syntax and the __declspec keyword.

Based on my experience, dllexport is there to avoid def files. When you
dllexport a __stdcall function it is exported alongwith the name
decoration. Thats the @ stuff after your function name.

For functions that you export via dllexport and import via dllimport and if both use the same compiler you shouldn't have problems with the decoration. With a def, the export happens with the name you provided in the def which
happens to be without name adornation. You could check the difference by
using Depency tool in Visual Studio 6.0 -> Tools.

Does that answer your question?

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
!Reply-To: "Robert A Riedel" <ra******@beckm an.com>
!From: "Robert A Riedel" <ra**********@b eckman.com>
!Subject: C4251 Compiler Warning: How Do I Remediate?
!Date: Tue, 23 Sep 2003 15:37:22 -0700
!Lines: 73
!Organization: Beckman Coulter
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <#F************ *@TK2MSFTNGP09. phx.gbl>
!Newsgroups:
microsoft.publi c.dotnet.langua ges.vc,microsof t.public.vc.lan guage
!NNTP-Posting-Host: 64-162-186-125.ded.pacbell .net 64.162.186.125
!Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
!Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.vc.language:1 98187
microsoft.publi c.dotnet.langua ges.vc:28638
!X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vc
!
!I have a class that is intended to be exported in a DLL that uses another
!class that is in a static library. All clients that use the DLL will also
!link with the same static library. In summary, the following condition
!exists:
!
!class A {} ; // Instantiated in the static library and specified
! // in a header included by all clients.
!
!//
!// This is the class using A that is exported by a DLL.
!//
!class __declspec( dllexport ) B
!{
! public :
! B( const A & ) ;
!
! const A &
! value( void ) const ;
!
! private :
! A _a ;
!} ;
!
!Of course, the implementation of class B is not shown, and class A
!has other members, so the entire example is greatly simplified, however,
!compilation of code similar to this always results in a C4251 warning
!being issued on any line where a type of class A is referenced by a class
!using the dllexport attribute.
!
!The question to be posed is how does one eliminate the C4251 warning
without
!re-declaring class A using the dllexport directive. The intent is not to
!export
!this class in any DLL since it is to be resolved at link-time, not
!run-time -- that
!is: all clients using class A must use the appropriate header and link with !the
!static library.
!
!NOTE: This message was posted to both the dotnet.language s.vc and
!vc.language newsgroups.
!
!--
!============== =============== =============== =============== ===========
!============== =============== =============== =============== ===========
!==
!== Bob Riedel
!== Beckman Coulter, Incorporated
!== PO Box 8000 W-529
!== 200 S Kraemer Blvd
!== Brea CA 92822-8000
!==
!== Email 1: ra******@beckma n.com
!== Email 2: ra******@mindsp ring.com
!==
!==
!== The opinions expressed are my own, and do not necessarily represent
!== those of Beckman Coulter, Inc.
!==
!============== =============== =============== =============== ===========
!============== =============== =============== =============== ===========
!==
!== "Effective education is the key to successful democracy."
!==
!== "Criticizin g the actions of others offers so little risk, and
!== requires so little effort that it is, without exception, the tool
!== of the lazy and of the foolish -- who have neither the intelligence
!== to discover, nor the discipline to pursue, a realistic
!== alternative."
!==
!============== =============== =============== =============== ===========
!============== =============== =============== =============== ===========
!
!
!

Nov 16 '05 #4
Hello Robert,

Thanks for the response.

In order to know the advantages and mechanics of using _declspec(dllim port)
and _declspec(dllex port) in the application, we could refer to one MSDN
article:
"INFO: Using _declspec(dllim port) & _declspec(dllex port) in Code"
http://support.microsoft.com/default...b;en-us;132044

Hope that helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Reply-To: "Robert A Riedel" <ra******@beckm an.com>
!From: "Robert A Riedel" <ra**********@b eckman.com>
!References: <#F************ *@TK2MSFTNGP09. phx.gbl>
<0s************ **@cpmsftngxa06 .phx.gbl>
!Subject: Re: C4251 Compiler Warning: How Do I Remediate?
!Date: Mon, 29 Sep 2003 16:05:21 -0700
!Lines: 167
!Organization: Beckman Coulter
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <#6************ *@TK2MSFTNGP12. phx.gbl>
!Newsgroups: microsoft.publi c.dotnet.langua ges.vc
!NNTP-Posting-Host: 64-162-186-125.ded.pacbell .net 64.162.186.125
!Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
!Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vc:28876
!X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vc
!
!Your reply contains only a partial explanation.
!
!The use of dllexport is described with reasonable clarity in the Microsoft
!writings, however, dllimport is not, nor have you really addressed its use
!in your reply. What is really problematic is that I cannot find a
reasonalbe
!explanation of its use anywhere. For example, the VC.NET 2003 help file
!states the following:
!
!"As a reference, search through the Win32 WINBASE.H header file. It
contains
!examples of __declspec(dlli mport) usage"
!
!However, WINBASE.H contains no such examples.
!
!An explanation of dllimport and examples would be appreciated.
!
!Thanks.
!
!"Yan-Hong Huang[MSFT]" <yh*****@online .microsoft.com> wrote in message
!news:0s******* *******@cpmsftn gxa06.phx.gbl.. .
!> Hello Robert,
!>
!> Thanks for your email.
!>
!> From MSDN, we could see that:
!>
!> The dllexport and dllimport storage-class attributes are
!Microsoft-specific
!> extensions to the C and C++ languages. They enable you to export and
!import
!> functions, data, and objects to and from a DLL.
!>
!> These attributes explicitly define the DLL's interface to its client,
!which
!> can be the executable file or another DLL. Declaring functions as
!dllexport
!> eliminates the need for a module-definition (.DEF) file, at least with
!> respect to the specification of exported functions. Note that dllexport
!> replaces the __export keyword.
!>
!> If a class is marked declspec(dllexp ort), any specializations of class
!> templates in the class hierarchy are implicitly marked as
!> declspec(dllexp ort).
!>
!> The declaration of dllexport and dllimport must use extended attribute
!> syntax and the __declspec keyword.
!>
!> Based on my experience, dllexport is there to avoid def files. When you
!> dllexport a __stdcall function it is exported alongwith the name
!> decoration. Thats the @ stuff after your function name.
!>
!> For functions that you export via dllexport and import via dllimport and
!if
!> both use the same compiler you shouldn't have problems with the
!decoration.
!> With a def, the export happens with the name you provided in the def
which
!> happens to be without name adornation. You could check the difference by
!> using Depency tool in Visual Studio 6.0 -> Tools.
!>
!> Does that answer your question?
!>
!> Best regards,
!> Yanhong Huang
!> Microsoft Online Partner Support
!>
!> Get Secure! - www.microsoft.com/security
!> This posting is provided "AS IS" with no warranties, and confers no
!rights.
!>
!> --------------------
!> !Reply-To: "Robert A Riedel" <ra******@beckm an.com>
!> !From: "Robert A Riedel" <ra**********@b eckman.com>
!> !Subject: C4251 Compiler Warning: How Do I Remediate?
!> !Date: Tue, 23 Sep 2003 15:37:22 -0700
!> !Lines: 73
!> !Organization: Beckman Coulter
!> !X-Priority: 3
!> !X-MSMail-Priority: Normal
!> !X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!> !X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!> !Message-ID: <#F************ *@TK2MSFTNGP09. phx.gbl>
!> !Newsgroups:
!> microsoft.publi c.dotnet.langua ges.vc,microsof t.public.vc.lan guage
!> !NNTP-Posting-Host: 64-162-186-125.ded.pacbell .net 64.162.186.125
!> !Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
!> !Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.vc.language:1 98187
!> microsoft.publi c.dotnet.langua ges.vc:28638
!> !X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vc
!> !
!> !I have a class that is intended to be exported in a DLL that uses
another
!> !class that is in a static library. All clients that use the DLL will
also
!> !link with the same static library. In summary, the following condition
!> !exists:
!> !
!> !class A {} ; // Instantiated in the static library and specified
!> ! // in a header included by all clients.
!> !
!> !//
!> !// This is the class using A that is exported by a DLL.
!> !//
!> !class __declspec( dllexport ) B
!> !{
!> ! public :
!> ! B( const A & ) ;
!> !
!> ! const A &
!> ! value( void ) const ;
!> !
!> ! private :
!> ! A _a ;
!> !} ;
!> !
!> !Of course, the implementation of class B is not shown, and class A
!> !has other members, so the entire example is greatly simplified, however,
!> !compilation of code similar to this always results in a C4251 warning
!> !being issued on any line where a type of class A is referenced by a
class
!> !using the dllexport attribute.
!> !
!> !The question to be posed is how does one eliminate the C4251 warning
!> without
!> !re-declaring class A using the dllexport directive. The intent is not to
!> !export
!> !this class in any DLL since it is to be resolved at link-time, not
!> !run-time -- that
!> !is: all clients using class A must use the appropriate header and link
!with
!> !the
!> !static library.
!> !
!> !NOTE: This message was posted to both the dotnet.language s.vc and
!> !vc.language newsgroups.
!> !
!> !--
!> !============== =============== =============== =============== ===========
!> !============== =============== =============== =============== ===========
!> !==
!> !== Bob Riedel
!> !== Beckman Coulter, Incorporated
!> !== PO Box 8000 W-529
!> !== 200 S Kraemer Blvd
!> !== Brea CA 92822-8000
!> !==
!> !== Email 1: ra******@beckma n.com
!> !== Email 2: ra******@mindsp ring.com
!> !==
!> !==
!> !== The opinions expressed are my own, and do not necessarily represent
!> !== those of Beckman Coulter, Inc.
!> !==
!> !============== =============== =============== =============== ===========
!> !============== =============== =============== =============== ===========
!> !==
!> !== "Effective education is the key to successful democracy."
!> !==
!> !== "Criticizin g the actions of others offers so little risk, and
!> !== requires so little effort that it is, without exception, the tool
!> !== of the lazy and of the foolish -- who have neither the intelligence
!> !== to discover, nor the discipline to pursue, a realistic
!> !== alternative."
!> !==
!> !============== =============== =============== =============== ===========
!> !============== =============== =============== =============== ===========
!> !
!> !
!> !
!>
!
!
!

Nov 16 '05 #5
Much better. Thanks for the info.

"Yan-Hong Huang[MSFT]" <yh*****@online .microsoft.com> wrote in message
news:Fo******** ******@cpmsftng xa06.phx.gbl...
Hello Robert,

Thanks for the response.

In order to know the advantages and mechanics of using _declspec(dllim port) and _declspec(dllex port) in the application, we could refer to one MSDN
article:
"INFO: Using _declspec(dllim port) & _declspec(dllex port) in Code"
http://support.microsoft.com/default...b;en-us;132044

Hope that helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
!Reply-To: "Robert A Riedel" <ra******@beckm an.com>
!From: "Robert A Riedel" <ra**********@b eckman.com>
!References: <#F************ *@TK2MSFTNGP09. phx.gbl>
<0s************ **@cpmsftngxa06 .phx.gbl>
!Subject: Re: C4251 Compiler Warning: How Do I Remediate?
!Date: Mon, 29 Sep 2003 16:05:21 -0700
!Lines: 167
!Organization: Beckman Coulter
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <#6************ *@TK2MSFTNGP12. phx.gbl>
!Newsgroups: microsoft.publi c.dotnet.langua ges.vc
!NNTP-Posting-Host: 64-162-186-125.ded.pacbell .net 64.162.186.125
!Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
!Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vc:28876
!X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vc
!
!Your reply contains only a partial explanation.
!
!The use of dllexport is described with reasonable clarity in the Microsoft !writings, however, dllimport is not, nor have you really addressed its use !in your reply. What is really problematic is that I cannot find a
reasonalbe
!explanation of its use anywhere. For example, the VC.NET 2003 help file
!states the following:
!
!"As a reference, search through the Win32 WINBASE.H header file. It
contains
!examples of __declspec(dlli mport) usage"
!
!However, WINBASE.H contains no such examples.
!
!An explanation of dllimport and examples would be appreciated.
!
!Thanks.
!
!"Yan-Hong Huang[MSFT]" <yh*****@online .microsoft.com> wrote in message
!news:0s******* *******@cpmsftn gxa06.phx.gbl.. .
!> Hello Robert,
!>
!> Thanks for your email.
!>
!> From MSDN, we could see that:
!>
!> The dllexport and dllimport storage-class attributes are
!Microsoft-specific
!> extensions to the C and C++ languages. They enable you to export and
!import
!> functions, data, and objects to and from a DLL.
!>
!> These attributes explicitly define the DLL's interface to its client,
!which
!> can be the executable file or another DLL. Declaring functions as
!dllexport
!> eliminates the need for a module-definition (.DEF) file, at least with
!> respect to the specification of exported functions. Note that dllexport
!> replaces the __export keyword.
!>
!> If a class is marked declspec(dllexp ort), any specializations of class
!> templates in the class hierarchy are implicitly marked as
!> declspec(dllexp ort).
!>
!> The declaration of dllexport and dllimport must use extended attribute
!> syntax and the __declspec keyword.
!>
!> Based on my experience, dllexport is there to avoid def files. When you
!> dllexport a __stdcall function it is exported alongwith the name
!> decoration. Thats the @ stuff after your function name.
!>
!> For functions that you export via dllexport and import via dllimport and !if
!> both use the same compiler you shouldn't have problems with the
!decoration.
!> With a def, the export happens with the name you provided in the def
which
!> happens to be without name adornation. You could check the difference by !> using Depency tool in Visual Studio 6.0 -> Tools.
!>
!> Does that answer your question?
!>
!> Best regards,
!> Yanhong Huang
!> Microsoft Online Partner Support
!>
!> Get Secure! - www.microsoft.com/security
!> This posting is provided "AS IS" with no warranties, and confers no
!rights.
!>
!> --------------------
!> !Reply-To: "Robert A Riedel" <ra******@beckm an.com>
!> !From: "Robert A Riedel" <ra**********@b eckman.com>
!> !Subject: C4251 Compiler Warning: How Do I Remediate?
!> !Date: Tue, 23 Sep 2003 15:37:22 -0700
!> !Lines: 73
!> !Organization: Beckman Coulter
!> !X-Priority: 3
!> !X-MSMail-Priority: Normal
!> !X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!> !X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!> !Message-ID: <#F************ *@TK2MSFTNGP09. phx.gbl>
!> !Newsgroups:
!> microsoft.publi c.dotnet.langua ges.vc,microsof t.public.vc.lan guage
!> !NNTP-Posting-Host: 64-162-186-125.ded.pacbell .net 64.162.186.125
!> !Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
!> !Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.vc.language:1 98187
!> microsoft.publi c.dotnet.langua ges.vc:28638
!> !X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vc
!> !
!> !I have a class that is intended to be exported in a DLL that uses
another
!> !class that is in a static library. All clients that use the DLL will
also
!> !link with the same static library. In summary, the following condition
!> !exists:
!> !
!> !class A {} ; // Instantiated in the static library and specified
!> ! // in a header included by all clients.
!> !
!> !//
!> !// This is the class using A that is exported by a DLL.
!> !//
!> !class __declspec( dllexport ) B
!> !{
!> ! public :
!> ! B( const A & ) ;
!> !
!> ! const A &
!> ! value( void ) const ;
!> !
!> ! private :
!> ! A _a ;
!> !} ;
!> !
!> !Of course, the implementation of class B is not shown, and class A
!> !has other members, so the entire example is greatly simplified, however, !> !compilation of code similar to this always results in a C4251 warning
!> !being issued on any line where a type of class A is referenced by a
class
!> !using the dllexport attribute.
!> !
!> !The question to be posed is how does one eliminate the C4251 warning
!> without
!> !re-declaring class A using the dllexport directive. The intent is not to !> !export
!> !this class in any DLL since it is to be resolved at link-time, not
!> !run-time -- that
!> !is: all clients using class A must use the appropriate header and link
!with
!> !the
!> !static library.
!> !
!> !NOTE: This message was posted to both the dotnet.language s.vc and
!> !vc.language newsgroups.
!> !
!> !--
!> !============== =============== =============== =============== ===========
!> !============== =============== =============== =============== ===========
!> !==
!> !== Bob Riedel
!> !== Beckman Coulter, Incorporated
!> !== PO Box 8000 W-529
!> !== 200 S Kraemer Blvd
!> !== Brea CA 92822-8000
!> !==
!> !== Email 1: ra******@beckma n.com
!> !== Email 2: ra******@mindsp ring.com
!> !==
!> !==
!> !== The opinions expressed are my own, and do not necessarily represent
!> !== those of Beckman Coulter, Inc.
!> !==
!> !============== =============== =============== =============== ===========
!> !============== =============== =============== =============== ===========
!> !==
!> !== "Effective education is the key to successful democracy."
!> !==
!> !== "Criticizin g the actions of others offers so little risk, and
!> !== requires so little effort that it is, without exception, the tool
!> !== of the lazy and of the foolish -- who have neither the intelligence
!> !== to discover, nor the discipline to pursue, a realistic
!> !== alternative."
!> !==
!> !============== =============== =============== =============== ===========
!> !============== =============== =============== =============== ===========
!> !
!> !
!> !
!>
!
!
!

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4862
by: Nahappan SM | last post by:
I have a struct : #include <string> struct __declspec (dllexport) FILEPROPERTIES { std::wstring FileName; std::wstring Type; };
7
1600
by: Alfonso Morra | last post by:
I cannot believe how convoluted it is to export function templates and class templates from a shared library (or DLL as it is called in the Windoze world). Micro$oft support for STL and standards in general is absolutely appaling. This is absolutely ridiculous. I have obtaind links from people who tried to help me solve this problem, several days ago, to no avail. Even the sample code at http://support.microsoft.com/kb/q168958/ when...
2
31670
by: Siemel Naran | last post by:
I keep getting warning messages like these: ....\include\myfile.h(451) : warning C4251: 'MyClass::m_myvariable' : class 'CPtrArray' needs to have dll-interface to be used by clients of class 'MyClass' D:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\af xcoll.h(367) : see declaration of 'CPtrArray' How can I get rid of the warnings.
0
863
by: Bart Simpson | last post by:
I am writing a shared object (Dll in Windows) and I am making extensive use of the STL. I am getting lots of warnings like this: ClassA.h(139): warning C4251: 'ClassA::indexarray' : class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'ClassA' with
6
2389
by: Bart Simpson | last post by:
I am writing a shared object (Dll in Windows) and I am making extensive use of the STL. I am getting lots of warnings like this: ClassA.h(139): warning C4251: 'ClassA::indexarray' : class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'ClassA' with
13
2285
by: Anonymous | last post by:
On MS site: http://msdn2.microsoft.com/en-us/library/esew7y1w(VS.80).aspx is the following garbled rambling: "You can avoid exporting classes by defining a DLL that defines a class with virtual functions, and functions you can call to instantiate and delete objects of the type. You can then just call virtual functions on the type."
6
4599
by: =?Utf-8?B?RmFiaWFu?= | last post by:
Hello, I have a class hierarchy distributed over 3 native C++ dlls. The base class has a .NET Windows.Form for status output via a gcroot<>. The gcroot is declared private - the sub classes only have access via a protected "print"-method. I need the different dlls as the sub classes implement the base class's pure virtual methods using different technologies. To use the native classes from outside their dlls I use the...
0
10768
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10475
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10520
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9309
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6940
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5614
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5774
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4408
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.