473,414 Members | 1,876 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,414 software developers and data experts.

Direct printing not working

Hi ALL
Please check the code below. OpenPrinter method returns Access is Denied error. Serial Printer is connected to the the IP address with name given at COM1
public enum ACCESS_MAS

PRINTER_ACCESS_ADMINISTER = 4
PRINTER_ACCESS_USE = 8
PRINTER_ALL_ACCESS = 98305

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)
public struct PRINTER_DEFAULTS

public string strDataType
public IntPtr ptrDevMode;
public ACCESS_MASK eDesiredAccess
[DllImport("winspool.drv", EntryPoint="OpenPrinterA", SetLastError=true, CharSet=CharSet.Auto, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)
public static extern long OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string strPrinterName, out IntPtr phPrinter, ref PRINTER_DEFAULTS pdDefaults)

public void TestPrint(string strData

IntPtr ptrPrinter;
PRINTER_DEFAULTS pdDefaults = new PRINTER_DEFAULTS();
pdDefaults.eDesiredAccess = ACCESS_MASK.PRINTER_ACCESS_ADMINISTER;

long lReturn = OpenPrinter("\\\\111.11.11.11\\Code 39", out ptrPrinter, ref pdDefaults
if(lReturn == 0 || ptrPrinter == IntPtr.Zero
{
int intError = Marshal.GetLastWin32Error()
Marshal.ThrowExceptionForHR(unchecked((int)0x80070 000 | Marshal.GetLastWin32Error()))
Note: Also can anybody tell me the link to get the exact declaratons of these APIs
Please help. Thanx in advance

Nov 16 '05 #1
1 4528
Please check the code below. OpenPrinter method returns Access is Denied error.
Do you have administer access to the printer?

[DllImport("winspool.drv", EntryPoint="OpenPrinterA", SetLastError=true, CharSet=CharSet.Auto, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
public static extern long OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string strPrinterName, out IntPtr phPrinter, ref PRINTER_DEFAULTS pdDefaults);
The return type here should be a bool, not long. And I wouldn't
recommend mixing CharSet.Auto with explciitly specifying the ANSI
version of the function as the entrypoint.

Note: Also can anybody tell me the link to get the exact declaratons of these APIs.


http://pinvoke.net is a good place to start looking. I'd declare it
like

[DllImport("winspool.drv", SetLastError=true, CharSet=CharSet.Auto)]
public static extern bool OpenPrinter(string strPrinterName, out
IntPtr phPrinter, ref PRINTER_DEFAULTS pdDefaults);

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Amit | last post by:
I have created formatted-PDF in Buffer. This PDF document have many images, lines, texts with underline-bold-italic. I put this buffer PDF contents to a variable. When I try to send the variable...
7
by: Kamilche | last post by:
I'm pretty desperate to get color syntax printing. I just tried out the evaluation version of 'Komodo', which several people in here suggested, and its print features are terrible. The text is...
9
by: Jody Gelowitz | last post by:
I am trying to find the definition of "Safe Printing" and cannot find out exactly what this entitles. The reason is that I am trying to print contents from a single textbox to no avail using the...
2
by: gerb | last post by:
Hello, I realise this is not a pure Javascript question, and that VBscript is probably involved at some point, though not as much as I fear. If you opened this item looking for a pute Javascript...
0
by: trint | last post by:
I need to know the best way to have my c#.net programs (Which I develop) to directly send files to a dedicated laserjet 4350, removing margins, scaling 100% and multi-tray control. Is there an...
0
by: ALMA_J_III | last post by:
Hi all! Customer will use HP LaserJet 4200TN printer for printing of invoices. 3 different versions of invoice on different color of paper should be to print. HP LaserJet 4200TN have 3 paper...
0
by: Clas | last post by:
Hello! I have written a javascript which posts back a page with __doPostBack if a user presses the escape-button on the keyboard. Then in Page_Load I´m doing a response.redirect to another page....
3
by: RajeshNamal | last post by:
Developing asp.net/C# web site, When I testing in my PC Crystal report Direct printing .but when i was Host in my web server it doesn't work. when i preview in crystal report viewer and Print...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.