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
Re: function returning memory address
Just do this inside the function.
return (void*)0x01EA2B00;
Re: function returning written address
Re: function returning memory address
Quote:
Originally Posted by
_Superman_
Just do this inside the function.
return (void*)0x01EA2B00;
i tried that, crashes too
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.
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
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 ><
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 :eek:
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.
Re: function returning memory address
Quote:
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?
Re: function returning memory address
i figured out my problem, i needed int FindVersion(void){}