Search This Blog

Saturday, February 21, 2009

VC++ Code equivalent to DoEvents is Visual basic

//VC++ Code equivalent to DoEvents is Visual basic

void DoEvents()
{
MSG msg;

while ( ::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if ( ::GetMessage(&msg, NULL, 0, 0))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
else
{
break;
}
}
}

MFC code to get the Path of Appliction and DLL






//MFC code to get the Path of Appliction
CString GetExePath ()
{
   TCHAR szPath[_MAX_PATH];
   szPath[0] = '\0';

   GetModuleFileName( NULL, szPath, sizeof(szPath) );

   CString csPath(szPath);

   int nPos = csPath.ReverseFind('\\');
   if ( nPos != -1)
   {
       csPath = csPath.Left(nPos+1);
   }
   else
   {
       csPath = "";
   }

   return csPath ;

}


//MFC code to get the Path of DLL if it is loaded from different path
#include <atlbase.h>
CString GetDLLPath ()
{
   TCHAR szPath[_MAX_PATH];
   szPath[0] = '\0';

   GetModuleFileName((HINSTANCE)&__ImageBase, szPath, sizeof(szPath) );

   CString csPath(szPath);

   int nPos = csPath.ReverseFind('\\');
   if ( nPos != -1)
   {
       csPath = csPath.Left(nPos+1);
   }
   else
   {
       csPath = "";
   }

   return csPath ;

}