Re: Dealing with HANDLEs

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



<snip>

void GetPointerOfProcessFromList( CProcess* pProcess)

This worked in debug. But in release it didn't seem to return the
pointer correctly, and that's why it called OpenProcess on the object
again. When I changed the function to return the pointer it worked:

CProcess* GetPointerOfProcessFromList( CProcess* pProcess)

Strange, I thought if I pass a pointer, it's like by ref, I can change its
address and it changes the passed object, not a copy of it. Also, it
worked in debug. I know it's getting out of the scope of this thread...
but just wanted to mention what the issue was.


This can't work ever; and if it does, it it by coincidence. This is basic
language info but FYI:

When you pass a pointer (non const), you can modify whatever it pointed to
by that pointer but the value of the pointer is stored on the stack, just
like any other parameter, and so cannot be modified. if you want to modify
the value of a pointer (ie make it point to somthing else), then you must
pass a pointer to the pointer.

for example:
void func1(CProcess** ppProcess)
{
CProcess* pProcess = *ppProcess; // get the input value
// do stuff and assign to pProcess
// now set the output
*ppProcess = pProcess;
}

// sample call
func1(&pProcess);


.



Relevant Pages

  • Re: Release version crashes - again
    ... DWORD *pointer = NULL; ... are not usually equal in retail, but they usually are in debug. ... but my code is crashing in the CONSTRUCTOR area (long ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Dealing with HANDLEs
    ... On every new process event this program creates a new Process object and ... pointer and assigns the pointer from the to it. ... This worked in debug. ... Strange, I thought if I pass a pointer, it's like by ref, I can change its ...
    (microsoft.public.win32.programmer.kernel)
  • Re: checking if pointer is NULL allowed?
    ... If it has been freed and causes the debug to crash, ... macro used in debugging routines that can take a pointer and return the ... There are routines that allocate a chunk of memory to store a number ...
    (comp.lang.c)
  • Re: checking if pointer is NULL allowed?
    ... If it has been freed and causes the debug to crash, ... generally not interested in the pointer once it has been freedCare to show how you would implement this? ... There are routines that allocate a chunk of memory to store a number ...
    (comp.lang.c)
  • When the based variables basing pointer is pointer based...
    ... I have a data structure which is pointer based (the data is in the ... The user space contains pointers to linked list entries in the heap. ... I threw it into debug, ...
    (comp.sys.ibm.as400.misc)