|
No. Memory allocated by GlobalAlloc is not visible to other process. If you want to share memory across process, i sugest that you use memory mapped files.
Also, MSDN state that GlobalAlloc is not the preferred way to allocate memory. Try the heap memory function instead (HeapAlloc, HeapFree, ect,ect).
|
|
|
|
|
Ok, I will use memory mapped files.
Thank you!
-Dominik
|
|
|
|
|
When you call ::CreateFileMapping with (HANDLE) LongToHandle(-1) as the first parameter, PAGE_READWRITE as the protection and a name, which is how other applications will access it by calling OpenFileMapping . If the creator will be in one set of permissions (like a service logged in as an administrator) and the other application will have lower permissions, you'll need to create and use SECURITY_ATTRIBUTES (you can create a NULL security attribute which essentially grants global rights to the memory.)
|
|
|
|
|
Hi,
I have a problem splitting up a string.
I have a thread which will send a string to my main thread by posting a message.
I therefore create my string
<br />
CString *s = new CString();<br />
s->Format("%s#@@#%s", _T("Error"), _T("ErrorMessage"));<br />
PostMessage(UWM_SENDSTRING, (WPARAM)i, (LPARAM)s);<br />
The code is successfully received by my function.
However, here is where it goes wrong.
<br />
LRESULT CMyView::OnSendString(WPARAM wparam, LPARAM lparam)<br />
{<br />
CString *s = (CString*)lparam;<br />
TRACE0(*s);
<br />
int pos = s->Find(_T("#@@#"));
TRACE0(s->Left(pos));
TRACE0(s->Right(s->GetLength()-(pos+4)));
<br />
delete s;<br />
<br />
<br />
So basically when I show the string, compute a position or show the length of *s everything is fine.
When I just want a part of the string, the first or last, I get a lot of crap or the program just crashes.
When I do all of that splitting in a normal procedure whit normal CString (not dynamically allocated), I get the results thaat I want, namely he part before #@@# and the part after that.
Any ideas how I can let this Left/Right splitting thing work on dynamic CStrings?
tia
Wim
|
|
|
|
|
Try setting a watchpoint (breakpoint on a data address) on s after you create it, and before the PostMessage call. It sounds like something else is modifying it. Also, have you single stepped through the OnSendString function, and watched the contents of s in the Watch window?
Software Zen: delete this;
|
|
|
|
|
I don't think what you are doing is allowed, in effect posting a class, I am sure someone will confirm/deny that, so why not do:-
CString *s = new CString();<br />
s->Format("%s#@@#%s", _T("Error"), _T("ErrorMessage"));<br />
TCHAR *sz = new char[s.GetLength() + 1);<br />
strcpy(sz, s->GetBuffer(0));<br />
PostMessage(UWM_SENDSTRING, (WPARAM)i, (LPARAM)sz);
Note the code is not 100% correct, e.g. strcpy should not be used if you are using UNICODE
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
This is probablya bit late (its a public holiday down here in Australia, but I got suckered into coming into the office anyway)
anyway, see this link for an explanation and working code on posting CStrings (look for "Passing Pointers in Messages") - Note well one of Joe's comments "However, if you ever plan to use PostMessage to pass a pointer to an object, then you are constrained to always use a static or heap-based object"
http://www.pgh.net/~newcomer/messages.htm[^]
Hope this helps ...
'G' <- Grinch !!!
|
|
|
|
|
Hi Garth,
Thanks for the advice.
Strangely enough, the piece of code I posted comes from another essay of Mr. Newcomer I read about threads[^].
There was a reference to the article you mentioned. So probably I missed something reading the articles, or I'm just a bad cut&paste person.
I will read these articles again tonight and see if I missed something, else I just send 2 messages (errorcode and errormessage) as it seems to work (Using watch variables) if I don't tamper around with the strings.
Thanks and enjoy your holiday
Wim
|
|
|
|
|
Wim Jans wrote:
) if I don't tamper around with the strings
Hi Wim - I think it comes down to that particular phrase ... when I worked in San Diego recently I worked on a project that had to modify a CString .. yuck !!! there's a particular set of hoops you have to go through - something like CString.ReleaseBuffer().. I think this is also discussed by Joe Newcomer, under his MVP tips 'CString Management' ... its still a pain in the rear though
good luck !
|
|
|
|
|
i am using SDI MFC application. i am trying to generate many modeless dialogs in child style at the same time to display drawen charts.i use it in child styleso i can apply cascadewindows(....) function. but that leads that the dialogs is misdrawed.it's fine in pop style but i can't make it cascaded or tiled. how can i do so??????????
|
|
|
|
|
Hi, everyone!
I have two samples on CRITICAL_SECTION, I want to know
the difference between them.
Sample 1:
--------
CRITICAL_SECTION cs;
EnterCriticalSection(&cs);
//code block1
LeaveCriticalSection(&cs);
EnterCriticalSection(&cs);
//code block2
LeaveCriticalSection(&cs);
--------
Sample 2:
--------
CRITICAL_SECTION cs1;
CRITICAL_SECTION cs2;
EnterCriticalSection(&cs1);
//code block1
LeaveCriticalSection(&cs1);
EnterCriticalSection(&cs2);
//code block2
LeaveCriticalSection(&cs2);
--------
I think in sample 1, code block 1 and code
block 2 can not be executed simultaneously.
But I sample 2, code block 1 and code
block 2 may be executed simultaneously.
Am I correct?
Thanks in advance,
George
|
|
|
|
|
George2 wrote:
CRITICAL_SECTION cs1;
CRITICAL_SECTION cs2;
EnterCriticalSection(&cs1);
//code block1
LeaveCriticalSection(&cs1);
EnterCriticalSection(&cs2);
//code block2
LeaveCriticalSection(&cs2);
hi george
EnterCriticalSection() is a blocking function, that will only returns when the calling thread get the ownership.your examle code doesnot excecuet simultaniosly
If u wanna that
use TryEnterCriticalSection() API, that will returns immediatly
~CodeTheDreams~
|
|
|
|
|
Thanks, Renjith pal!
In such case,
1. Thread 1 enters code block 2, before it leaves code block 2,
for some reason, it sleeps;
2. Thread 2 enters code block 1;
3. for some reason, thread 1 wakes up and run code block 2,
So in my case, code block 1 and code block 2 could run simultaneously.
Am I correct? But in my sample 1, such case would not happen.
I am not sure about my two samples, so I want to listen to others.
Thanks in advance,
George
|
|
|
|
|
George2 wrote:
But I sample 2, code block 1 and code
block 2 may be executed simultaneously.
In different threads, yes.
It's like a mutex with a twist - you can reenter an already entered critical section from within the same thread.
|
|
|
|
|
Thanks, Mike pal!
Do you mean my original opinion about two cases
are correct?
Cheers,
George
|
|
|
|
|
yes (i.e. yes it's correct, and yes I guess that is what Mike means)
The main difference between a mutex and a critical section is that a CS is bound to a process, while a mutex can be used cross-process.
It's a royal pain to watch a sex drugs and rock'n'roll design decay into an aids crack and techno implementation [sighist] [Agile Programming] [doxygen]
|
|
|
|
|
Thanks, peterchen pal!
George
|
|
|
|
|
My program gets the following error sometimes under Window Me.
-----------------------------------------
Inaccurate System Timer
Restart after reset of system timer
Press Enter to End.
-----------------------------------------
Is there an explanation why this happens?
Thanks in advance.
Edwin Geng
|
|
|
|
|
Edwin, you need to post more information. Is this a message from your application? Is it a message from the operating system? What happens if you press Enter? What are the circumstances when you get the error, and when you don't get the error?
Software Zen: delete this;
|
|
|
|
|
Why do I get this error how do I correct it?
I looked in the help files and tried their suggestiong, but they didn't work.
Thanks...!
|
|
|
|
|
La doc nous dit que :
Static Library Versions Library Description
NAFXCW.LIB Release version
NAFXCWD.LIB Debug version (default)
UAFXCW.LIB Release version with Unicode support
UAFXCWD.LIB Debug version with Unicode support
Il faut la version PRO de Visual Studio pour compiler en Static
|
|
|
|
|
Windows ME
Visual C++ 6.0
Hi!
I need to get/set the attibutes and date/time of directories.
I tried the win32 functions GetFileTime & SetFileTime. For this functions I need a handle to the directory.
HANDLE handle = CreateFile(
"C:\\TEMP",
GENERIC_READ, //for GetFileTime
0, //don't share
NULL, //no SECURITY_ATTRIBUTES
OPEN_EXISTING,
FILE_NORMAL, //also tried FILE_ATTRIBUTE_DIRECTORY
//and & FILE_FLAG_BACKUP_SEMANTICS
NULL);
I always get INVLID_HANDLE_VALUE, GetLastError returns 5.
How to get a handle in Win 95-98?
Thanx
|
|
|
|
|
Peppe wrote:
FILE_FLAG_BACKUP_SEMANTICS
Isn't that an NT-only flag?
If so, I believe you have to resort to the old DOS-ish INT 21h interface ("documented" in MSDN) - no promises that what you want to do is supported there though.
|
|
|
|
|
Hi,
since I'm not vey dedicated to GUI programming and it is in some cases necessary, I was seeking the way to make GUI in my applications faster, which I was writting directly through API, but not to use any RAD tool.
I started to learn MFC which is very (not to say hard ) opaque to me, maybe because I used to do programming in API directly or something else.
Friend of mine, suggested me to use WTL to make GUI faster, which is (in his opinion, I don have one yet ) much better in any aspect regarding MFC.
So, I've downloaded WTL 7.0 from MS site, but not to count add-in wizard in VC I don't know where to start from, for learning to do programming using this library. I've found one .chm file on this subject but it was corrupted, and nothing else.
So my question is, can anyone help to get start, firstly by informing me where can I find some good free documentation on this subject and a good tutorial to understand better WTL and to begin my programming very soon independantly.
Thanks.
|
|
|
|
|
try this :
http://perso.wanadoo.fr/laurent.kempe/technical/wtl/
|
|
|
|