473,378 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

warning C4251 using gcroot<> accross multiple native dlls

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
__declspec(dllexport) marco. This all works without any runtime error.

Still when the sub classes' dlls are compiled I get the following warning
(for each sub class):

warning C4251: 'UnmanagedComponent::m_pFormDebugOutput' : struct 'gcroot<T>'
needs to have dll-interface to be used by clients of class
'UnmanagedComponent'

where "UnmanagedComponent" is my base class and "m_pFormDebugOutput" is the
"private"-declared gcroot<of type Windows.Forms.Form.

What does this warning mean in this respect? Is there a solution to get rid
of it (apart from switching it off)?

Thanks a lot in advance. Regards,

Fabian
Nov 21 '07 #1
6 4542
The warning doesn't matter unless some inline member function of
UnmanagedComponent (or its derived classes) uses pFormDebugOutput in some way
other than a simple pointer reference. If it is the case (access member
functions through the pointer) you have to export gcroot<>

IMO the best solution is to use the pimpl idiom to get rid of private members
from the interface definition.

Regards

--
Cholo Lennon
Bs.As.
ARG
"Fabian" <Fa****@discussions.microsoft.comwrote in message
news:39**********************************@microsof t.com...
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
__declspec(dllexport) marco. This all works without any runtime error.

Still when the sub classes' dlls are compiled I get the following warning
(for each sub class):

warning C4251: 'UnmanagedComponent::m_pFormDebugOutput' : struct 'gcroot<T>'
needs to have dll-interface to be used by clients of class
'UnmanagedComponent'

where "UnmanagedComponent" is my base class and "m_pFormDebugOutput" is the
"private"-declared gcroot<of type Windows.Forms.Form.

What does this warning mean in this respect? Is there a solution to get rid
of it (apart from switching it off)?

Thanks a lot in advance. Regards,

Fabian

Nov 21 '07 #2
Hi Cholo,
If it is the case (access member functions through the pointer) you have to export gcroot<>
How would I do this in this case?

__declspec(dllexport) gcroot<FormDebugOutput^>;

in the header file makes the compiler produce the following message:

warning C4091: '__declspec(dllexport)' : ignored on left of 'gcroot<T>' when
no variable is declared
IMO the best solution is to use the pimpl idiom to get rid of private members
from the interface definition.
How much performance would this additional redirection cost? My design
already is performance consuming: Calling into the gcroot<should take at
least one context switch.

Thanks a lot for your help,

Fabian

Nov 22 '07 #3
How would I do this in this case?
>
__declspec(dllexport) gcroot<FormDebugOutput^>;

in the header file makes the compiler produce the following message:

warning C4091: '__declspec(dllexport)' : ignored on left of 'gcroot<T>' when
no variable is declared
To view an example of how to export a template take a look to:
http://support.microsoft.com/?scid=k...8958&x=12&y=10

