473,785 Members | 2,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(dlle xport) 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: 'UnmanagedCompo nent::m_pFormDe bugOutput' : struct 'gcroot<T>'
needs to have dll-interface to be used by clients of class
'UnmanagedCompo nent'

where "UnmanagedCompo nent" is my base class and "m_pFormDebugOu tput" is the
"private"-declared gcroot<of type Windows.Forms.F orm.

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 4597
The warning doesn't matter unless some inline member function of
UnmanagedCompon ent (or its derived classes) uses pFormDebugOutpu t 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****@discuss ions.microsoft. comwrote in message
news:39******** *************** ***********@mic rosoft.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(dlle xport) 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: 'UnmanagedCompo nent::m_pFormDe bugOutput' : struct 'gcroot<T>'
needs to have dll-interface to be used by clients of class
'UnmanagedCompo nent'

where "UnmanagedCompo nent" is my base class and "m_pFormDebugOu tput" is the
"private"-declared gcroot<of type Windows.Forms.F orm.

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(dlle xport) gcroot<FormDebu gOutput^>;

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

warning C4091: '__declspec(dll export)' : 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(dlle xport) gcroot<FormDebu gOutput^>;

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

warning C4091: '__declspec(dll export)' : 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_p tr, the penalty is minimum (almost nothing; the compiler adds
only one instruction). If you use boost::shared_p tr 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_p tr. If your class is copyable you have to use boost::shared_p tr
--
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****@discuss ions.microsoft. comwrote in message
news:11******** *************** ***********@mic rosoft.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****@discuss ions.microsoft. comwrote in message
news:D6******** *************** ***********@mic rosoft.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(dlle xport) gcroot<FormDebu gOutput^>;

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

warning C4091: '__declspec(dll export)' : 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
4307
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
3231
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 writing one object in C# which will take the entire table tag contents and renders. Ie., we need to pass "<table>………… <thead>……</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
0
334
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 COM. I'm attempting to develop an ATL wrapper to expose a COM interface to a .NET assembly (I don't want to have to sign the .NET assembly to expose directly).
5
2639
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 of a class _Temp_iterator tries to obtain the address of a gcroot, but fails because gcroot::operator& is private. -- Gerhard Menzl #dogma int main ()
0
1155
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 WebControl='<%= Me.Attributes("WebControl")%>' runat="server" ID="Skincontrolmanager1"/> anybody can help me!? tks!
1
2397
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. # explain SELECT date FROM album WHERE (date='1093989600'); Index Scan using date_album_key on album (cost=0.00..86.31 rows=21 width=8) Index Cond: (date = 1093989600::bigint)
4
2382
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 my own tool (http://openswarm.sourceforge.net). I already started restructuring my code to separate the actual command implementations from the command-line scripts (which is optparser-based now) and have some ideas how to proceed. But probably...
45
18904
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 of their elements? Why can't I change the element itself? class Program { private struct MyStruct
2
2059
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! Error: BC30456: 'Read_DOM' is not a member of
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
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
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
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
5381
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.