|
How about using SendMessage to send the WM_COMMAND message with the ID of the button to the button's parent window, or even better, invoke the handler with a simple function call.
Steve
|
|
|
|
|
doorprize wrote: Is it a matter of sending a message from the button function, saying here is Ctrl 1 but how do you code that?
you could you SendInput api
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
My thanks to the guys who found the time to help me with this. It led me on a search to look at the ways this could be done. I was thinking C with something like, putchar(c), shows you how little I know about MFC, but to answer my own question, Paul DiLascia has written a great example of using SendInput which others might be interested in. It can be found at:
http://msdn2.microsoft.com/en-us/magazine/cc163867.aspx
|
|
|
|
|
Hello everyone,
The space in string should use heap address memory space, not stack, right? But through debugging, for example,
string str = "hello";
why I can not see the invocation of new operator? Anyone could point out where STL string class allocates space on heap and using which function to allocate please (any other approach other than using new to allocate space on heap?)?
thanks in advance,
George
|
|
|
|
|
Most implementations of std::string have a smallish stack allocated buffer which is used for strings small enough to fit into it. Try assigning a much longer string and see what happens.
<blockquote class="FQ"><div class="FQA">George_George wrote:</div>Anyone could point out where STL string class allocates space on heap</blockquote>
Its done through the allocator. By default for a std::string this will be
allocator<char>
In my version of Visual Studio the actual call to new is around line 44 in the header file "xmemory"
|
|
|
|
|
Hi Josh,
I doubt your below comments. If the space is allocated on stack,
1. How do you deal with global object instance? There is no global stack or something, right?
2. How do you pass one string object instance from one function to another -- safely to ensure address space is valid?
Josh Gray wrote: Most implementations of std::string have a smallish stack
regards,
George
|
|
|
|
|
Hello George,
Im not sure I understand your questions
<blockquote class="FQ"><div class="FQA">George_George wrote:</div>1. How do you deal with global object instance? There is no global stack or something, right?</blockquote>
There is only one stack, you can consider it a global stack I guess
<blockquote class="FQ"><div class="FQA">George_George wrote:</div>2. How do you pass one string object instance from one function to another -- safely to ensure address space is valid?</blockquote>
Its either passed by value in which case the assignment operator of the destination string is invoked, allocating memory if nessasary or its passed by reference in which case the underlying char array is not copied
Think of it like this
class string
{
public:
void assign(char* str)
{
if(strlen(str) < 15)
{
//small string will fit in array on stack
strcpy(smallArray, str, strlen(str));
}
else
{
//to big for stack array so allocate space on heap
strPointer = new char[strlen(str)+1];
strcpy(strPointer, str, strlen(str));
}
}
private:
char smallArray[16];
char* strPointer;
};
|
|
|
|
|
Hi Josh,
Thanks for so much information. Suppose in your code for class string, there are two functions, foo and goo, foo invokes goo. Then,
1. In goo, it allocates a string, small. In your point, it should be on the stack on function goo, right?
2. Goo returns the string by reference to foo;
3. Then foo will refer to some space in goo function stack, which is unwound when goo returns.
Is it safe?
BTW:
Josh Gray wrote: There is only one stack, you can consider it a global stack I guess
I mean the function call stack. You mean there is another global stack? Intereted in that, do you have any recommended links for the memory space?
regards,
George
|
|
|
|
|
There is only one stack. It isued for storing objects as well as holding various memory addresses required for implementing function calls. The stack is a single FILO (first in, last out) data structure.
If you do this
void foo()
{
string& str = goo();
}
string& goo()
{
string myString("George is cool");
return myString;
}
it will fail (some compilers will give a warning)
The reason is that when goo() returns the stack pointer goes back to where it was before the call to goo and anything allocated on the stack by goo will be gone. This will also be true even if you assign a long string and the string class puts it on the heap, the reason is that myString is on the stack and its pointer to the heap will be lost.
|
|
|
|
|
Thanks Josh,
I find the warning of your code in Visual Studio 2008,
warning C4172: returning address of local variable or temporary
But what makes me confused is, as you mentioned if the content is larger than 16 bytes, heap should be used to allocate, right?
But why if I increase the length of thecontent, the same warning exists? My code,
#include <string>
using namespace std;
string& goo()
{
string myString("George is cool 111111111111111111111 11111111111111111111111111111111111");
return myString;
}
void foo()
{
string& str = goo();
}
regards,
George
|
|
|
|
|
You get the warning because myString is on the stack. If it is internally using the heao to store something it doesnt matter. When the method returns myString is lost and with it the pointer to the memory on the heap
You could try
void foo()
{
string myString;
goo(myString);
}
void goo(string& str)
{
str = "George is cool";
}
|
|
|
|
|
Thanks Josh,
Got your idea. My bad before.
regards,
George
|
|
|
|
|
George_George wrote: 1. In goo, it allocates a string, small. In your point, it should be on the stack on function goo, right?
The allocated memory is either going to be from the heap or from the stack.
George_George wrote: Is it safe?
char *goo1( void )
{
char *s = new char[5];
return s;
}
char *goo2( void )
{
char s[5];
return s;
}
string s1 = goo1();
string s2 = goo2();
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks DavidCrow,
My question is answered.
regards,
George
|
|
|
|
|
From my application , I need to load the contents of a reg file programmatically .
I have tried to use Shellexecute supplying the filepath to the reg file however it still prompts me by asking if i need to insert the file into the registry.
I would want to do this silently as the regedit /s option does it silently.
thanks
Engineering is the effort !
|
|
|
|
|
Why not just shellexecute the command you mentioned, "regedit /s file.reg"?
|
|
|
|
|
thats the nice tip i must say!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
"If it were machines, the pair_programming seem to work, but for humans it is pair_crackdown that seems to work! " - Nisamudheen
Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
|
That's the book I learned STL on. I thought it was a good read. Over the years, while using it, I think it seemed to be a little lacking as a reference for some reason. But overall a good book.
One of the quirks of STL is the way strings evolved over the years, so you end up having stuff talking about char * strings and the std::string class and the other classes have evolved to use std::string. Anyway, it can be a little confusing. I seem to recall this book covering both.
|
|
|
|
|
That's "the" book on STL, if you ask me.
|
|
|
|
|
the reviews for it were all good too but i just wanted to make sure. thanks guys. I feel a little stupid now i didnt realize it was so popular. i wouldnt have asked if i knew it was like asking if scott meyers was worth buying.
|
|
|
|
|
markt wrote: scott meyers was worth buying
His stl book is also pretty good
|
|
|
|
|
I'm using CAsyncSocket::OnReceive() to receive data at rates above 5Mbps (100+ packets per second) and it appears that Windows is dropping some of the data. Here's my test setup:
Two computers connected to a hub both with 100Mbps connections and no other devices attached.
PC1 - sending 10,000 1.3k UDP packets @ 5Mbps
PC2 - receives ~9700 1.3k UDP packets
Now the weird thing is when WireShark is running on PC2 WireShark captures all 10,000 1.3 k UDP packets. So i know the data is making it to PC2, but don't know why my app that's using CAsyncSockets::OnReceive( ) can't seem to get all the data.
Anyone have any ideas? Is this possible a Windows messaging limitation? Any insight would be greatly apprceiated.
Thanks
Earnest
|
|
|
|
|
What are you doing in OnReceive?
You should be looping there (calling recv()/Receive()/ReceiveFrom()) until all the datagrams
available have been received.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Here's basicly my OnReceive() routine minus some error checking:
void CMyAsyncSocket::OnReceive(int nErrorCode)
{
int BytesIn;
BytesIn = ReceiveFrom(Buff, BuffSize, SenderAdd, SenderPrt);
PacketsRcvd++;
CAsyncSocket::OnReceive(nErrorCode);
}
|
|
|
|