|
<br />
void NoSideEffect(int *T)<br />
{<br />
<br />
int G = 5;<br />
T = &G;<br />
<br />
<br />
}<br />
int X = 2;<br />
NoSideEffect(&X);<br />
printf("X is Now %d \n",X);<br />
X is Now 2
don't change why?could you explain more detail
|
|
|
|
|
This is because c++ accurately always passes by value When you pass a pointer you are passing the value of the pointer which is a memory address. when the compiler creates a stack frame the value of the memory address is put on the stack as a local variable when you change the value of that variable you point it to a new memory location and no longer maps to memory address of the variable in the caller. So any change will not affect the caller since you are changing the location associated with another variable in this case another local variable which is allso on the stack.
a programmer traped in a thugs body
|
|
|
|
|
using references is safer, you do not have to check for NULL pointers.
This signature was proudly tested on animals.
|
|
|
|
|
|
That's right. You cannot pass a null to a reference like you can for a pointer.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hi All,
I m developing the sdi application.I want to handle the System menu move option.
If I press ALT+SPACE on my application and select move ..then I need the event handler..
can anybody pls help me out in this..
Thanks in Advance,
Ashok.
|
|
|
|
|
I believe this[^] is what you need.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I am attempting to control mouse events, like moving the mouse and pressing any mouse key ...
I am using the following code to set the mouse position as (0,0)
LPINPUT i;
MOUSEINPUT mi;
mi.dx=0;
mi.dy=0;
mi.dwFlags=MOUSEEVENTF_LEFTDOWN;
mi.time=0;
mi.dwExtraInfo=GetMessageExtraInfo();
mi.mouseData=0;
i[0].mi=mi;
i[0].type=INPUT_MOUSE;
SendInput(1,i,sizeof(i));
But, I am getting an exception at the line
i[0].mi=mi;
Actually I want to control the mouse pointer through an external hardware, which will be connected at the serial port.
I will read the data from the serial port like mouse movement and any mouse key being pressed, then SET this mouse status to the system mouse ....this is my ultimate aim ...
So I wrote the above code to set the mouse position first, but its not working ...
Please someone help me here ...
Apurv
A man is but the product of his thoughts. What he thinks, he becomes.
.......Mahatma Gandhi
Be the change you want to see in the world.
.......Mahatma Gandhi
|
|
|
|
|
LPINPUT i;
LPINPUT means pointer to structure INPUT. Here i is of type LPINPUT. You have to allocate memory for this before you use this variable.
ie LPINPUT i = new INPUT;
akt
|
|
|
|
|
oh ... thanks ...
its not giving anymore errors ...
but the mouse position is not set ....
here is my updated code ...
LPINPUT i = new INPUT;
MOUSEINPUT mi;
mi.dx=0;
mi.dy=0;
mi.dwFlags=MOUSEEVENTF_MOVE;
mi.time=0;
mi.dwExtraInfo=GetMessageExtraInfo();
mi.mouseData=0;
i[0].mi=mi;
i[0].type=INPUT_MOUSE;
SendInput(1,i,sizeof(i));
Apurv
A man is but the product of his thoughts. What he thinks, he becomes.
.......Mahatma Gandhi
Be the change you want to see in the world.
.......Mahatma Gandhi
|
|
|
|
|
Try this
INPUT i;
MOUSEINPUT mi;
mi.dx=0;
mi.dy=0;
mi.dwFlags=MOUSEEVENTF_MOVE;
mi.time=0;
mi.dwExtraInfo=GetMessageExtraInfo();
mi.mouseData=0;
i.mi=mi;
i.type=INPUT_MOUSE;
SendInput(1, &i, sizeof(i));
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
its working ... superman .... thank you very much ....
will this SendInput() function work outside the application window ?
I mean, while i interface it with my hardware, so that the key inputs are coming from the hardware, know suppose the mouse is over the start button, and i send the Left-button pressed event to the SendInput() function ... will this result the Start button being pressed ???
Apurv
A man is but the product of his thoughts. What he thinks, he becomes.
.......Mahatma Gandhi
Be the change you want to see in the world.
.......Mahatma Gandhi
|
|
|
|
|
I believe that it will work where ever the mouse pointer is located.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Please check the last parameter of SendInput();
It requires the size of structure INPUT. For this you have call sizeof(INPUT).
In your code, you have taken sizeof(i). i means LPINPUT.
As i said earlier LPINPUT is a pointer. So sizeof(i) will return the size of a pointer variable only(4 bytes).
akt
|
|
|
|
|
Hi All
I am getting assertion in altsimpstr.h file.
void AddRef() throw()
{
ATLASSERT(nRefs > 0);
_AtlInterlockedIncrement(&nRefs);
}
how can i find solution of this asserton.
Plz help me
|
|
|
|
|
Can you show your code that it products this error?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Davitor wrote: how can i find solution of this asserton.
Use your debugger to gather as much information as possible: what is the context in your code (use the callstack), inspect the different variables just before the crash (put a breakpoint just before the call where it crashes), ...
|
|
|
|
|
Hi all,
i Have SDI type application,I m creating a Mutex to avoid multiple instance of application. and use system tray icon feature.
for creating mutex i m using this code:
HANDLE hMutex = ::CreateMutex(NULL, TRUE, _T("GlobalMainMutex"));
switch(::GetLastError())
{
case ERROR_SUCCESS:
break;
case ERROR_ALREADY_EXISTS:
return FALSE;
default:
return FALSE;
}
for system tray icon i m taking help of this article.
http://www.codeproject.com/KB/shell/systemtray.aspx[^]
My problem is that is application is already running and its in hide mode and icon present in system tray,now when i click on my exe than its not open becoz of mutex.
i what when application is already running or its hide than if i click on exe icon than the hide application can show.
please tell me how can i do this.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
First of all, if i were you i'd use a different name for the mutex because "GlobalMainMutex" doesn't seem to be that unique as it should, maybe use a GUID generator and use the generated code as name, or as part of the name of your mutex.
To show the already running instance you could either broadcast a registered message when your new instance detects another instance running upon which your program brings up its window, this sounds a tiny bit overkill (post/send a message to EVERY running app in the system) but it is easy to do, or you could try to find your own process by enumerating processes and checking their names or executable names or whatever and posting a thread message to it, or you could enumerate windows on the system and if you find the one belonging to your process (for example by class name) post a message to it.
p.s: to avoid confusement, i don't mean use a GUID generator to generate a new name every time your app starts, since that would -of course- make the whole idea useless...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
please can u explain me with any example. i m very thankful to u.
thanks.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Well, i currently have no time to write you a complete example proggie but i can try to give you a "skeleton", i hope it will help you somewhat
UINT WM_ACTIVATE_MY_APPLICATION = RegisterWindowMessage("WM_ACTIVATE_MY_APPLICATION_315FrYu76A");
...
if (there_is_another_instrance_running)
{
BroadcastSystemMessage(BSF_POSTMESSAGE, BSM_APPLICATIONS, WM_ACTIVATE_MY_APPLICATION, 0, 0);
exit(0);
}
...
BEGIN_MESSAGE_MAP(CMyVeryOwnApp, CWinApp)
...
ON_THREAD_MESSAGE(WM_ACTIVATE_MY_APPLICATION, OnActivateMyVeryOwnApp)
...
END_MESSAGE_MAP()
...
LRESULT CMyVeryOwnApp::OnActivateMyVeryOwnApp(WPARAM wParam, LPARAM lParam)
{
...
ShowMyVeryOwnMainWindowAndBringToFront();
...
} I hope this helps somewhat...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
this error comes
error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CDataDoctorsEmployeePlannerApp::* )(WPARAM,LPARAM)' to 'void (__thiscall CWinThread::* )(WPARAM,LPARAM)'
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
And you really have no idea what this could mean? Change the LRESULT to void in the method's declaration and definition.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Code-o-mat wrote: ShowMyVeryOwnMainWindowAndBringToFront();
What is in this function.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Code to make your window visible using ShowWindow[^], bring it to front using BringWindowToTop[^], and whatever else you like...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|