Application crashes in a call to PageSetupDlg

Hi,

I have an application that uses the PageSetupDlg API. I fill in a
PAGESETUPDLG object and pass it on the address of it to the API. The
filling up is done with the following (VC++) code:

        PAGESETUPDLG psd;
        // Initialize PAGESETUPDLG
        ZeroMemory(&psd, sizeof(PAGESETUPDLG));
        psd.lStructSize = sizeof(PAGESETUPDLG);
        psd.hwndOwner   = hwndOwner; // Handler to the owner of the
dialog. The owner is a VB app

        HGLOBAL devIn = GlobalAlloc(GMEM_MOVEABLE, dev->dmSize +
dev->dmDriverExtra); //dev is the device passed on to this piece of
code by the calling application
        DEVMODE *devCopy = (DEVMODE *)GlobalLock(devIn);
        CopyMemory( (PVOID)devCopy, dev, dev->dmSize +
dev->dmDriverExtra);
        GlobalUnlock(devIn);
        psd.hDevMode    = devIn;

        psd.hDevNames   = NULL;
        psd.Flags       = PSD_INTHOUSANDTHSOFINCHES | PSD_MARGINS |
PSD_ENABLEPAGEPAINTHOOK;
        psd.rtMargin.top = margins->top;
        psd.rtMargin.left = margins->left;
        psd.rtMargin.right = margins->right;
        psd.rtMargin.bottom = margins->bottom;
        psd.lpfnPagePaintHook = PaintHook;

Immediately after this, a call to PageSetupDlg(&psd) is made. When the
user clicks OK on the page setup dialog that gets displayed, the
application crashes. This was not happening in general; however I just
changed the printer connected to my machine and the crash started
occuring. I did some debugging and realized that after the user click
OK the control does not come back to the calling DLL (the one which
makes the call to PageSetupDlg). That being said, the  allback method
PaintHook does get called while PrintSetupDlg is drawing the sample
page.

The PaintHook method handles only the message WM_PSD_MARGINRECT from
Windows and returns False for all other cases. I verified that the call
from the PaintHook method is exiting with an expected return value
everytime this method is being called.

Any idea why a crash like this could be happening? I am experiencing
this crash on a Windows XP machine. I am trying to figure out if the
crash is being caused in the PageSetupDlg API call or due  to any
parameter being passed to it. Any help will be highly appreciated.

Thanks,
Ankit

0
10/10/2006 1:34:18 PM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
539 Views

Similar Articles

[PageSpeed] 50

I could figure out that the crash was happening because the VB
application used to pass a memory address where the details for the
DEVMODE structure used to get copied from the PageSetupDlg API. this
was a byte array with hardcoded size and the size of the data being
copied was greater than the byte array. Hence the crash.

Thanks,
Ankit

ankit.saxena@gmail.com wrote:
> Hi,
>
> I have an application that uses the PageSetupDlg API. I fill in a
> PAGESETUPDLG object and pass it on the address of it to the API. The
> filling up is done with the following (VC++) code:
>
>         PAGESETUPDLG psd;
>         // Initialize PAGESETUPDLG
>         ZeroMemory(&psd, sizeof(PAGESETUPDLG));
>         psd.lStructSize = sizeof(PAGESETUPDLG);
>         psd.hwndOwner   = hwndOwner; // Handler to the owner of the
> dialog. The owner is a VB app
>
>         HGLOBAL devIn = GlobalAlloc(GMEM_MOVEABLE, dev->dmSize +
> dev->dmDriverExtra); //dev is the device passed on to this piece of
> code by the calling application
>         DEVMODE *devCopy = (DEVMODE *)GlobalLock(devIn);
>         CopyMemory( (PVOID)devCopy, dev, dev->dmSize +
> dev->dmDriverExtra);
>         GlobalUnlock(devIn);
>         psd.hDevMode    = devIn;
>
>         psd.hDevNames   = NULL;
>         psd.Flags       = PSD_INTHOUSANDTHSOFINCHES | PSD_MARGINS |
> PSD_ENABLEPAGEPAINTHOOK;
>         psd.rtMargin.top = margins->top;
>         psd.rtMargin.left = margins->left;
>         psd.rtMargin.right = margins->right;
>         psd.rtMargin.bottom = margins->bottom;
>         psd.lpfnPagePaintHook = PaintHook;
>
> Immediately after this, a call to PageSetupDlg(&psd) is made. When the
> user clicks OK on the page setup dialog that gets displayed, the
> application crashes. This was not happening in general; however I just
> changed the printer connected to my machine and the crash started
> occuring. I did some debugging and realized that after the user click
> OK the control does not come back to the calling DLL (the one which
> makes the call to PageSetupDlg). That being said, the  allback method
> PaintHook does get called while PrintSetupDlg is drawing the sample
> page.
>
> The PaintHook method handles only the message WM_PSD_MARGINRECT from
> Windows and returns False for all other cases. I verified that the call
> from the PaintHook method is exiting with an expected return value
> everytime this method is being called.
>
> Any idea why a crash like this could be happening? I am experiencing
> this crash on a Windows XP machine. I am trying to figure out if the
> crash is being caused in the PageSetupDlg API call or due  to any
> parameter being passed to it. Any help will be highly appreciated.
> 
> Thanks,
> Ankit

