Tuesday, July 28, 2009

Again c++ and pointers ...?

I try to learn the pointers and in the same time to create a GTA-SA trainer but i'm having problems ...





i use this code :


"


int main ()


{








int *pointer;





pointer = reinterpret_cast%26lt;int*%26gt;(0xB7CE50);





*pointer = 100;








getchar();











}


"





But i get this:





"Unhandled exception at 0x004113c8 in memory.exe: 0xC0000005: Access violation writing location 0x00b7ce50."





I also tried to do pointer = 0xB7CE50; but won't compile,can not convert from int to int* .





So what now?





Can anyone give me a good and working example?


PS:You can use inline ASM!





Thanks!!!

Again c++ and pointers ...?
The reason this is throwing an exception is because the memory location you are trying to write to 0x00B7CE50 is protected by the operating system.





The proper way to get memory for a pointer is to utilize the c++ opperator 'new'





try this:





int* pointer;





pointer = new int();


// in straight C this would be pointer = (int*)malloc(sizeof(int));





*pointer = 100;

brandon flowers

No comments:

Post a Comment