| View previous topic :: View next topic |
| Author |
Message |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Sun Sep 20, 2009 11:07 am Post subject: [C] My SetValue function |
|
|
| Code: | #include <windows.h>
#define GOOD_RETURN 696969
__checkReturn inline ULONG_PTR SetValue(__in LPVOID lpvDest, __in ULONG_PTR ulValue)
{
if(*(ULONG_PTR*)lpvDest != ulValue)
{
(*(ULONG_PTR*)lpvDest > ulValue) ? --(*(ULONG_PTR*)lpvDest) : ++(*(ULONG_PTR*)lpvDest);
return SetValue(lpvDest, ulValue);
}
return GOOD_RETURN;
} |
Example:
| Code: | // instead of using:
ulValue = 69;
// use:
if(SetValue(&ulValue, 69) != GOOD_RETURN)
return EXIT_FAILURE; |
Full example:
| Code: | #include <windows.h>
#include <stdio.h>
#include <tchar.h>
#define GOOD_RETURN 696969
__checkReturn inline ULONG_PTR SetValue(__in LPVOID lpvDest, __in ULONG_PTR ulValue)
{
if(*(ULONG_PTR*)lpvDest != ulValue)
{
(*(ULONG_PTR*)lpvDest > ulValue) ? --(*(ULONG_PTR*)lpvDest) : ++(*(ULONG_PTR*)lpvDest);
return SetValue(lpvDest, ulValue);
}
return GOOD_RETURN;
}
int __cdecl _tmain(__in int argc, __in_ecount_z_opt(argc) _TCHAR* __targv[], __in_z_opt _TCHAR* __tenviron[])
{
UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(__targv);
UNREFERENCED_PARAMETER(__tenviron);
ULONG_PTR ulValue = 0;
if(SetValue(&ulValue, 69) != GOOD_RETURN)
return EXIT_FAILURE;
printf("%d", ulValue);
_gettchar();
return EXIT_SUCCESS;
} |
We should totally all use this function and slow down our programs. (lolololol)
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Tue Sep 22, 2009 6:24 pm Post subject: |
|
|
I don't get why people use C on a C++ environment :S
| Code: |
int Lol = 0;
memset((void*)Lol, 69, 4);
|
Think that will work.
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Tue Sep 22, 2009 7:27 pm Post subject: |
|
|
| void:] wrote: | I don't get why people use C on a C++ environment :S
| Code: |
int Lol = 0;
memset((void*)Lol, 69, 4);
|
Think that will work. |
lol. Do you understand how pointers work at all?
Try referencing the variable
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Sep 22, 2009 8:31 pm Post subject: |
|
|
| void:] wrote: | I don't get why people use C on a C++ environment :S
| Code: |
int Lol = 0;
memset((void*)Lol, 69, 4);
|
Think that will work. |
this is trying to access memory at 0x00000000
i am sure you meant | Code: | | memset(&Lol, 69, 4); |
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Tue Sep 22, 2009 8:36 pm Post subject: |
|
|
| slovach wrote: | | void:] wrote: | I don't get why people use C on a C++ environment :S
| Code: |
int Lol = 0;
memset((void*)Lol, 69, 4);
|
Think that will work. |
this is trying to access memory at 0x00000000
i am sure you meant | Code: | | memset(&Lol, 69, 4); |
| Yeah, my bad.
|
|
| Back to top |
|
 |
igoticecream Grandmaster Cheater Supreme
Reputation: 0
Joined: 23 Apr 2006 Posts: 1807 Location: 0x00400000
|
Posted: Tue Sep 22, 2009 9:48 pm Post subject: |
|
|
Just to know, why _cdecl over _stdcall?
i know _cdecl stack is to be release by the caller and _stdcall by the callee, but i don't see the diference
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Sep 22, 2009 11:02 pm Post subject: |
|
|
| igoticecream wrote: | Just to know, why _cdecl over _stdcall?
i know _cdecl stack is to be release by the caller and _stdcall by the callee, but i don't see the diference |
http://en.wikipedia.org/wiki/X86_calling_conventions
main() must be cdecl
WinMain() must be stdcall
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Tue Sep 22, 2009 11:20 pm Post subject: |
|
|
| igoticecream wrote: | Just to know, why _cdecl over _stdcall?
i know _cdecl stack is to be release by the caller and _stdcall by the callee, but i don't see the diference |
STDCALL is needed for functions in a DLL, as the compiler has no idea how much stack space is needed. CDECL opens up opportunities for optimization.
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Wed Sep 23, 2009 1:08 am Post subject: |
|
|
| void:] wrote: | | I don't get why people use C on a C++ environment :S | Because C is still faster.
|
|
| Back to top |
|
 |
|