|
Thanks. I think you are right.
|
|
|
|
|
Why not have a class with std::vector as a public member, and some interface functions for the other stuff you want to do? Or will that somehow defeat the purpose?
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
It would break a lot of existing code. This template class (which I need to reimplement) must have exactly the same interface as std::vector plus several extra functions.
|
|
|
|
|
I want to change the screen saver without any message to user? Can u help me out?
Mahesh
|
|
|
|
|
I've looked into this with no success....I'm not sure if it's possible....
|
|
|
|
|
Hello,
is the memory allocated by the GlobalAlloc function really global? Can different processes access the same memory block allocated by GlobalAlloc?
Thanks
-Dominik
|
|
|
|
|
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;
|
|
|
|