Click here to Skip to main content
15,918,742 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralOnPaint and CPaintDC Pin
Malcolm Smart14-Jan-05 3:02
Malcolm Smart14-Jan-05 3:02 
GeneralRe: OnPaint and CPaintDC Pin
Ryan Binns14-Jan-05 3:40
Ryan Binns14-Jan-05 3:40 
GeneralRe: OnPaint and CPaintDC Pin
Mike Dimmick14-Jan-05 3:40
Mike Dimmick14-Jan-05 3:40 
GeneralRe: OnPaint and CPaintDC Pin
Malcolm Smart14-Jan-05 4:37
Malcolm Smart14-Jan-05 4:37 
GeneralLoading HTML documents Pin
Hans Ruck14-Jan-05 2:00
Hans Ruck14-Jan-05 2:00 
GeneralPls Help with CMetaFileDC and CScrollView Pin
Dimitris Vikeloudas14-Jan-05 0:41
Dimitris Vikeloudas14-Jan-05 0:41 
QuestionVC6 - bug? Could you try on your Box? Pin
peterchen14-Jan-05 0:24
peterchen14-Jan-05 0:24 
AnswerRe: VC6 - bug? Could you try on your Box? Pin
peterchen14-Jan-05 0:29
peterchen14-Jan-05 0:29 
// RelBugRepro.cpp : reproduces a seemingly optimizer problem in VC& SP5 or SP6
// an annotated version is also available

#include <comdef.h>

// ------------ HELPER -----------------------------------------
// Mostly mock objects and -functions.  For the actual function exposing the issue, see below
inline GUID GetSomeID()
{
   static const GUID someid_ = 
   { 0x11112222, 0x3333, 0x4444, { 0x55, 0x55, 0x66, 0x66, 0x77, 0x77, 0x88, 0x88 } };
   
   return someid_;
}

IUnknownPtr GetSomeUnknown()  // I need a working IUnknown, I guess a mock would do, too
{
   try
   {
      static IUnknownPtr unk;
      struct __declspec(uuid("{CFC399AF-D876-11d0-9C10-00C04FC99C8E}")) idMSXML;
      if (unk==NULL)
         unk.CreateInstance(__uuidof(idMSXML));
      if (unk != NULL)
         return unk;
   }
   catch(...) {} 

   DebugBreak(); // failed to create object, some other problem
   return NULL;
}

// inheriting twice from IUnknownPtr. Of course the original is a bit more functional :)
struct CPtrWrap : IUnknownPtr
{
    CPtrWrap(IUnknownPtr unk) : IUnknownPtr(unk) {}
};

struct CFinalPtr : public CPtrWrap
{
   CFinalPtr(CPtrWrap psw) : CPtrWrap(psw) {}
};

// this function gets called with invalid parameters
static IUnknownPtr GetItem(GUID id, long l0, long l1)
{
   return (id == GetSomeID()) ? GetSomeUnknown() : NULL;
}

// mock for MFC CCmdUI
struct CEnableMe
{
   virtual void Enable(BOOL bOn = TRUE) {}
};


// mock for MFC CWinApp
struct CMyOneApp
{
   int m_mainFrame;
   CMyOneApp() : m_mainFrame(1) {}
   void UpdateEditDuplicate(CEnableMe * pCmdUI);
};

// ========= the function in question ===================
void CMyOneApp::UpdateEditDuplicate(CEnableMe * pCmdUI) 
{
   try {
      bool enable = false;

      { 
         rand();
         GUID ParentID = GetSomeID();
         CFinalPtr itParent = GetItem(ParentID, 0, 0);

         if (itParent == NULL) _com_issue_error(E_POINTER);
         enable = m_mainFrame != NULL;
      }
      pCmdUI->Enable( enable );
      return;
   } catch(_com_error ce)
   {  
      // Anything goes here
      OutputDebugString(" *********** FAILED ***********\n");
   }
}                                                                                


// ------------ WinMain --------------------
int APIENTRY WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
   CEnableMe cmdUI;
   CoInitialize(0); // required since we call the GetUnknown
   
   CMyOneApp app;
   app.UpdateEditDuplicate(&cmdUI);
   return 0;
   CoUninitialize();
}



I never really know a killer from a savior
boost your code || Fold With Us! || sighist | doxygen

AnswerRe: VC6 - bug? Could you try on your Box? Pin
Aamir Butt14-Jan-05 0:38
Aamir Butt14-Jan-05 0:38 
GeneralRe: VC6 - bug? Could you try on your Box? Pin
peterchen14-Jan-05 1:24
peterchen14-Jan-05 1:24 
GeneralRe: VC6 - bug? Could you try on your Box? Pin
Aamir Butt16-Jan-05 17:31
Aamir Butt16-Jan-05 17:31 
GeneralRe: VC6 - bug? Could you try on your Box? Pin
peterchen16-Jan-05 18:42
peterchen16-Jan-05 18:42 
AnswerRe: VC6 - bug? Could you try on your Box? Pin
KaЯl14-Jan-05 1:37
KaЯl14-Jan-05 1:37 
AnswerRe: VC6 - bug? Could you try on your Box? Pin
Ryan Binns14-Jan-05 1:59
Ryan Binns14-Jan-05 1:59 
GeneralRe: VC6 - bug? Could you try on your Box? Pin
Ryan Binns14-Jan-05 2:39
Ryan Binns14-Jan-05 2:39 
GeneralRe: VC6 - bug? Could you try on your Box? Pin
peterchen14-Jan-05 3:16
peterchen14-Jan-05 3:16 
GeneralRe: VC6 - bug? Could you try on your Box? Pin
peterchen14-Jan-05 3:07
peterchen14-Jan-05 3:07 
GeneralRe: VC6 - bug? Could you try on your Box? Pin
Ryan Binns14-Jan-05 3:16
Ryan Binns14-Jan-05 3:16 
GeneralEXE Icon modifier Pin
CVNK7613-Jan-05 23:20
CVNK7613-Jan-05 23:20 
GeneralRe: EXE Icon modifier Pin
Joel Holdsworth15-Jan-05 0:19
Joel Holdsworth15-Jan-05 0:19 
GeneralRe: EXE Icon modifier Pin
cvnk17-Jan-05 0:26
cvnk17-Jan-05 0:26 
GeneralTired of ...... Pin
pc_dev13-Jan-05 22:49
pc_dev13-Jan-05 22:49 
GeneralRe: Tired of ...... Pin
Maximilien14-Jan-05 0:40
Maximilien14-Jan-05 0:40 
GeneralRe: Tired of ...... Pin
Roger Allen14-Jan-05 0:58
Roger Allen14-Jan-05 0:58 
Generalin view of MDI app OnMove() never happens Pin
T.T.H.13-Jan-05 22:45
T.T.H.13-Jan-05 22:45 

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.