Thread: Print Preview

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    Print Preview

    Hello again everyone,

    Another quick question. I build a program in debug mode using MFC.dll as shared and my print preview works fine. If I build the program as a release using standard windows libraries(since the program will be running on machines running windows 9x), I get an assertion error. I don't know why it would be because I am using standard windows libraries because the print function works building that way. Any ideas?


    Thanks,
    Kendal

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Check that the functions you used are compatible with later versions of MS OS's.

    ie InitCommonControlsEx() needs WIN98

    Else narrow it down for us a bit by posting the code that causes the problem.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    I am using XP and when I build a release version with the 'use of MFC ' project property set to standard windows library, the print option works just fine. The print preview gives me an assertion error. The systems this program will run on should be 98 and later. I don't know why the release will not run on XP right now. The .cpp code that controls the print and print preview commands is attached to this thread. The .h file is in this thread because I could not attach two files. Let me know what you think.

    [code]
    #include "Doc.h"

    /////////////////
    // Picture view is a typical scroll view.
    //
    class CPictureView : public CScrollView {
    public:
    virtual ~CPictureView();
    CPictureDoc* GetDocument() { return (CPictureDoc*)m_pDocument; }

    protected:
    BOOL m_rcImage; // rect to display image in
    UINT m_iHowScale; // how to scale image
    BOOL _printing;

    CPictureView();
    void GetImageRect(CRect& rc);
    void SetScrollSizes();
    void PrintingAdjustment(CSize& sz);

    virtual void OnDraw(CDC* pDC); // overridden to draw this view
    virtual void OnInitialUpdate(); // called first time after construct

    //////////////////////Virtual Print Functions
    virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
    virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
    virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);


    // command/message handlers
    afx_msg void OnViewScale(UINT nID);
    afx_msg void OnUpdateViewScale(CCmdUI* pCmdUI);
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    afx_msg void OnSize(UINT nType, int cx, int cy);

    DECLARE_DYNCREATE(CPictureView)
    DECLARE_MESSAGE_MAP()
    };


    Thanks again,
    Kendal

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    Did I forget to attach the cpp file? I'm sorry. I will attach it to this message. Also, I THINK that I may have tracked down where the problem might be occuring, but I cannot figure out why. Look in the following code....

    Code:
    BOOL AFXAPI _AfxCheckDialogTemplate(LPCTSTR lpszResource, BOOL bInvisibleChild)
    {
    	ASSERT(lpszResource != NULL);
    	HINSTANCE hInst = AfxFindResourceHandle(lpszResource, RT_DIALOG);
    	HRSRC hResource = ::FindResource(hInst, lpszResource, RT_DIALOG);
    	if (hResource == NULL)
    	{
    		if (DWORD_PTR(lpszResource) > 0xffff)
    			TRACE(traceAppMsg, 0, _T("ERROR: Cannot find dialog template named '%s'.\n"),
    				lpszResource);
    		else
    			TRACE(traceAppMsg, 0, "ERROR: Cannot find dialog template with IDD 0x%04X.\n",
    				LOWORD((DWORD_PTR)lpszResource));
    		return FALSE;
    	}
    whenever the code hits the HRSRC hResource, it returns a null value. The only reason that could be is because of the hInst value. When I try to step into the AfxFindResourceHandle function, I get a message that "There is no source code available in the current location". The AfxFindResourceHandle function is located in dllinit.cpp which is located in the mfc/src folder within .NET. The folder is being accessed because the program steps into other .cpp files in the same folder. Why would it not step into the AfxFindResourceHandle function????? Any ideas.

    Thanks,
    Kendal

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    Found It

    I found the problem.......Just to let everybody know.
    The resources preprocessor definition had _AFXDLL in its values list. I don't know exactly what this is supposed to do in general but I did trace the AfxFindResourceHandle function header down to the AFXWIN.H file and within that file it has the following declaration:

    Code:
    // Use AfxFindResourceHandle to find resource in chain of extension DLLs
    #ifndef _AFXDLL
    #define AfxFindResourceHandle(lpszResource, lpszType) AfxGetResourceHandle()
    #else
    HINSTANCE AFXAPI AfxFindResourceHandle(LPCTSTR lpszName, LPCTSTR lpszType);
    #endif
    I guess that when the program is not using MFC as a shared DLL it has to DEFINE AfxFindResourceHandle??? Generally speaking....What is _AFXDLL supposed to represent as a preprocess definition?????

    Thanks everyone,
    Kendal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. merging linked lists
    By scwizzo in forum C++ Programming
    Replies: 15
    Last Post: 09-14-2008, 05:07 PM
  2. Print Preview problem
    By MarkookraM in forum Windows Programming
    Replies: 4
    Last Post: 09-24-2006, 10:13 AM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  4. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM
  5. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM