It doesn't make sense to pass memory pointers between address spaces.
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0
I was under the impression that a child process shares memory space.
I pass an int pointer to one app at runtime via command line and the second app modifies it. Since both apps know the address they can share the variable between them.
At least that is how I thought it to work, I have certainly done this in another scripting language, passing a whole array of pointers.
No a child process(at least a child process in Linux) has its own address space so passing pointers from its parent will be meaningless.
Maybe you could pass along some specifics of what your trying to do.
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0
I am pretty sure I can also achieve the same now, but not unless I can pass two.exe a pid and a pointer.
(
Sounds like your accessing the parent or client address space via its pid and a pointer which sounds like your processes may not be sharing an address space.
Note: I have programmed on Windows system infrequently, so I'm ignorant of its functionality.
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0
I think you should consider a few problems with your approach.
1. What if your pointer, points to dynamic memory that's been freed.
2. What if your pointer, points to memory on the stack that's been released.
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0
>>Now the next part of my plan is a way to convert this char* representation of a pointer which will be passed in, to the actual numeric value of it.
Forget that idea, it won't, and can't work for reasons previously given. Pointers can not be passed between processes because each process has its own address space. Process A can not write into process B's address space, the operating system will prevent it by producing an Access Violation type of error.
Ancient Dragon
Achieved Level 70
32,145 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69
why don't you just try it and see for yourself if it works or not.
Ancient Dragon
Achieved Level 70
32,145 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69
call strtol() to convert the string to an unsigned int, then assign that to a pointer of type unsigned char*.
unsigned char* ptr;
char* p;
unsigned int x = strtol(argv[1], &p, 16);
ptr = (unsigned char*)x;
or more simply
char* p;
unsigned char* ptr = (unsigned char*)strtol(argv[1],&p, 16);
Ancient Dragon
Achieved Level 70
32,145 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69
you don't need vInt if all you are going to do is pass it to the Windows function. I don't know without testing if stringstream will work correctly like that, it may just return the char* instead of converting it to an integer.
Now that I think about it
stringstream ss;
int *iInt;
unsinged int x;
ss << argv[1];
ss >> x;
iInt = (int*)x;
Ancient Dragon
Achieved Level 70
32,145 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69
Question Answered as of 1 Year Ago by
Ancient Dragon
and
gerard4143