|
Thanks it's working.
Thanks once again...........
|
|
|
|
|
I'm glad I could help.
Shameless plug: May I please ask you to mark the helpful replies as "Good Answer" by clicking on the appropriate posts?
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
I have a dll that needs to share data among all instances. How can I accomplish this? I've tried a multitude of compiler-specific #pragma's (visual studio 2008 for anyone who's asking) and no matter what I do, I cannot share the variables across all instances.
MSDN says memory-mapped files are one of several solutions, so any info on that too would be welcome.
|
|
|
|
|
|
I've tried that, and it didn't work
I remember reading somewhere (on MSDN) that the #pragma data_seg() directive should not be used with classes that require deep copy constructors. Unfortunately, the data I want to share is an std::list.
The page you linked me to goes on to say "Because of these restrictions, Microsoft does not recommend sharing C++ objects between processes."
They also don't recommend sharing pointers, so what alternative do I have?
|
|
|
|
|
Sauce! wrote: They also don't recommend sharing pointers, so what alternative do I have?
In the same page:
In general, if you want to use C++ to share data between processes, write a class
that internally uses a memory-mapped file to share data, but do not share the class instances themselves. This might require special care in developing such a class, but it enables application developers to fully control the side effects of sharing data.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I guess I have a bit of reading to do, this sounds complicated
|
|
|
|
|
BTW, why do you need to share data across several instance of the dll ?
|
|
|
|
|
I guess (is just a guess) you may serialize objects in memory mapped files.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You can't share a std::list as it allocates nodes on the heap and uses pointers. Boost[^]'s Boost.Interprocess[^] library might be what you're looking for. Among its numerous features are containers like STL's but which can be shared between processes.
Steve
|
|
|
|
|
I use memory mapped files to do exactly this in several places in our [XP embedded based] system. (The trick is to use a mutex to ensure that only one instance does the initializing and the rest just open the memory mapped file.)
|
|
|
|
|
It's not particularly necessary that each instance of the dll share a particular variable - I could instead have each instance of the dll send a message to my application (which loads the dll) and have my app use the message to add the new value to the end of the list. How does that sound?
I'm attempting to simulate input latency by installing a keyboard and mouse hook that records all input, blocks it, and then resends it after a specified interval. I'll probably have trouble differentiating between messages I'm recieving from the system, and messages that I have forwarded after the appropriate interval, however that is a river I'll have to cross when I get to it.
So I guess I'll see what I can do about forwarding the messages directly to my application, where they will then be pushed onto a list (it should be a fairly trivial matter)
edit: is there any way at all I can send a message using the win32 SendMessage() along with some user data, like a flag? It would make my life a hell of a lot easier :P
|
|
|
|
|
Sauce! wrote: is there any way at all I can send a message using the win32 SendMessage() along with some user data, like a flag?
If your data is two DWORDs or less (and WPARAM and LPARAM), just use a WM_USER message or see RegisterWindowMessage(). If longer, use WM_COPYDATA.
|
|
|
|
|
Unfortunately the data is larger than a DWORD or two, and I'm not sure I can use WM_COPYDATA either, as MSDN advises against passing pointers between processes (and dll instances) - with COPYDATASTRUCT using pointers to do it's thing, it pretty much counts it out.
|
|
|
|
|
I am creating an background application which runs in the background, for that i want to know which key has been pressed by user. Right now, i am using this code:
while( 1 )
{
for( int i = 0; i < 256; i++ )
{
GetAsyncKeyState( i );
}
}
But, due to while( 1 ) other applications are hanging. Is there any alternative for GetAsyncKeyState( int ) function OR can i use the same function in another way?
|
|
|
|
|
You should use a global keyboard hook (see: "Using Hooks") for the purpose.
Are you writing a keylogger?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks for your reply Pallini. I was curious about how keylogger works and while searching, i got a keylogger code in c++. Now i am just trying to edit it, just for a learning purpose.
|
|
|
|
|
Here's some neat theory on hooks and DLLs and a practical example to illustrate it all, by Dr. Joseph Newcomer: Hooks and DLLs[^]
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
I see you already found a better way to do what you want, so this is just an "additional footnote" to your original problem: to make your while loop less CPU hungry you can add a Sleep(1) call somewhere inside it, or maybe use SwithToThread[^] (althorough SwitchTothread seems to be much less effective than Sleep), this way the loop yields execution to other threads and does not eat up all the CPU power. I mean something like:
while( 1 )
{
for( int i = 0; i < 256; i++ )
{
GetAsyncKeyState( i );
}
Sleep(1);
}
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
i have created two modeless dailog and invoking it in InitInstance().
That two dialog is displayed correctly.But what happened is, the second dialog creates icon in Taskbar like main applcation seperatley apart form main application.It has its own close,Move menu option.
How its possible.I posted my code below.
In InitInstance()
pMainFrame->AlarmBanner();
pMainFrame->ToolTab();
void CMainFrame::AlarmBanner()
{
CAlarmBanner *oAbanner;
oAbanner = new CAlarmBanner;
oAbanner->Create(IDD_ALARMBANNER,this);
oAbanner->ShowWindow(SW_NORMAL);
}
void CMainFrame::ToolTab()
{
CToolTab *otoolbar;
otoolbar = new CToolTab;
otoolbar->Create(IDD_TOOLBAR_DIALOG,this);
otoolbar->ShowWindow(SW_NORMAL);
}
BOOL CToolTab::OnInitDialog()
{
CDialog::OnInitDialog();
m_brush.CreateSolidBrush(RGB(173, 216, 230));
SetWindowPos(&CWnd::wndBottom,0,80,45,SystemDM.dmPelsHeight,SWP_SHOWWINDOW);
return TRUE;
}
BOOL CAlarmBanner::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowPos(&CWnd::wndBottom,0,0, SystemDM.dmPelsWidth, SystemDM.dmPelsHeight/12, SWP_SHOWWINDOW);
return TRUE;
}
Anu
|
|
|
|
|
The 2nd dialog may have the 'Application Window' property set TRUE. Check the dialog properties and make sure this value is set to FALSE.
L u n a t i c F r i n g e
|
|
|
|
|
Yes.
Thank you so much
Anu
|
|
|
|
|
Hi,
I edited OnGetMaxMininfo() function to change display size when i maximize the child window like below
int XBorder = GetSystemMetrics(SM_CXMAXIMIZED);
int YBorder = GetSystemMetrics(SM_CYMAXIMIZED);
lpMMI->ptMaxTrackSize.x = XBorder-50;
lpMMI->ptMaxTrackSize.y = YBorder-40;
It comes fine.But what i want is the position of window is from 50,50
Ex:
Left :50,Top:50,Width:XBorder-50,Height:Border-40
How can i get that?
I use
lpMMI->ptMaxPosition.x=50;
lpMMI->ptMaxPosition.y=50;
But no use?
Pls help me.
Anu
|
|
|
|
|
Cannot understand your question, could you please elaborate a bit?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Im my applcation constanly im placing one dialog at top of the screen.So if i maximize my child windows definetly quater of child frame will get hide behind the dialog.To overcome this problem i planed that when i maximize the child frame,then it maximized to full window but top of the window should below the dialog.
Can u understand my point.
Anu
|
|
|
|