0
11/22/2006 3:13:13 PM
Reply:

Similar Artilces:

Access 2007 Crash
I have a data base created in Access 2003 and I have converted to Access 2007 format. It seems to work just fine until you try to use the "FIND" button. It will located the item you used "FIND" to look for and then promply crash. Any ideas what would cause this and how to fix it ? ConfusedINVentura, Perhaps posting the code used will yield some helpful answers. -- Gina Whipp 2010 Microsoft MVP (Access) "I feel I have been denied critical, need to know, information!" - Tremors II http://www.regina-whipp.com/index_files/TipList.htm "...

A short video on RMS Loyalty Point Application
If you have searched for an affordable, functional and reliable Loyalty program for both Store or HQ installation...watch this brief Video. http://www.retail-pos.com/Loyalty.wmv Please contact us for detailed information and demo. sales(AT)retail-pos.com www.retail-pos.com ...

Get Runtime Error or Server Error in '/' Application
All of a sudden, we receive a Runtime Error or Server Error in '/'Application when trying to save changes to any data in CRM. Cannot log cases, new data, or changes to any existing Accounts, Cases, etc. Any ideas? I have tried rebooting server, stopping and restarting all CRM services, and have refreshed the link to the Server in the Deployment Manager. Hi Michele, have you turned on dev errors and checked the application event log? Mike ------------ Greaterthantwo Media http://www.greaterthantwo.com Coming Soon: Send bulk email templates with file attachments from Outlo...

