Click here to Skip to main content
15,906,708 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to egalise two strings Pin
ShilpiP27-Jul-07 3:06
ShilpiP27-Jul-07 3:06 
GeneralRe: How to egalise two strings Pin
toxcct27-Jul-07 3:12
toxcct27-Jul-07 3:12 
QuestionCheck if is valid pointer address? Pin
bosfan27-Jul-07 2:22
bosfan27-Jul-07 2:22 
AnswerRe: Check if is valid pointer address? Pin
sdancer7527-Jul-07 2:32
sdancer7527-Jul-07 2:32 
AnswerRe: Check if is valid pointer address? Pin
Mike Dimmick27-Jul-07 2:34
Mike Dimmick27-Jul-07 2:34 
AnswerRe: Check if is valid pointer address? Pin
CPallini27-Jul-07 2:51
mveCPallini27-Jul-07 2:51 
AnswerRe: Check if is valid pointer address? Pin
bosfan27-Jul-07 3:16
bosfan27-Jul-07 3:16 
AnswerRe: Check if is valid pointer address? Pin
Randor 27-Jul-07 4:42
professional Randor 27-Jul-07 4:42 
As Mike Dimmick said there are no 100% sure methods to verify a pointer. Nevertheless here are some basic techniques that could be used to increase the odds.

Some basic check that works on all pointers:
<br />
VERIFY(NULL != lpSomePointer)<br />
VERIFY(0 == (lpSomePointer & 3));<br />


At this point it *might* be a pointer because the number is an even number which is not NULL.

Microsoft supplies the functions IsBadCodePtr() and IsBadWritePtr() for checking the memory location. An example of using it on a function pointer might be:

if(FALSE == IsBadCodePtr((FARPROC)(LPVOID)pInstructions))<br />
{<br />
//...<br />
}


While using it on a pointer to a writable address might look like:

if(FALSE== IsBadWritePtr((LPVOID)pInstructions,1))<br />
{<br />
//...<br />
}


If you wanted to create your own verification to check if the pointer is pointing to a memory address which is executable... for a function pointer you might do something like:

MEMORY_BASIC_INFORMATION mbi;<br />
if(VirtualQueryEx(GetCurrentProcess(),(LPVOID)pInstructions,&mbi,sizeof(MEMORY_BASIC_INFORMATION)))<br />
{<br />
	if(mbi.Protect & PAGE_EXECUTE_READ && mbi.State & MEM_COMMIT && mbi.AllocationProtect & PAGE_EXECUTE_WRITECOPY && mbi.Type & MEM_IMAGE)<br />
	{<br />
		(*this.*MyMemberFunction)(someval);<br />
	}<br />
}


If you wanted to write some extremely hacked-up NON-PORTABLE and compiler specific code to do some additional checking on a C++ member function you might look for some prologue asm instructions:

For example:

push esi
push edi

<br />
unsigned char ASM[] = "\x56\x57\x8B\x7C\x24\x0C";<br />
PDWORD pAddress = (PDWORD)&SomeFucntion;<br />
DWORD_PTR pInstructions = *pAddress;<br />
if(memcmp((LPVOID)pInstructions,ASM,sizeof(ASM))<br />
{<br />
//might be good pointer<br />
}<br />


There is no guarantee that your compiler will produce a specific asm prologue... or the function may become _inline in which case this technique would fail.

I cant really think of anymore methods... and to be honest the ones listed above do not make any guarantees.

Best Wishes,
-Randor (David Delaune)
GeneralRe: Check if is valid pointer address? Pin
bosfan27-Jul-07 4:55
bosfan27-Jul-07 4:55 
GeneralRe: Check if is valid pointer address? Pin
Michael Dunn27-Jul-07 10:04
sitebuilderMichael Dunn27-Jul-07 10:04 
GeneralRe: Check if is valid pointer address? Pin
Michael Dunn27-Jul-07 10:04
sitebuilderMichael Dunn27-Jul-07 10:04 
QuestionCAsyncSocket::DoCallBack(WPARAM wParam, LPARAM lParam) Pin
xxblinux27-Jul-07 2:15
xxblinux27-Jul-07 2:15 
AnswerRe: CAsyncSocket::DoCallBack(WPARAM wParam, LPARAM lParam) Pin
Mike Dimmick27-Jul-07 2:36
Mike Dimmick27-Jul-07 2:36 
AnswerRe: CAsyncSocket::DoCallBack(WPARAM wParam, LPARAM lParam) Pin
xxblinux27-Jul-07 16:33
xxblinux27-Jul-07 16:33 
Questiondifference b/w long pointer and pointer to string Pin
hari prasad sathpadi27-Jul-07 1:56
hari prasad sathpadi27-Jul-07 1:56 
AnswerRe: difference b/w long pointer and pointer to string Pin
toxcct27-Jul-07 2:34
toxcct27-Jul-07 2:34 
AnswerRe: difference b/w long pointer and pointer to string Pin
Nemanja Trifunovic27-Jul-07 2:42
Nemanja Trifunovic27-Jul-07 2:42 
AnswerRe: difference b/w long pointer and pointer to string Pin
Mike Dimmick27-Jul-07 2:44
Mike Dimmick27-Jul-07 2:44 
QuestionHow to egalise two strings Pin
garfaoui27-Jul-07 0:16
garfaoui27-Jul-07 0:16 
AnswerRe: How to egalise two strings Pin
GameProfessor27-Jul-07 0:20
GameProfessor27-Jul-07 0:20 
GeneralRe: How to egalise two strings Pin
garfaoui27-Jul-07 0:23
garfaoui27-Jul-07 0:23 
AnswerRe: How to egalise two strings Pin
F.Falk27-Jul-07 0:24
F.Falk27-Jul-07 0:24 
AnswerRe: How to egalise two strings Pin
ashukasama27-Jul-07 0:24
ashukasama27-Jul-07 0:24 
AnswerRe: How to egalise two strings Pin
garfaoui27-Jul-07 0:38
garfaoui27-Jul-07 0:38 
GeneralRe: How to egalise two strings Pin
mandanani27-Jul-07 0:36
mandanani27-Jul-07 0:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.