body { margin:0px; padding:0px; background:#f6f6f6; color:#000000; font-size: small; } #outer-wrapper { font:normal normal 100% 'Trebuchet MS',Trebuchet,Verdana,Sans-Serif; } a { color:#DE7008; } a:hover { color:#9E5205; } a img { border-width: 0; } #content-wrapper { padding-top: 0; padding-right: 1em; padding-bottom: 0; padding-left: 1em; } @media all { div#main { float:right; width:66%; padding-top:30px; padding-right:0; padding-bottom:10px; padding-left:1em; border-left:dotted 1px #e0ad12; word-wrap: break-word; /* fix for long text breaking sidebar float in IE */ overflow: hidden; /* fix for long non-text content breaking IE sidebar float */ } div#sidebar { margin-top:20px; margin-right:0px; margin-bottom:0px; margin-left:0; padding:0px; text-align:left; float: left; width: 31%; word-wrap: break-word; /* fix for long text breaking sidebar float in IE */ overflow: hidden; /* fix for long non-text content breaking IE sidebar float */ } } @media handheld { div#main { float:none; width:90%; } div#sidebar { padding-top:30px; padding-right:7%; padding-bottom:10px; padding-left:3%; } } #header { padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; border-bottom:dotted 1px #e0ad12; background:#F5E39e; } h1 a:link { text-decoration:none; color:#F5DEB3 } h1 a:visited { text-decoration:none; color:#F5DEB3 } h1,h2,h3 { margin: 0; } h1 { padding-top:25px; padding-right:0px; padding-bottom:10px; padding-left:5%; color:#F5DEB3; background:#DE7008; font:normal bold 300% Verdana,Sans-Serif; letter-spacing:-2px; } h3.post-title { color:#9E5205; font:normal bold 160% Verdana,Sans-Serif; letter-spacing:-1px; } h3.post-title a, h3.post-title a:visited { color: #9E5205; } h2.date-header { margin-top:10px; margin-right:0px; margin-bottom:0px; margin-left:0px; color:#777777; font: normal bold 105% 'Trebuchet MS',Trebuchet,Verdana,Sans-serif; } h4 { color:#aa0033; } #sidebar h2 { color:#B8A80D; margin:0px; padding:0px; font:normal bold 150% Verdana,Sans-serif; } #sidebar .widget { margin-top:0px; margin-right:0px; margin-bottom:33px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; font-size:95%; } #sidebar ul { list-style-type:none; padding-left: 0; margin-top: 0; } #sidebar li { margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; list-style-type:none; font-size:95%; } .description { padding:0px; margin-top:7px; margin-right:12%; margin-bottom:7px; margin-left:5%; color:#9E5205; background:transparent; font:bold 100% Verdana,Sans-Serif; } .post { margin-top:0px; margin-right:0px; margin-bottom:30px; margin-left:0px; } .post strong { color:#000000; font-weight:bold; } pre,code { color:#999999; } strike { color:#999999; } .post-footer { padding:0px; margin:0px; color:#444444; font-size:80%; } .post-footer a { border:none; color:#968a0a; text-decoration:none; } .post-footer a:hover { text-decoration:underline; } #comments { padding:0px; font-size:110%; font-weight:bold; } .comment-author { margin-top: 10px; } .comment-body { font-size:100%; font-weight:normal; color:black; } .comment-footer { padding-bottom:20px; color:#444444; font-size:80%; font-weight:normal; display:inline; margin-right:10px } .deleted-comment { font-style:italic; color:gray; } .comment-link { margin-left:.6em; } .profile-textblock { clear: both; margin-left: 0; } .profile-img { float: left; margin-top: 0; margin-right: 5px; margin-bottom: 5px; margin-left: 0; border: 2px solid #DE7008; } #sidebar a:link { color:#999999; text-decoration:none; } #sidebar a:active { color:#ff0000; text-decoration:none; } #sidebar a:visited { color:sidebarlinkcolor; text-decoration:none; } #sidebar a:hover { color:#B8A80D; text-decoration:none; } .feed-links { clear: both; line-height: 2.5em; } #blog-pager-newer-link { float: left; } #blog-pager-older-link { float: right; } #blog-pager { text-align: center; } .clear { clear: both; } .widget-content { margin-top: 0.5em; } /** Tweaks for layout editor preview */ body#layout #outer-wrapper { margin-top: 0; } body#layout #main, body#layout #sidebar { margin-top: 10px; padding-top: 0; } -->

Wednesday, January 30, 2008

Use _beginthread/_beginthreadex instead CreateThread.



According to Jeffrey's book(Windows via C/C++) , When using CRT function/library(_fcvt, errno, atof, etc) in thread procedure, we should use _beginthread/_beginthreadex.

Because, _beginthread/_beginthreadex allocate memory area for CRT .
However CreateThread does not has any method for CRT.
So It makes an unpredicted quit and memory leaks.

I've tested CreateThread and _beginthread/_beginthreadex.
Below code is tested code.
Project was Consol Project and used Purify Plus for detect memory leaks.






DWORD WINAPI ThreadProc(__in LPVOID lpParameter);

DWORD WINAPI InputProc(__in LPVOID lpParameter);

unsigned _stdcall CallThreadHandlerProc(void *pThreadHandler);

unsigned _stdcall InputProc_BT(void *pThreadHandler);

BOOL bExit = FALSE;
HANDLE ThrdHandle=0;
HANDLE InputThrd = 0;
DWORD thrdID;

int _tmain(int argc, _TCHAR* argv[])
{

unsigned int ID1, ID2;

/**
Thread Creation using CreateThread

uncomment
these lines test for CreateThread


ThrdHandle = CreateThread(0,0, ThreadProc, 0, 0,
&thrdID);

InputThrd =
CreateThread(0,0, InputProc, 0, 0, &thrdID);


**/


/*Thread Creation using
_beginthreadex*/

ThrdHandle = reinterpret_cast(_beginthreadex0,1024,

CallThreadHandlerProc,0,0,&ID1));


InputThrd = reinterpret_cast(_beginthreadex(0,1024,

InputProc_BT,0,0, &ID2));


WaitForSingleObject(ThrdHandle,
INFINITE);

CloseHandle(ThrdHandle);
CloseHandle(InputThrd);

return 0;

}