How to transfer and copy Call list from iPhone to computer?
[url=http://www.transfer-iphone.com/transfer-and-backup-call-list-from-iphone-to-computer-with-iphone-tool-kits.html][b]How to transfer and copy Call list from iPhone to computer with iPhone Tool Kits?[/b][/url]Do you want to copy Call list from iPhone to computer for printting? [url=http://www.transfer-iphone.com/transfer-files-sms-contacts-call-list-ibooks-from-iphone-to-computer.html][b]iPhone Tool Kits[/b][/url] is an easy to use utility designed to help you back up all your files on your iPhone, so that you can recover any lost or missing songs, videos, books, photos and so on. It can eas...

outlook application error
I am using outlook 2000, while I start outlook I am getting the below message. Please send me the solution urgently. The instruction at "0x77c4371c" referenced memory at "0x8004010f". The Memory could not be "read". Thanking you, Gururaj Does Outlook start in safe mode? (Start | Run | outlook.exe /safe | ok button) The reason that I ask is that this message could mean a corrupted addin or registry key/value. If it is the later (registry key), it will require a new mail profile and the steps do vary since outlook can be configured in Internet Mail Only o...

adding button on edit.aspx and calling external .net web service in event handler
Hi, In the case section in Microsoft CRM Server if I open through web site in iis,I go to the edit.aspx and try adding a button server control or html control button,asp.net control addition gives error,because perhaps the formbase is a custom control refrenced through assembly,so I am looking to add a button on the page from where I can call a web service to send a fax,is it possible through isv config file,this is my first day in office with this server,I get errors in the case screen when i add aspx button to edit.aspx,the whole form seems to be made from 3 custom controls thru 3 assembly ...

Worksheet Crashing Excel
I know that this is going to be rather generic, but I have a macro enabled file that I created in excel 2007 (saved in 2003 format) that works great, but when I try to close the file, it ALWAYS asks if I want to save the changes (even if I JUST saved) and then whether I choose to save or not, it crashes excel. I know that you don't know what my code is, but is anyone aware of this happening, or a good place to start looking in my code to fix errors? I would have no problem posting code if needed... I am frustrated and lost... Thanks in advance for any help! Hi Shane, ...

CDialog crashes on second DoModal
Could it perhaps be because we are missing a a message handler when the first one is destroyed? On Tue, 11 Apr 2006 07:36:02 -0700, ultranet <ultranet@discussions.microsoft.com> wrote: >Could it perhaps be because we are missing a a message handler when the first >one is destroyed? It could be anything. Are you calling it like this? MyDlg dlg; dlg.DoModal(); dlg.DoModal(); If so, be aware that the second call does not start with a freshly initialized MyDlg object. It might work, but it might fail if member variables contain invalid values the second time around. Control vari...

Excel crashes immediately upon startup
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel excel seems to crash every time I try to start it up. several excel files I've tried to load immediately flash up, load for a brief second, and then excel crashes and asks to report a problem. I've tried removing preferences, reinstalling, removing old install receipts, even transferring my user to a clean system with no success. I've updated with the most recent version and still no success. the problem is within my user account, as excel starts fine in a test user. However with the amount of docume...

RMS POS crashing just before receipt prints
I have a Epson TM-T88IV printer installed with an APG cash drawer on RMS 2.0 SP3. they are configured through the Epson OPOS ADK and in the Database>Registers>Properties window. when I complete a sale the cash drawer opens but the program crashes before the receipt prints. It comes up with an error saying "Run-time error '9': Subscript out of range. The strange thing is, when I go to [ctrl+shift+F5] Peripherals, everything checks out A-OK. I've read countless discustions trying to figure this out and nothing seems to be working. Anyone have an idea...

HELP
I have some problems that seems to be related to the NT UserID. I have some code that creates an email as follow (Client side call to Outlook): <script LANGUAGE="VBScript"> Set objsession = createobject("OUTLOOK.APPLICATION") Set objNewMail = objsession.CreateItem(olMailItem) objNewMail.Bcc = "List of recipient variable..." objNewMail.Subject = "" objNewMail.Recipients.ResolveAll objNewMail.Display window.close </SCRIPT> For user A, wherever he logs in it works fine. For user B, wherever he logs in the...

Get data from oracle application database into project server 2007
Scenario we have finance dept and HR dept and we have implemented EPM 2007 . now management main consults with Budgeting and costing. they dont want to again enter data about resource (standard rates,overtime rates , fixed cost , cost/use) e.t.c and want to integrate from HR dept and Finance Dept applications with the oracle database and in that oracle database these data is already exist of users. how i can integrate from these oracle applications and get data of those users which are added in the project server 2007 from active directory . what is the best and easy w...

Got a call from MSFT
I had a trouble ticket opened, and someone from Product Development" called to get some feedback on the product. Should I "let him have it"? Never had MSFT call before, so I think they are getting the message that 05 is a POS. Can't hurt. Might help. "AA" <anonymous@discussions.microsoft.com> wrote in message news:0de801c4abcb$575f7140$a401280a@phx.gbl... > I had a trouble ticket opened, and someone from Product > Development" called to get some feedback on the product. > Should I "let him have it"? Never had MSFT call before, ...

How to reinstall Money 2007 Plus after a coumputer crash?
Where can I find instructions on how to reinstall Money 2007 Plus after a computer crash? I had to reformat my hard drive. I located the 2005 CD and the serial number for my online purchase of Money Plus in 2007. Reinstalling the 2005 software did not seem to offer a way to upgrade without the CD for the 2007 version. I've down loaded the trial version expecting an option to enter my serial number but again I was stumped. Thanks for any help. In microsoft.public.money, doug.fett@raymondcorp.com wrote: >here can I find instructions on how to reinstall Money 2007 Plus >after a c...

Outlook 2007 Crashing When Accessing "Old" Emails
I just added a new computer to our home office (OS: Windows 7 Home Premier). Outlook 2007 was easily installed and I could create and send email with no problem. I copied my .pst files from my old computer (also Outlook 2007, but XP Pro SPF) onto the new computer. But when I select an email to read from one of these old pst files Outlook freezes. Same thing happens if I copy a message from the old pst into the new account and attempt to read the message ... Outlook freezes. I can open Sent messages that originated from the new email account, though. Very odd and frust...

Hard Drive Crash---Import pst file
I have a back-up file (~ 3.3 GB) of Outlook 2007 from crashed hard drive . When I try to import PST file I get the following message: "Errors have been detected in the file" Tried Scanpst.exe to no avail. When I try to open directly from the recovered file using Outlook I get a message that the "attachment size exceeds the allowable limit" Suggestions on how to import/repair PST file would be greatly appreciated. Thanks. Jimmy Is this backup a copy of a pst file or was it created with some backup software? Is this file located on the current hd? Are...

HDD Crashed, recovered data but need 'Administer permisssion'
Every time I go into one particular database it comes up "You dont have permisson to run 'AutoExec'" Apparantly I dont have "Administer permisssion" I have searched Google and access to find out how to set this to no avail, can anyone help? On Sat, 01 Mar 2008 11:00:00 GMT, "Dave Cox" <davecox61@nospamtiscali.co.uk> wrote: >Every time I go into one particular database it comes up "You dont have >permisson to run 'AutoExec'" Apparantly I dont have "Administer permisssion" >I have searched Google and acces...

when to call DispatchMessage
Hi, if I handle an event in an event loop do I still need to call DispatchMessage afterwards? or is it only for the messages I don't handle? It's only for message that you don't want any further processing done on. That said, this is an MFC newsgroup. It's is very rare to implement your own "event loop" in an MFC application. Makes me think I may not really understand what it is you are doing. -- Jonathan Wood SoftCircuits http://www.softcircuits.com Available for consulting: http://www.softcircuits.com/jwood/resume.htm "alexl" <alextheblade@gmai...

Application exception in CMdiFrameWnd::OnUpdateFrameTitle
Hi, We have developed an MDI application, and recently made changes to it to: close an existing document and display a new one. This is crashing on a customer's PC, but despite extensive testing in the lab we have been unable to reproduce the crash. The release exe was compiled with VisualStudio6 and with the debug option of "program database" to generate a symbol pdb file. The customer has kindly sent us a 6Mb DrWatson crash dump file which we have analyzed. The problem appears to come from MFC42! CMDIFrameWnd::OnUpdateFrameTitle+0x74 I attach the Windbg analysis results (belo...

MS office 2004 installed but applications not opening??
Hi, After searching the newsgroup postings for similar problems, none of the previous solutions seem to work for me and I am at a loss as to what the problem could be. Until recently office:mac 2004 was running fine on my 12" ibook 1.33GHz but due to unforeseen coffee spillage :(, I am now on a Macbook 2.0 GHz and office no longer works. I did one install and by mistake used one of the product keys that I had used before (whoops). Everything worked fine but after 24 hrs all office applications stopped responding (the icon would appear in the dock, bounce once and then dissapear). I thoug...

Phone Call
Is there are way to change the Call Initiator on a batch of phone call activities? When Leads are reassigned the activities are reassigned but the Call Initiator field remains set to value of the phone call creator. ...

Could I use toolbar and statusbar in my dialog based MFC application?
Hi: I am new to vc++. Could an dialog based MFC application use toolbar like VB does. And how to use it? ben :-) Yes, you can. See http://www.codeproject.com/statusbar/dlgstatbar01.asp and http://www.codeproject.com/dialog/dlgtoolstatusbar.asp -- Regards, Nish [VC++ MVP] http://www.voidnish.com http://blog.voidnish.com "mRbEn" <mrben_2004@126.com> wrote in message news:OJnc1mTJFHA.2560@TK2MSFTNGP09.phx.gbl... > Hi: > I am new to vc++. Could an dialog based MFC application use toolbar like > VB > does. And how to use it? > > ben > :-) > > ...

