Access Violation when trying to print from ASPX using IE9 on Windows 7 32 bit

Access Violation when trying to print from ASPX using IE9 on Windows 7 32 bit

Hi Experts,
                       Thanks for your time! I could really use your help on an Access Violation issue that I encountered when using a VC++ dll in my VB.NET Web Application. One point of interest here is that it occurs only on IE9 operating on a 32 bit ( but not on the 64 bit version) Windows 7 Enterprise machine.

We have a print control written in VC++ which is invoked to print a particular page. It is invoked from Javascript after instantiating the object using <object> in the ASPX page.

                        The usual methodology for Printing is used here. We use the HTMLDocument and create LPOLECOMMANDTARGET pointer to the document. We make a call using the pointer->Exec while using OLECMDID_PAGESETUP which opens the PageSetup Dialog. After this, another Exec call is made using OLECMDID_PRINT to print the page.

Generic Code:
....

lpTarget->Exec(NULL, OLECMDID_PAGESETUP, OLECMDEXECOPT_PROMPTUSER, NULL , NULL);

...

lpTarget->Exec(NULL, OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, NULL , NULL);


                  Before these calls are made, we get the Dialogs for Header,Footer,Margins and using a call back function for generating the PageSetup dialog, we set custom values for the Headers and Footers before printing the document.  We use the CBT Hook Codes: HCBT_CREATEWND,HCBT_ACTIVATE,HCBT_DESTROYWND to generate the Headers and Footers. It is here that the Access Violation Error is encountered.


                We attempt to Click an OK Button using the SendMessage Function: SendMessage(okHWND,BM_CLICK,0,0) for the Footer dialog.This results in an access violation error  at location 0x000005 for 0x000000. The weird part is that this error is only reproducible on IE9 + Windows 7 32 bit. I tested on IE9 + Windows 7 64 bit and did not get any errors!

               I have verified that the handle for the OK button (okHWND) is not NULL.  I have tried using WM_LBUTTONDOWN and WM_LBUTTONUP instead of BM_CLICK, but to no avail..

I did come across a partial fix though. When I replaced SendMessage with PostMessage, I did not get any crash. But the PageSetupDialog appeared for a millisecond and disappeared; i.e,
Pagesetup was by-passed and the file started printing.

Can any of you throw some light into this matter?
atlasmedicalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

atlasmedicalAuthor Commented:
I solved the problem myself.. I just replaced SendMessage with PostMessage to resolve the problem.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.