|
Hi,
I want to share an object which is use by differents applications. This object is instanciate only once in a DLL and all applications use this DLL (and the same object).
Thus this object must be visible on the level of the OS (win2k)
I've already try to map in a sharable memory (create in the DLL) this object and that works if I don't use pointer in it.
To create this sharable memory I use this code : CreateFileMapping(...) and MapViewOfFile(...)
My question: How to share an object on the level of the OS?
Thanks in advance...
Hello World!!!
from Raphaël
|
|
|
|
|
You can use a pointer inside of your Memory mapped file, you will just need to manager the memory yourself.
So if you create your initial object, then decide that you want to allocate 50 bytes for a string, you can place that 50 bytes anywhere in your memory mapped file, however you will need to keep track somehow that it is being used so you do not reallocate it for another pointer.
Another solution is to use your memory mapped files for you objects, and any pointers you could allocate with GlobalAlloc. This allows you to share the allocated pointers between processes, however you will need to lock the pointer in place for each process before you attempt to use it. This solution is a little more cumbersome than new, but it may be better for you than writing your own memory manager for the file mapping scheme.
One other thing, if you decide to do GlobalAlloc, you could make you one single object that is shared by all apps, in your single DLL, a global object inside of a shared data section. That would save you the trouble of setting up and deleting the memory mapped file.
You can declare a variable in a shared data section simply by declaring it like this:
<br />
#pragma comment(linker, "/SECTION:.shr,RWS")<br />
#pragma data_seg(".shr")<br />
OBJECT g_obj;<br />
#pragma data_seg()<br />
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Thanks for all...
But when I try to use the pragma code:
#pragma comment(linker, "/SECTION:.shr,RWS")
I've got a warning:
LINK : warning LNK4039: section ".shr" specified with /SECTION option does not exist
...
Hello World!!!
from Raphaël
|
|
|
|
|
I have more than one help file in different languages.
I want to call the help file accordingly the selected language.
How does it work?
|
|
|
|
|
Set the m_pszHelpFilePath member of CYourApp to appropriate value. Don't forget that this should be full path, not the filename only.
Tomasz Sowinski -- http://www.shooltz.com
*** Purgamentum init, exit purgamentum ***
|
|
|
|
|
I need to detect when the user moves the mouse out of one of my buttons while the mouse button is down in order to stop the process that has started when the user clicked the button.
I was receiving help from another member of codeproject but he is on holiday now .
do you know how the trakmouseevent api works and if so, could you give me an example of how it works?
I don't know where to place it, in the pretranslatemessage would be OK?
as always thank you very much.
|
|
|
|
|
This is code out of the WTL BitmapButton:
MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
MESSAGE_HANDLER(WM_MOUSELEAVE, OnMouseLeave)
LRESULT OnMouseMove(UINT , WPARAM , LPARAM lParam, BOOL& bHandled)
{
if(::GetCapture() == m_hWnd)
{
POINT ptCursor = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
ClientToScreen(&ptCursor);
RECT rect;
GetWindowRect(&rect);
unsigned int uPressed = ::PtInRect(&rect, ptCursor) ? 1 : 0;
if(m_isPressed != uPressed)
{
m_isPressed = uPressed;
Invalidate();
UpdateWindow();
}
}
else if(0 == m_isMouseOver)
{
m_isMouseOver = 1;
Invalidate();
UpdateWindow();
StartTrackMouseLeave();
}
bHandled = FALSE;
return 1;
}
LRESULT OnMouseLeave(UINT , WPARAM , LPARAM , BOOL& )
{
if(1 == m_isMouseOver)
{
m_isMouseOver = 0;
Invalidate();
UpdateWindow();
}
return 0;
}
BOOL StartTrackMouseLeave()
{
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = m_hWnd;
return _TrackMouseEvent(&tme);
}
I hope this helps.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
If I understand you correctly, and if you are using a "normal" button control, you should be able to use the BM_GETSTATE message to determine if the button is "down" or not. This could easily be checked during mouse movement messages.
(As an aside...)
However, if I do understand you correctly, you are doing some action when the user depresses a button, but not when they release it, which is counter to how the button control is designed to work.
The usual exceptions to this are things like "repeating buttons", like if you were simulating how pressing and holding a scroll button works. (BTW: many implementations of "repeating buttons" are broken and fail to use the button state correctly, and continue to fire if you move the mouse off the button while keeping the mouse-button down.)
Peace!
-=- James (Sonork:100.21837)
"There is nothing worse than being oblivious to the fact that you do not know what you are doing."
[Get Check Favorites 1.5 Now!]
|
|
|
|
|
Ok, I ran into this a while back and never solved it correctly. Now, I'm trying to draw images with transparency again and this problem is really eating away at me. No matter how hard I try, I can not seem to get a CImageList to draw correctly using a bitmap for the mask.
From what I've read in the MSDN help, it seems it'd be as easy as this:
CImageList tbImgList;
CBitmap tbBMP_Color;
CBitmap tbBMP_MASK;
POINT pt;
// Create the Image List
tbBMP_COLOR.LoadBitmap ( IDB_MYPICTURE_COLOR );
tbBMP_MASK.LoadBitmap ( IDB_MYPICTURE_ALPHA );
tbImgList.Create ( 64, 64, ILC_COLOR24 | ILC_MASK, 0, 0 );
tbImgList.Add ( &tbBMP_COLOR, &tbBMP_MASK );
// Draw the Image List at 0,0
pt.x = 0;
pt.y = 0;
tbImgList.Draw( &dc, 0, pt, ILD_TRANSPARENT );
But that doesn't work?! Am I missing something here or is this thing just plain broken?
-John
"Ask me about my vow of silence"
|
|
|
|
|
It would certainly help if you'd check return codes from Create and Add. And, you could be more specific about "doesn't work" part - there's nothing on the screen or you have problem with transparency.
A wild guess - try to change last param in Create call to non-zero.
Tomasz Sowinski -- http://www.shooltz.com
*** Purgamentum init, exit purgamentum ***
|
|
|
|
|
>>It would certainly help if you'd check return codes from Create and Add.<<
Ahh yes, I should've checked those. Create returns 1 for success, which is expected. Oddly enough however, Add returns -1 no matter what I do, even though it seems to succeed. According to MSDN it should be returning the zero-based index of the first new image if successful...odd.
>>And, you could be more specific about "doesn't work" part - there's nothing on the screen or you have problem with transparency.<<
Ah, right. Sorry about that. Yeah, they were drawing fine, just not using any transparency.
Well anyway, I was finally able to get it to work.....or at least kind of. As it turns out, I had mistaken what exactly a mask bitmap means. I thought that it meant it allowed for a nice 256 levels of alpha transparency masking. Instead, it appears to really work as an on/off mask. Apparently the transparent areas in my mask bitmaps were something like 253, 253, 253 and thus it saw them as opaque. It looks like 255,255,255 is transparent and anything else is opaque.
Unfortunately, that's not what I was after. Does anyone happen to know of a nice(and efficient!) way to do true variable transparency drawing?
-John
"Ask me about my vow of silence"
|
|
|
|
|
Hi, I'm writing application for PDA to communicate with a PC server.
After the dial-up connection is established, i purposely disconnect
the connection, but my program can't detect it and just happily tries
to send/receive data. I even suspect that recv() never returns after
connection is gone. So my questions are: how to detect whether
network is available(i think IE does a good job)? and is it true that
recv() can't return when network is gone? if so, how to recover?
Thanks a lot!!!
Wenrich
|
|
|
|
|
:(Can you tell me how to vectorize a bitmap,thanks!
Beth B.Yang
|
|
|
|
|
only this ? anything else ? it's no small feat.
I suggest you look for the catmull-rom algo. in the book "computer graphics :principles and practice" by vandam, foley, feiner, hughes.
Catmull is used to fit points onto a curve, for example, when drawing with a mouse, or a graphic pen, use the points to generate a curve.
but first you must filter out the bitmap, with combinations of contrast, edge detection, and other filters like that.
Max.
|
|
|
|
|
Thank you for your help
What I am doing is sharpen the bitmap edge and save it as vector format.Which may involve edge detect and image partition,and also the bitmap vectorize.Hopes your help.
Thank you
|
|
|
|
|
Hi Folks
Re: ADO.NET : SqlDataReader : I need to assign retrieved value to C++ variable
I have found the source of the problem expressed in the thread "ADO.NET : SqlDataReader : I need to assign retrieved value to C++ variable":
http://www.codeproject.com/script/comments/forums.asp?forumid=3785#xx309754xx
but do not yet know why it occurs or how I can fix it.
The problem arises with the /clr compiler setting.
Here is the code to illustrate this:
/////////////////////////////////////////////////////////
#include <stdafx.h>
#include <cstdlib>
#include "try_ADONET.h"
//#using <mscorlib.dll>
//#using <system.dll>
//#using <system.data.dll> // This is required for the ADO.NET Provider
using namespace std;
//using namespace System;
int Main()
{
CString busNumberSQL[2];
CString bus = "Hello";
busNumberSQL[1] = bus;
return 0;
}
////////////////////////////////////////////////////////
Without the /clr setting the array of CString busNumberSQL[2] is correctly contructed as is CString bus and the line
busNumberSQL[1] = bus;
works as expected. This can be seen by putting a breakpoint in at
return 0;
and seeing the variables in a Watch. Copy the expanded Watch details (Name, Value & Type) to an EXCEL sheet.
..................
Next, add the compiler switch /clr and rerun the code.
CString bus is constructed correctly BUT something weird happens in the construction of CString busNumberSQL[2].
Now,
busNumberSQL[1] = bus;
results in the address of bus as an integer being assigned to busNumberSQL[1], and look at the Watch details!!
Copy the expanded Watch details (Name, Value & Type) to an EXCEL sheet
Name: busNumberSQL; Value: {Length=2}; Type: ATL::CStringT<char,strtraitmfc<char,atl::chtraitscrt<char> > >[] ...(Note no dimension at end compared to the "no /clr" case.
Next Watch line: [0] 2083454756 __int32
Next Watch line: [1] 3103464 __int32
My conclusion is that busNumberSQL[2] is not an array of CString.
Of course, I need the /clr in order to use ADO.NET!
It seems as though a CString works, but a CString array for some (unknown) cannot even be defined.
Do you have any light for me? (I have not got into your previous post yet on Marshall)
Best regards
Doug.
(In case you are wondering I am very much a beginner with C++ and .NET)
Doug
|
|
|
|
|
|
I just installed the Platform SDK (Aug 2002) on my system (Win2000 SP3) and have pointed VC++ (still using 6.0, I'm afraid!) to it. My build dies because a source file references ::SHAutoComplete() .
I get an "undefined function" error, which makes sense because my shlwapi.h doesn't contain a prototype for the function, inspite of the fact that the Platform SDK and MSDN docs both say I need to #include shlwapi.h and link with shlwapi.dll . I'm using shlwapi.dll version 6.0.2800.1106, which exceeds the 5.0 minimum requirement.
What am I doing wrong?
A CP article by Chris Losinger wraps ::SHAutoComplete() by dynamically loading its address from shlwapi.dll , but it seems I shouldn't have to do this, since the code did (supposedly) compile at one point (on someone else's machine). I'm off to find an alternate shlwapi.h ...
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
i find that function on shlwapi.h, i have too the sdk from august. its in the line 1236.
LWSTDAPI SHAutoComplete(HWND hwndEdit, DWORD dwFlags);
i dont know if this can help you.
|
|
|
|
|
#define _WIN32_IE 0x0500 before all your #includes in stdafx.h. This lets you use IE 5 features
--Mike--
"I'd rather you just give me a fish today, because even if you teach me how to fish, I won't do it. I'm lazy." -- Nish
Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Thanks guys, I found it in the latest version of shlwapi.h , which interestingly enough, didn't seem to get installed when I installed the Platform SDK (core components and MDAC only).
Thanks for your replies!
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Does inline member functions still increase performance ? doesn't the compiler optimize this for us now ?
|
|
|
|
|
inline is an indication to the compiler that it can inline a function, but it is up to the compiler whether the inlining takes place or not. If the compiler is smart eonugh, it can decide not to inline an inline function if it deems it inappropriate (the code is too big, the functions is recursive, etc.), although you shouldn't rely on the compiler wisdom with respect to this subject and happily prefix inline to every function. So, choose carefully what functions you decide to declare as inline .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Inlining absolutely improves performance.
I wrote a program that analyzes satellite switch ring states (we're talking about billions to trillions of possible states here), and inlining improved the algorithm efficiency by 25%.
Turn off incremental linking and "debug and continue", as this injects an additional JMP instruction for every function in your code (a layer of abstraction that makes it easier to patch in new code).
Read everything you can find about the compiler's optimization switches. Some of these are not intuitive, some of them conflict with others. Look at the differences at the assembly language level.
Finally, experience has shown me that I'm hardly ever right about where I think the program is slowing down (and I think I'm a darn good programmer, especially knowing assembly language and being able to root around at that level). Use a code profiler or add profiling in to your code yourself!
Marc
|
|
|
|
|
Ok, is the standard heap manager thingy able to cope with a fragmented heap?
An intelligent heap manager might add a performance hit, but be able to deal with a fragmented heap without failing completely.
Do I have to write my own to get this functionality?
Basically, we have an object cache in our code. When memory gets tight, we throw away some of the cached data. At some point in the future, the new operator throws an exception saying no memory available despite us having at least 1.5G available (big machine). Does this make sense?
J
|
|
|
|
|