<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="https://syndication.webwiz.net/rss_namespace/">
 <channel>
  <title>Codejock Developer Community : AfxGetMainWnd() returns NULL?</title>
  <link>http://forum.codejock.com/</link>
  <description><![CDATA[This is an XML content feed of; Codejock Developer Community : General Discussion : AfxGetMainWnd() returns NULL?]]></description>
  <copyright>Copyright (c) 2006-2013 Web Wiz Forums - All Rights Reserved.</copyright>
  <pubDate>Mon, 27 Apr 2026 17:24:35 +0000</pubDate>
  <lastBuildDate>Tue, 02 Oct 2007 04:16:31 +0000</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 12.04</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>forum.codejock.com/RSS_post_feed.asp?TID=8230</WebWizForums:feedURL>
  <image>
   <title><![CDATA[Codejock Developer Community]]></title>
   <url>http://forum.codejock.com/forum_images/codejock-logo.gif</url>
   <link>http://forum.codejock.com/</link>
  </image>
  <item>
   <title><![CDATA[AfxGetMainWnd() returns NULL? : Thanks for above, fixed now as...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26775&amp;title=afxgetmainwnd-returns-null#26775</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=2928">terrym</a><br /><strong>Subject:</strong> 8230<br /><strong>Posted:</strong> 02 October 2007 at 4:16am<br /><br />Thanks for above, fixed now as we rewrote our own ProcessShellCommand, which works perfect, not sure why the original one worked and after a few changes it stopped, but thanks for above.<DIV>&nbsp;</DIV><DIV>Just glad to get it working again as behind schedule now ;)</DIV>]]>
   </description>
   <pubDate>Tue, 02 Oct 2007 04:16:31 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26775&amp;title=afxgetmainwnd-returns-null#26775</guid>
  </item> 
  <item>
   <title><![CDATA[AfxGetMainWnd() returns NULL? : AIUI, m_pMainWnd only becomes...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26717&amp;title=afxgetmainwnd-returns-null#26717</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=1770">Roger</a><br /><strong>Subject:</strong> 8230<br /><strong>Posted:</strong> 01 October 2007 at 11:57am<br /><br />AIUI, m_pMainWnd only becomes valid <strong>after</strong> calling ProcessShellCommand. However, during this function, OnNewDocument() gets called before the frame has been created.<DIV>&nbsp;</DIV><DIV>This only happens the first time the program starts, in every other call of OnNewDocument(), the main window pointer will be valid.</DIV><DIV>&nbsp;</DIV><DIV>Can you defer your processing until OnInitialUpdate() for a view?</DIV><DIV>&nbsp;</DIV><DIV>Regards,</DIV><DIV>Roger</DIV>]]>
   </description>
   <pubDate>Mon, 01 Oct 2007 11:57:10 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26717&amp;title=afxgetmainwnd-returns-null#26717</guid>
  </item> 
  <item>
   <title><![CDATA[AfxGetMainWnd() returns NULL? : but m_pMainWnd is NULL :( ]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26713&amp;title=afxgetmainwnd-returns-null#26713</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=2928">terrym</a><br /><strong>Subject:</strong> 8230<br /><strong>Posted:</strong> 01 October 2007 at 10:29am<br /><br />but m_pMainWnd is NULL :(]]>
   </description>
   <pubDate>Mon, 01 Oct 2007 10:29:31 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26713&amp;title=afxgetmainwnd-returns-null#26713</guid>
  </item> 
  <item>
   <title><![CDATA[AfxGetMainWnd() returns NULL? : Surely the document architecture...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26712&amp;title=afxgetmainwnd-returns-null#26712</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=2928">terrym</a><br /><strong>Subject:</strong> 8230<br /><strong>Posted:</strong> 01 October 2007 at 10:19am<br /><br />Surely the document architecture creates the CMainFrame instance in the above code, all we do after is <FONT size=2><P></FONT><FONT color=#008000 size=2>// show and update window</P></FONT><FONT size=2><P></FONT><FONT color=#010001 size=2>m_pMainWnd</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>ShowWindow</FONT><FONT size=2>( </FONT><FONT color=#010001 size=2>SW_SHOW</FONT><FONT size=2> );</P><P></FONT><FONT color=#010001 size=2>m_pMainWnd</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>UpdateWindow</FONT><FONT size=2>();</P><DIV></DIV><DIV></DIV></FONT>]]>
   </description>
   <pubDate>Mon, 01 Oct 2007 10:19:57 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26712&amp;title=afxgetmainwnd-returns-null#26712</guid>
  </item> 
  <item>
   <title><![CDATA[AfxGetMainWnd() returns NULL? : Ah ok, I must be blind and getting...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26707&amp;title=afxgetmainwnd-returns-null#26707</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=2928">terrym</a><br /><strong>Subject:</strong> 8230<br /><strong>Posted:</strong> 01 October 2007 at 9:21am<br /><br />Ah ok, I must be blind and getting dumb the older I get<DIV>&nbsp;</DIV><DIV>Anychance you can show example below please</DIV>]]>
   </description>
   <pubDate>Mon, 01 Oct 2007 09:21:33 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26707&amp;title=afxgetmainwnd-returns-null#26707</guid>
  </item> 
  <item>
   <title><![CDATA[AfxGetMainWnd() returns NULL? : You didn&amp;#039;t paste lines _after_...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26706&amp;title=afxgetmainwnd-returns-null#26706</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=6851">Oleg</a><br /><strong>Subject:</strong> 8230<br /><strong>Posted:</strong> 01 October 2007 at 9:16am<br /><br />You didn't paste lines _after_ <FONT color=#010001 size=2>ProcessShellCommand where you create instance of CMainFrame.</FONT>]]>
   </description>
   <pubDate>Mon, 01 Oct 2007 09:16:00 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26706&amp;title=afxgetmainwnd-returns-null#26706</guid>
  </item> 
  <item>
   <title><![CDATA[AfxGetMainWnd() returns NULL? : Hi  But this is not the case:  CSingleDocTemplate...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26702&amp;title=afxgetmainwnd-returns-null#26702</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=2928">terrym</a><br /><strong>Subject:</strong> 8230<br /><strong>Posted:</strong> 01 October 2007 at 8:57am<br /><br /><P>Hi</P><DIV>&nbsp;</DIV><DIV>But this is not the case:</DIV><DIV>&nbsp;</DIV><FONT size=2><P></FONT><FONT color=#010001 size=2>CSingleDocTemplate</FONT><FONT size=2> *</FONT><FONT color=#010001 size=2>pDocTemplate</FONT><FONT size=2>;</P><DIV></FONT><FONT color=#010001 size=2>pDocTemplate</FONT><FONT size=2> = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#010001 size=2>CSingleDocTemplate</FONT><FONT size=2>( </FONT><FONT color=#010001 size=2>IDR_MAINFRAME</FONT><FONT size=2>, </FONT><FONT color=#010001 size=2>RUNTIME_CLASS</FONT><FONT size=2>( </FONT><FONT color=#010001 size=2>CMainDoc</FONT><FONT size=2> ), </FONT><FONT color=#010001 size=2>RUNTIME_CLASS</FONT><FONT size=2>( </FONT><FONT color=#010001 size=2>CMainFrame</FONT><FONT size=2> ), </FONT><FONT color=#010001 size=2>RUNTIME_CLASS</FONT><FONT size=2>( </FONT><FONT color=#010001 size=2>CWorkspaceView</FONT><FONT size=2> ) );</DIV><P></FONT><FONT color=#010001 size=2>AddDocTemplate</FONT><FONT size=2>( </FONT><FONT color=#010001 size=2>pDocTemplate</FONT><FONT size=2> );</P></FONT><FONT size=2><P></FONT><FONT color=#010001 size=2>EnableShellOpen</FONT><FONT size=2>();</P></FONT><FONT size=2><P></FONT><FONT color=#010001 size=2>CCommandLineInfo</FONT><FONT size=2> </FONT><FONT color=#010001 size=2>cmdInfo</FONT><FONT size=2>;</P><P></FONT><FONT color=#010001 size=2>ParseCommandLine</FONT><FONT size=2>( </FONT><FONT color=#010001 size=2>cmdInfo</FONT><FONT size=2> );</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> ( !</FONT><FONT color=#010001 size=2>ProcessShellCommand</FONT><FONT size=2>( </FONT><FONT color=#010001 size=2>cmdInfo</FONT><FONT size=2> ) )</P><DIV></DIV><DIV>{</DIV><DIV>// do error</DIV><DIV>}</DIV><DIV>&nbsp;</DIV><DIV>&nbsp;</DIV><DIV>&nbsp;</DIV><DIV>See the above works fine if I just run the app, but if I pass a command line to load a file it then does it</DIV><DIV>&nbsp;</DIV><DIV>it's like something is stopping m_pMainWnd from initialising as it creates the CMainFrame etc. for us using the doc architecture</DIV><DIV>&nbsp;</DIV><DIV>Any ideas much appreciated</FONT></DIV>]]>
   </description>
   <pubDate>Mon, 01 Oct 2007 08:57:28 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26702&amp;title=afxgetmainwnd-returns-null#26702</guid>
  </item> 
  <item>
   <title><![CDATA[AfxGetMainWnd() returns NULL? : Hi,  Obviously you create CMainFrame...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26700&amp;title=afxgetmainwnd-returns-null#26700</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=6851">Oleg</a><br /><strong>Subject:</strong> 8230<br /><strong>Posted:</strong> 01 October 2007 at 8:50am<br /><br /><DIV>Hi,</DIV><DIV>&nbsp;</DIV><DIV>Obviously you&nbsp; create CMainFrame after <FONT color=#010001 size=2>ProcessShellCommand call.</DIV></FONT>]]>
   </description>
   <pubDate>Mon, 01 Oct 2007 08:50:36 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26700&amp;title=afxgetmainwnd-returns-null#26700</guid>
  </item> 
  <item>
   <title><![CDATA[AfxGetMainWnd() returns NULL? : It must be in our code, but it...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26690&amp;title=afxgetmainwnd-returns-null#26690</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=2928">terrym</a><br /><strong>Subject:</strong> 8230<br /><strong>Posted:</strong> 01 October 2007 at 7:05am<br /><br />It must be in our code, but it seems that when our app calls <DIV>&nbsp;</DIV><FONT size=2><P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> ( !</FONT><FONT color=#010001 size=2>ProcessShellCommand</FONT><FONT size=2>( </FONT><FONT color=#010001 size=2>cmdInfo</FONT><FONT size=2> ) )</P><DIV></DIV><P>&nbsp;</P><P>this in turn calls OnOpenDocument (which we have overridden) but if we pass a filename on the commandline then m_pMainWnd is null, if we dont pass a filename then it is correct</P><DIV></DIV><DIV></DIV>Strange, any ideas much appreciated</FONT>]]>
   </description>
   <pubDate>Mon, 01 Oct 2007 07:05:36 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26690&amp;title=afxgetmainwnd-returns-null#26690</guid>
  </item> 
  <item>
   <title><![CDATA[AfxGetMainWnd() returns NULL? : Reason can be only in code you...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26659&amp;title=afxgetmainwnd-returns-null#26659</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=6851">Oleg</a><br /><strong>Subject:</strong> 8230<br /><strong>Posted:</strong> 30 September 2007 at 9:16am<br /><br /><P>Reason can be only in code you have. Trace where you created CMainframe and where you call AfxGetMainWnd() .</P>]]>
   </description>
   <pubDate>Sun, 30 Sep 2007 09:16:25 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=8230&amp;PID=26659&amp;title=afxgetmainwnd-returns-null#26659</guid>
  </item> 
 </channel>
</rss>