Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 4th, 2003, 08:36 AM
Registered User
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Shared data in DLL

I am employing a system-wide CBT hook that needs to respond to certain Windows messages and to inform a single instance of a 'Handler'. The hook works fine globally but of course each instance of the DLL (i.e. for each process it gets injected into) has its own 'Handler'.

I have tried to make the Handler object 'shared' through the following code:

#pragma comment(linker, "/SECTION:.SHARED,RWS")
#pragma data_seg(".SHARED")
HHOOK hHookCbt = 0;
Handler handler;
#pragma data_seg()


This doesn't seem to work though (I believe that objects may not be sharable, only primitive data types?) so perhaps file mapping might be the answer.

Does anybody have any ideas and/or suggestions on how to go about this please?

Thanks,

Chris.
Reply With Quote
  #2 (permalink)  
Old June 5th, 2003, 08:58 AM
Registered User
 
Join Date: Jun 2003
Location: Curitiba, , Brazil.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What you mean by not working?
Could you post some compilable code?

Josué Andrade Gomes
Reply With Quote
  #3 (permalink)  
Old March 30th, 2006, 08:06 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

According to
http://msdn2.microsoft.com/en-US/library/h90dkhs0(VS.80).aspx

the data in shared section have to be initialized. It means STATICALLY assigned in source code, the compiler inserts this initialization directly to the compiled DLL. So you cannot share objects this way...



-----------------
http://www.ubytujnas.cz
Reply With Quote
  #4 (permalink)  
Old April 18th, 2006, 11:29 AM
Registered User
 
Join Date: Apr 2006
Location: Poole, Dorset, United Kingdom.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can share objects in a shared section, but you have to be sneaky to do it by using placement new:

Code:
#pragma comment(linker, "/SECTION:.SHARED,RWS")
#pragma data_seg(".SHARED")
HHOOK hHookCbt = 0;
static BYTE buffer[sizeof(Handler)] = {0};
#pragma data_seg()
// each process gets its own copy of the pointer:
static Handler* pHandler = NULL;
...
// In the first process to load the dll, create the single shared handler using placement new:
pHandler = new (buffer) Handler;
// subsequent processes just cast the pointer:
pHandler = reinterpret_cast<Handler*>(buffer);
The destructor won't get called automatically using this mechanism, so if you need it to run, call it explicitly when the last process exits:
Code:
pHandler->~Handler();
Ian
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Missing System.Data.SQLClient dll mike_abc VB.NET 2 June 3rd, 2011 10:18 PM
Shared Data source Vs connection on report level mverma4you Reporting Services 0 June 6th, 2007 01:47 AM
Can't Reference System.Data.dll (ch 2, ex 1) Moonpile BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 4 January 8th, 2007 02:44 PM
xmlhttp requesting data from a dll in .net millennium Classic ASP XML 0 June 23rd, 2004 07:36 AM



All times are GMT -4. The time now is 09:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.