-
May 17th, 2009, 12:07 PM
#1
function returning written address
hi i have problem with that
Code:
void* FindVersion(void)
{
return (void*)(DWORD*)0x01EA2B00;
}
struct cl_funcs_s ofuncs;
cl_funcs_s *pfuncs = (cl_funcs_s*) FindVersion();
it doesn't return address right, so it crash application
if i just make
Code:
struct cl_funcs_s ofuncs;
cl_funcs_s *pfuncs = (cl_funcs_s*) 0x01EA2B00;
so it is all ok, but i need function there
Last edited by Owyn; May 18th, 2009 at 04:08 AM.
-
May 17th, 2009, 09:34 PM
#2
Re: function returning memory address
Just do this inside the function.
return (void*)0x01EA2B00;
-
May 18th, 2009, 01:14 AM
#3
Re: function returning written address
-
May 18th, 2009, 03:22 AM
#4
Re: function returning memory address
Originally Posted by _Superman_
Just do this inside the function.
return (void*)0x01EA2B00;
i tried that, crashes too
-
May 18th, 2009, 03:38 AM
#5
Re: function returning memory address
You've introduced a "magic" address into your code.
You can do this sort of weird syntax in the IDE debugger where you see the pointers. Not normal to put it into your code.
-
May 18th, 2009, 03:40 AM
#6
Re: function returning memory address
i know that working with magic addresses is bad but anyway i need it in my code, 2nd variant of my code works fine but i need a function or anything so i can choose magic address depending on conditions
-
May 18th, 2009, 05:50 AM
#7
Re: function returning memory address
i use visual studio 2008
working code
Code:
struct cl_funcs_s ofuncs;
cl_funcs_s *pfuncs = (cl_funcs_s*) 0x01EA2B00;
non working code
[os.cpp]
Code:
void* FindVersion(void)
{
return (void*)0x01EA2B00;
}
[main.cpp]
Code:
#include "os.cpp"
struct cl_funcs_s ofuncs;
cl_funcs_s *pfuncs = (cl_funcs_s*) FindVersion();
now i really don't know what is wrong ><
-
May 18th, 2009, 06:33 AM
#8
Re: function returning memory address
The memory layout may change every time you modify your source code. Assuming to find a function body at a specific memory location is one of the worst techniques I have ever seen
If you need to return the address of a function, the use the function name to determine its address:
Code:
void somefunc()
{
}
void* FindVersion()
{
return reinterpret_cast<void*>( somefunc );
}
Can you please elaborate what exactly you are doing? Maybe the template method pattern can be applied for a more robust solution.
- Guido
-
May 18th, 2009, 06:55 AM
#9
Re: function returning memory address
Originally Posted by Owyn
i know that working with magic addresses is bad but anyway i need it in my code, 2nd variant of my code works fine but i need a function or anything so i can choose magic address depending on conditions
Are you doing C development on embedded systems?
-
May 18th, 2009, 12:52 PM
#10
Re: function returning memory address
i figured out my problem, i needed int FindVersion(void){}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|