473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SetHdevmode problem

92
Hi
I am trying to change the DevMode structure to change the paper source to be used by the PrintDocument.
I know that there is a PaperSource provided by the PrintDocument.PrinterSettings but the requirement of my program is to use our API to change the DevMode and set the new DevMode to the PrintDocument.

When I tried it, the program will successfuly print a document with whatever paper source I provide on the PrintDocument, but only on the first pass. If I execute the same code again, the program will suddenly close without prompting any error when it reaches the PrintDocument.Print().

I'm using VB 2003.
Here's the code snippet:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private WithEvents pd As New PrintDocument
  3. ...
  4.  
  5. // The following lines are part of the click event handler:
  6. Dim dm, hInstance as IntPtr
  7. Dim dmSize as Int32
  8. ...
  9. dm = Nothing
  10. GetDevMode(hInstance, dm, dmSize) //Gets the size of the DevMode
  11. dm = Marshal.AllocCoTaskMem(dmSize) //Allocate memory
  12. GetDevMode(hInstance, dm, dmSize) //Set the DevMode
  13. pd.PrinterSettings.SetHDevMode(dm)
  14. pd.Print() //Program fails here on the next execution
  15. ...
  16. Marshal.FreeCoTaskMem(dm)
  17. ...
  18.  
  19.  

GetDevMode will consistently set the dmSize, while it also sets the dm to point to a memory location, thus I can say that there is no problem on our GetDevMode API (and, we have a version in C++ of the same program, using the same API and it works perfectly fine.)

Did I miss something on the settings of the PrintDocument or misuse the Interop/Marshal functions?
I hope somebody can help me with this.. or even at least give me ideas on how to solve it.

Thank you..
Mar 13 '08 #1
2 2109
deric
92
This might be insane but the solution came just out of the fluke! This is one of my many encountered bizarre happenings in .Net..

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3004360&SiteID=1&mode=1
Mar 14 '08 #2
What's the solution? The link is dead! :(
Nov 28 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
3
by: Eric Eggermann | last post by:
Hello, I need to implement a custom print dialog, and I'm trying to show a printers configuration box, like when you click Properties on the windows forms PrintDialog. I've gotten as far as...
0
by: heino | last post by:
Hello I am trying to understand how to use GetHdevmode/SetHdevmode to set public and private portions of DEVMODE structure. Is there any example in C# .Net framework that shows how to...
0
by: heino | last post by:
Hello I am trying to use GetHdevmode/SetHdevmode to set public and private portions of DEVMODE structure. Can any one post an example in C# .Net framework that shows how to change...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.