DWORD WINAPI ThreadProc(__in LPVOID lpParameter)

{

while (bExit == FALSE)

{

int decimal, sign;

char *buffer;

double source = 3.1415926535;

buffer = _fcvt( source, 7, &decimal, &sign );


}

return 0;

}


DWORD WINAPI InputProc(__in LPVOID lpParameter)

{

char ch;

std::cin>>ch;

bExit = TRUE;

return 0;

}


unsigned _stdcall CallThreadHandlerProc(void *pThreadHandler)

{

while (bExit == FALSE)

{

int decimal, sign;

char *buffer;

double source = 3.1415926535;
buffer = _fcvt( source, 7, &decimal, &sign );

}

DWORD exitCode;

GetExitCodeThread(ThrdHandle, &exitCode);

_endthreadex(exitCode);

return 0;

}

unsigned _stdcall InputProc_BT(void *pThreadHandler)

{

char ch;

std::cin>>ch;

bExit = TRUE;

DWORD exitCode;

GetExitCodeThread(InputThrd, &exitCode);

_endthreadex(exitCode);

return 0;

}




Result is CreateThread occured memory leaks.
This capture shows memory leaks at using _fcvt CRT function.


Below capture shows no memory leaks when using _beginthreadex.

Sunday, January 20, 2008

The Greatest book of the this century was published for Visual C++ programmers.


WINDOWS Via C/C++.

Finally I got the book.

I'm really look forward Jeffrey's new book.


I didn't read yet, however hitted my heart big impact just looked appearance.


Wednesday, January 16, 2008

MFC Beta Now Available

MFC Beta Now Available
A beta version of a major MFC/TR1 feature pack is now available for download. Please note that this feature pack is only supported on systems which have the English language (ENU) version of Visual Studio Team System 2008 Team Suite or Visual Studio 2008 Professional Edition installed.
These components allow developers to create applications with the “look and feel” of the most popular Microsoft products - including Office, Internet Explorer, and Visual Studio. With this update, you’ll be able to build applications that utilize:
· Office Ribbon style interface
· Office 2007, Office 2003 and Office XP look and feel
· Modern Visual Studio-style docking toolbars and panes
· Fully customizable toolbars and menus
· A rich set of advanced GUI controls
· Advanced MDI tabs and groups
· And much more!
In addition, this release includes an implementation of TR1. Portions of TR1 are scheduled for adoption in the upcoming C++0x standard as the first major addition to the ISO 2003 standard C++ library. Our implementation includes a number of important features such as:
· Smart pointers
· Regular expression parsing
· New containers (tuple, array, unordered set, etc)
· Sophisticated random number generators
· Polymorphic function wrappers
· Type traits
· And more!
Please note that the beta installation may require Visual Studio 2008 media be available during setup. This will be resolved in the final release.
Enjoy!
The Visual C++ Development Team
Published Monday, January 07, 2008 2:42 PM by vcblog
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using RSS

Copied from VC++ Team Blog.
http://blogs.msdn.com/vcblog/archive/2008/01/07/mfc-beta-now-available.aspx