|
kumarashoka wrote: 1. what is stack.
Do you mean "what is A stack", or "what is THE stack"?
Oh well I'll just answer both, since they have a lot to do with each other.
A stack is a data structure that lets you put something on top, and the only thing you can remove from it is the top.
THE stack, is a stack (well partly..), which grows downwards in memory on every architecture that you are likely to care about (which doesn't usually matter, unless you want to do low level things), and it stores things like the address where the current function will return to if you say "return ", it is also used to store some local variables (explaining exactly which is a little hard, but if you pretend a variable is on the stack, the compiler will make sure it is), and sometimes it is used to store function parameters (but not always, equally complicated, and they will be on the stack if you want then to be), and there can be some other things there which you usually don't have to worry about.
For return addresses, THE stack really is a stack, but the variables and parameters are accessed as if the stack is just a piece of memory - and that's exactly what it is, but we like to pretend that we can only take things off the top to make it easier to manage (and also it wouldn't make much sense to Not treat it like that in the context of functions calls)
|
|
|
|
|
|
kumarashoka wrote: 1. what is stack.
A LIFO queue.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
|
how a pointer save memory and what is the limitation of pointer.
|
|
|
|
|
(overly simplified)
A pointer does not save memory; it only points to another place in memory that contains "the stuff you want to point to" outside of the stack space.
There is no limitation of using pointers, it is powerful, but somewhat more "dangerous" to use. (lost pointers, lost memory, unchecked dereferences... )
...
This signature was proudly tested on animals.
|
|
|
|
|
Maximilien wrote: outside of the stack space
What makes you say that? It doesn't really make it any simpler.. and it's not even true
|
|
|
|
|
I have copied one of my programs into another program and made the necessary changes for the new program. But whenever I open a AfxMessageBox(,); it displayes the previous program's title in the title portion of the message box. How do I remedy this?
Sample code:
CString str = "Select the [OK] button to begin processing the data";
int nTest = 0;
nTest = AfxMessageBox(str, MB_OK);
(The title of the messagebox is that of the previous program.)
A C++ programming language novice, but striving to learn
|
|
|
|
|
Is this a CWinApp based application? If so...what is the value of the string in your project with resource ID AFX_IDS_APP_TITLE?
CWinApp::m_pszAppName[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Yes, this fixed my needs. Thank you!
A C++ programming language novice, but striving to learn
|
|
|
|
|
I studied the msdn and the forum in detail but I could not figure out what is the problem with this code?
The key press event is not working?? SendInput API is a mess indeed.
INPUT input;
KEYBDINPUT kinput;
kinput.dwFlags=KEYEVENTF_KEYUP|KEYEVENTF_EXTENDEDKEY;
kinput.wVk=91; // key to activate start up window
kinput.time=0;
input.type = INPUT_KEYBOARD;
input.ki = kinput;
::SendInput( 1, &input, sizeof(input));
|
|
|
|
|
What does GetLastError() return?
[edit]
Maybe this link[^] may help.
[\edit]
|
|
|
|
|
I find the error.
Actually I am not assigning the proper values to flag. Documentation says that when key is pressed, do not assign any thing to flags.
KEYEVENTF_KEYUP
If specified, the key is being released. If not specified, the key is being pressed
|
|
|
|
|
At me a question. In the project I use CMapStringToOb, number of objects which I store in it much, the order 100000. Speed of work, including speed of work destructor, does not arrange me. A question in the following — there are any analogues CMapStringToOb which work faster? The Same question in occasion of CObList — I search for fast analogue.
Thanks in advance.
|
|
|
|
|
Hi I have a service written in Visual C++ 6 that needs to interact with an application written in vb.net. In my service I have used :
DWORD mymsg=RegisterWindowMessage("my_message")
to register a unique custom message.
I then use:
BOOL b=SendNotifyMessage(HWND_BROADCAST,mymsg,NULL,NULL)
to broadcast my message. However, I can't seem to be able to capture this message in the Windowproc function of my vb.net application.
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Integer
Dim mymsg As Integer = RegisterWindowMessage("my_message")
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
if m.Msg=mymsg then
--do something--
end if
end sub
Please help!
P.S.:I need to show a pop up in my .net application when it receives this message. The message values have all registered properly in both applications and are returned to be the same when I print them. Also the SendNotitfyMessage in my service returns a non zero value(supposed to indicate success). What do I do?? What am I doing wrong?
|
|
|
|
|
The message registered with RegisterWindowMessage are valid only for a session.
You cannot use this for your case since a service runs as a different user than the application.
You can instead use a named event for your purpose.
Use CreateEvent[^] to open/create an event both the service and the application.
Now your application can wait on the event handle that will be set from the service.
Just remember to give a name for the last parameter to the API.
And also remember to prefix the name with "Global\" .
So you could typically you a name like "Global\my_message" .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Well, here's the thing.
1.I'm able to communicate from the app. to the service using the ControlService function but not the other way around.
2.You say that it is only valid for a session. But as you can see I've used RegisterWindowMessage in the service as well as app.(to get the same SYSTEMWIDE unique -that's what msdn says- value for my message both inside the service and the app.) So if the app is reloaded from another user's context the app will gather the value of the message again.
3.I've even had the values displayed in both my service and app and they are the same. Thus the message is definitely unique and visible to both.
4.I even printed a log of all the messages recvd by wndproc of the app but the broadcasted msg never reaches the wndproc despite being successfully broadcasted from the service.
As for your idea of using named events, I did that and again the same issue was encountered. The service says that the event was set but the application never captures the event. Just to confirm, while using CreateEvent I still do need to follow the escaping conventions right? i.e I used CreateEvent(NULL,0,0,"Global\\my_message") in the service and
CreateEvent(Nothing,0,0,"Global\my_message") in the app.(since vb.net doesn't need to escape backslash)
Here's the code:
HANDLE MY_EVENT=CreateEvent(NULL,false,false,"Global\\my_message");
SetEvent(MY_EVENT);
In vb.net:
Const SYNCHRONIZE As Integer = &H100000L
Dim MY_EVENT As Integer
Private Declare Function OpenEvent Lib "kernel32" Alias "OpenEventA" (ByVal dwDesiredAccess As Long, ByVal inheritHandle As Integer, ByVal lpName As String) As Integer
Private Declare Function WaitForSingleObject Lib "kernel32" Alias "WaitForSingleObject" (ByVal hHandle As Integer, ByVal dwMilliseconds As Integer) As Integer
Sub New()
InitializeComponent()
Me.TopLevel = True
Try
my_event_thread = New Thread(AddressOf MyEventWatcher)
Catch ex As Exception
MsgBox("Error in initializing! " + ex.Message)
Application.Exit()
End Try
End Sub
Private Sub MyEventWatcher()
Try
MY_EVENT = OpenEvent(SYNCHRONIZE, 1, "Global\my_message")
While True
WaitForSingleObject(MY_EVENT, INFINITE)
MsgBox("Done")
End While
Catch ex As Exception
MsgBox("Exception:" + ex.Message)
End Try
End Sub
What should I do now?Any ideas? Thanks for the help!
modified on Monday, August 10, 2009 3:22 AM
|
|
|
|
|
Hi thanks for all the advice. I've managed to take care of it. I had to make the service interactive in order to make my application visible to it and I found no other way of making it visible due to the different user contexts. So you were right But one thing that I haven't quite understood is, why didn't events work? I mean a "Global" event should not be hindered by contexts/sessions right? But even the global events raised by the service were not visible to my application. Can you explain?
|
|
|
|
|
I'm not exactly sure why global names with events didn't work.
I'm sure it should work because I have done the exact same thing to communicate between a service and an application.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
hmm..and did you make your service interactive or not? By the way, did you look at the code that I had posted, the one using global events? Just to be sure I did it right.
|
|
|
|
|
I used the following code to create a file, so that every user can read, modify, delete and write to it:
CreateFile(
m_szLogFilePath,
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_DELETE | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN,
NULL);
but when I log in with a user other than one in which I created the file, I can not save any modification in it neither delete it. any help?
Thank you masters!
|
|
|
|
|
I guess your proble is related with the NULL value of the fourth parameter, see [^].
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]
|
|
|
|
|
so what?
Thank you masters!
|
|
|
|
|
Provided my guess is correct (I'm not an expert about) you've to explicitely create a security descriptor, see [^].
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 are probably right.
If you want to have EVERYONE permission, you need to create new security descriptor.
NULL says that the default ACL is used, i.e. only the user or someone with higher privileges (administrator for example) can change the file.
Try this:
SECURITY_ATTRIBUTES m_pSecAttrib;
SECURITY_DESCRIPTOR* m_pSecDesc;
m_pSecDesc = (SECURITY_DESCRIPTOR*)LocalAlloc(LPTR,
SECURITY_DESCRIPTOR_MIN_LENGTH);
InitializeSecurityDescriptor(m_pSecDesc,
SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(m_pSecDesc,TRUE,(PACL)NULL,FALSE))
m_pSecAttrib.nLength = sizeof(SECURITY_ATTRIBUTES);
m_pSecAttrib.bInheritHandle = TRUE;
m_pSecAttrib.lpSecurityDescriptor = m_pSecDesc;
It should create security descriptor with EVERYONE permission.
Instead of NULL, send &m_pSecAttrib.
Hope I helped.
|
|
|
|