Click here to Skip to main content
16,011,743 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionMFC + Windows Embedded Xp [modified] Pin
bankai12311-Oct-07 3:42
bankai12311-Oct-07 3:42 
AnswerRe: MFC + Windows Embedded Xp Pin
JudyL_MD11-Oct-07 4:57
JudyL_MD11-Oct-07 4:57 
GeneralRe: MFC + Windows Embedded Xp Pin
bankai12311-Oct-07 5:00
bankai12311-Oct-07 5:00 
QuestionAny alternative for IsBadReadPtr / IsBadWritePtr Pin
sw@thi11-Oct-07 3:03
sw@thi11-Oct-07 3:03 
AnswerRe: Any alternative for IsBadReadPtr / IsBadWritePtr Pin
Cedric Moonen11-Oct-07 3:25
Cedric Moonen11-Oct-07 3:25 
GeneralRe: Any alternative for IsBadReadPtr / IsBadWritePtr Pin
sw@thi11-Oct-07 20:12
sw@thi11-Oct-07 20:12 
GeneralRe: Any alternative for IsBadReadPtr / IsBadWritePtr Pin
JudyL_MD12-Oct-07 3:19
JudyL_MD12-Oct-07 3:19 
AnswerRe: Any alternative for IsBadReadPtr / IsBadWritePtr Pin
Matthew Faithfull11-Oct-07 3:32
Matthew Faithfull11-Oct-07 3:32 
IsBadReadPtr / IsBadWritePtr are as good as it gets on Win32 I'm afraid. You shouldn't run into too much trouble as long as your app is doing 'ordinary' things with memory i.e. no mucking around with non-paged pool or using exception filters to allocate virtual memory. I wouldn't try using them against anything you expect to be allocated on the stack either as compiler optimisations might change behaviour between Debug and Release builds.

That leaves you with IsBadReadPtr / IsBadWritePtr are fine for Heap memory you allocate yourself i.e. new and delete.

I use a special class to check pointer parameters like this when they are passed. The template class has assignment from and cast to operators for the original pointer type. The cast calls the relevant check function whenever it is used. The checking classes are removed in the Release build for performance by the use of a macro. so

void SomeFunc( CNullPointerCheck<char*> pszData )

which checks pszData for NULL on every call in Debug, becomes

void SomeFunc( char* pszData )

with zero overhead in Release builds. It gets written as

void SomeFunc( _PC_NP(char*) pszData )

which makes it clear this is a Parameter Check for Null Pointer

Other classes check for Readable and Writable memory of a certain size at the target of the pointer using the IsBadReadPtr/IsBadWritePtr functions so

void SomeFunc( _PC_WP(char*, 40) pszData )

for example checks for at least 40 characters of writable memory.
I'll post the whole lot as an article some day when I'm happy with the error reporting system.

Nothing is exactly what it seems but everything with seems can be unpicked.

GeneralRe: Any alternative for IsBadReadPtr / IsBadWritePtr Pin
Stephen Hewitt11-Oct-07 17:58
Stephen Hewitt11-Oct-07 17:58 
GeneralRe: Any alternative for IsBadReadPtr / IsBadWritePtr Pin
Matthew Faithfull11-Oct-07 23:22
Matthew Faithfull11-Oct-07 23:22 
GeneralRe: Any alternative for IsBadReadPtr / IsBadWritePtr Pin
Stephen Hewitt14-Oct-07 14:55
Stephen Hewitt14-Oct-07 14:55 
GeneralRe: Any alternative for IsBadReadPtr / IsBadWritePtr Pin
sw@thi11-Oct-07 20:22
sw@thi11-Oct-07 20:22 
QuestionRe: Any alternative for IsBadReadPtr / IsBadWritePtr Pin
David Crow11-Oct-07 3:54
David Crow11-Oct-07 3:54 
AnswerRe: Any alternative for IsBadReadPtr / IsBadWritePtr Pin
led mike11-Oct-07 4:12
led mike11-Oct-07 4:12 
QuestionRe: Any alternative for IsBadReadPtr / IsBadWritePtr Pin
ThatsAlok11-Oct-07 4:08
ThatsAlok11-Oct-07 4:08 
AnswerRe: Any alternative for IsBadReadPtr / IsBadWritePtr Pin
Stephen Hewitt11-Oct-07 18:00
Stephen Hewitt11-Oct-07 18:00 
QuestionHow to access properties of ActiveX control in atl Pin
Rajesh_Yadav_8011-Oct-07 2:40
Rajesh_Yadav_8011-Oct-07 2:40 
GeneralRe: How to access properties of ActiveX control in atl Pin
Matthew Faithfull11-Oct-07 2:52
Matthew Faithfull11-Oct-07 2:52 
QuestionHow to send hex data to TCP socket using Winsock Pin
alofang11-Oct-07 2:35
alofang11-Oct-07 2:35 
AnswerRe: How to send hex data to TCP socket using Winsock Pin
ThatsAlok11-Oct-07 2:55
ThatsAlok11-Oct-07 2:55 
GeneralRe: How to send hex data to TCP socket using Winsock Pin
alofang11-Oct-07 4:13
alofang11-Oct-07 4:13 
QuestionBackground color Pin
ArielR11-Oct-07 2:33
ArielR11-Oct-07 2:33 
AnswerRe: Background color Pin
Nelek11-Oct-07 2:41
protectorNelek11-Oct-07 2:41 
GeneralRe: Background color Pin
ThatsAlok11-Oct-07 3:55
ThatsAlok11-Oct-07 3:55 
GeneralRe: Background color Pin
Stephen Hewitt11-Oct-07 18:42
Stephen Hewitt11-Oct-07 18:42 

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.