Word Crash
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) I have a Word merge file, data is in a Filemaker file, and every time I try to save the file Word crashes. Hi Ann: Maggie the document. The Maggie: 1. Create a new blank document 2. Carefully select all of the text in the bad document EXCEPT the last paragraph mark 3. Copy it. 4. Paste in the new document. 5. Save under a new file name and close all, then re-open. This technique for de-corrupting is known as "Doing a 'Maggie'", after Margaret Secara from the TECHWR-L mailing list, who first...

Exchange crashing #2
Good afternoon, I am having a problem with my exc. 2003 server. upon booting -up it works fine for a short while but after 30min or so, no-one can login. the ex. services are all running but when you get an error when you open up sys. manager. the app. event log gave me this error: Process STORE.EXE (PID=2820). Topology Discovery failed, error 0xffffffff. what can be causing this and how can i fix it, Thanks. -- Colin Camp There must be more errors than that in the log. What are the Event IDs? Topology Discovery failures are typically an indication of AD problems. You could run dc...

vbscript using internetexplorer.application does mousedown?
I have an issue with using vbscript to login to a website, key some criteria, and download a file. I've already overcome a few roadblocks since the site is driven by javascript and doesn't respond like normal HTML. I have ran into an issue where the javascript on the site is looking for a "mousedown" event. The "mousedown" fires off a function to reload a frame, while the "click" part is cancled by another function. Works fine with a real mouse and person, but I need this automated, and when I use: ie.Document.Frames("undefine...