The problem with dllexport is that it's incompatible with __clrcall convention
(used by clr objects) :-( so you cannot export a template with clr types (I
didn't know it until today). If you don't have inline functions that use use
gcroot<simply get rid the warning with #pragma or use pimpl idiom (or redesign
your classes to provide an interface based in abstract classes).
>
IMO the best solution is to use the pimpl idiom to get rid of private
members
from the interface definition.

How much performance would this additional redirection cost? My design
already is performance consuming: Calling into the gcroot<should take at
least one context switch.
It's depends of how you implement the pimpl idiom. If you use a raw pointer or
boost::scoped_ptr, the penalty is minimum (almost nothing; the compiler adds
only one instruction). If you use boost::shared_ptr the penalty increase. Just
take a look the generated asm code using a raw pointer:

class Foo {
...
void pimplCall();
void directCall();

ToCall m_toCall;

struct Impl;
Impl* m_pImpl;
...
};

struct Foo::Impl {
ToCall m_toCall;
};

pImpl call: m_pImpl->m_toCall.Test();
00401057 mov eax,dword ptr [this]
0040105A mov ecx,dword ptr [eax+4]
0040105D call ToCall::Test (401000h)

Direct call: m_toCall.Test();
00401077 mov ecx,dword ptr [this]
0040107A call ToCall::Test (401000h)
Regards

PS: [boost] Remember that If your class is non copyable you can use
boost::scoped_ptr. If your class is copyable you have to use boost::shared_ptr
--
Cholo Lennon
Bs.As.
ARG

Nov 22 '07 #4
Hi Cholo,
The problem with dllexport is that it's incompatible with __clrcall convention
(used by clr objects) :-( so you cannot export a template with clr types (I
didn't know it until today).
If you create a pure win32 dll with the VS wizard it has __stdcall
convention. Compiled with /clr you get a dll which can both use clr objects
via a gcroot<and export native classes that use a gcroot.
But then we're back to the beginning: The class export works, but the
compiler complains about the non-exported gcroot member.

thanks a lot for your help,

Fabian
Nov 23 '07 #5
Maybe this can help:

http://msdn.microsoft.com/msdnmag/issues/06/06/CAtWork/
http://www.thescripts.com/forum/thread285515.html

Regards
--
Cholo Lennon
Bs.As.
ARG
"Fabian" <Fa****@discussions.microsoft.comwrote in message
news:11**********************************@microsof t.com...
Hi Cholo,
The problem with dllexport is that it's incompatible with __clrcall
convention
(used by clr objects) :-( so you cannot export a template with clr types
(I
didn't know it until today).

If you create a pure win32 dll with the VS wizard it has __stdcall
convention. Compiled with /clr you get a dll which can both use clr objects
via a gcroot<and export native classes that use a gcroot.
But then we're back to the beginning: The class export works, but the
compiler complains about the non-exported gcroot member.

thanks a lot for your help,

Fabian

Nov 23 '07 #6

"Fabian" <Fa****@discussions.microsoft.comwrote in message
news:D6**********************************@microsof t.com...
Hi Cholo,
>If it is the case (access member functions through the pointer) you have
to export gcroot<>

How would I do this in this case?

__declspec(dllexport) gcroot<FormDebugOutput^>;

in the header file makes the compiler produce the following message:

warning C4091: '__declspec(dllexport)' : ignored on left of 'gcroot<T>'
when
no variable is declared
>IMO the best solution is to use the pimpl idiom to get rid of private
members
from the interface definition.

How much performance would this additional redirection cost? My design
already is performance consuming: Calling into the gcroot<should take at
least one context switch.
gcroot should not cause a context switch unless combined with Remoting.

pimpl's performance cost is a tiny fraction of a context switch, maybe
1/1000.
>
Thanks a lot for your help,

Fabian
Nov 23 '07 #7

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

Similar topics

7
by: R. Anbeeswaran | last post by:
Hi All, void main() { const int i = 20; int *p = const_cast<int*>(&i); *p = 40; cout <<"i="<< i <<"\t"<<"*p="<<*p<<"\n"; }
2
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
0
by: nmyatt | last post by:
Hi, The project I'm working on consists mainly of legacy VC6 C++ and VB, but we wish to write all new code in C#. So I'm looking at ways for exposing .NET functionality to VB and C++ through...
5
by: Gerhard Menzl | last post by:
Has anyone ever tried to sort a Standard Library container of gcroots? I have run into the problem that somewhere deep in the Library logic (in line 338 of <memory>, to be precise) the destructor...
0
by: clécio | last post by:
Hi folks! i developed a web custom control inherited from webcontrol, but when i try to bound a property using <%= %>, i have all the code put between de ' ! ex.: <uc1:SkinControlManager...
1
by: Marc Boucher | last post by:
I'm using PG 7.3.4 I've a table with a column of type int8 where I store date-based values, and an index exists for it. The problem is that the index is almost never used with the '>' test. #...
4
by: Anastasios Hatzis | last post by:
I'm looking for a pattern where different client implementations can use the same commands of some fictive tool ("foo") by accessing some kind of API. Actually I have the need for such pattern for...
45
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
2
by: -Karl | last post by:
Couls someone please advise me on this error. What I am trying to do is be able to convert an XML document into arrays. I read that the subs & functions have to be in <scripttags. Thanks! ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.