Re: Win AP question
From: Tom Shelton (tom_at_mtogden.com)
Date: 04/16/04
- Next message: Bamse: "How to enable audit of files/folders access from .NET code?"
- Previous message: William Ryan eMVP: "Re: Use C# to operate a mobile device"
- In reply to: Kevin: "Win AP question"
- Next in thread: Einar Høst: "Re: Win AP question"
- Reply: Einar Høst: "Re: Win AP question"
- Reply: Kevin: "Re: Win AP question"
- Reply: Kevin: "Re: Win AP question"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 16 Apr 2004 00:04:41 -0700
On 2004-04-16, Kevin <anonymous@discussions.microsoft.com> wrote:
> Hi all
>
> I have an interesting question.... I am working witha Win API this is the Function:
> Public Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (ByVal hPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, ByVal Level As Long, pJob As Byte, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
>
> Which I got from the API viewer that comes with VB 6. I have tried to convert it to the following:
>
> [DllImport("winspool.drv")]
> public static extern long EnumJobs(long hPrinter,long FirstJob,long NoJobs,long Level,ref JOB_INFO_1 jInfo,long cdBuf,long pcbNeeded,long pcReturned );
>
> however i think I may have gotten a few things wrong, which I am hoping someone will be able to correct me.
>
> 1. In the Declare statement there is a parameter that is : pJob As Byte and I've even seen it as : pJob As Any
> Now my question is that can I pass my struct(JOB_INFO_1) in there? even though the datatype it wants is byte, can I still pass the struct in there? How do i get my struct popultaed from this call, when it accepts a byte? do i need to do anything with how I created my strcut, this is my sample code of the strcut declaration :
> [StructLayout(LayoutKind.Sequential)]
> public struct JOB_INFO_1
> {
> public long JobId;
> public string pPrinterName;
> public string pMachineName;
> public string pUserName;
> public string pDocument;
> public string pDatatype;
> public string pStatus;
> public long Status;
> public long Priority;
> public long Position;
> public long TotalPages;
> public long PagesPrinted;
> public SYSTEMTIME Submitted;
> }
>
> [StructLayout(LayoutKind.Sequential)]
> public struct SYSTEMTIME
> {
> public int wYear;
> public int wMonth;
> public int wDayOfWeek;
> public int wDay;
> public int wHour;
> public int wMinute;
> public int wSecond;
> public int wMilliseconds;
> }
>
> 2. If ever I see another winAPI that accepts a datatype of "Any" what do I know what is "supposed to get there"?
>
> Thanks for any help
> Kevin
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct JOB_INFO_1
{
public int JobId;
public string pPrinterName;
public string pMachineName;
public string pUserName;
public string pDocument;
public string pDatatype;
public string pStatus;
public int Status;
public int Priority;
public int Position;
public int TotalPages;
public int PagesPrinted;
public SYSTEMTIME Submitted;
}
[DllImport("winspool.drv", CharSet=CharSet.Auto)]
public static extern int EnumJobs(
System.IntPtr hPrinter,
int FirstJob,
int NoJobs,
int Level,
ref JOB_INFO_1[] jInfo,
int cdBuf,
out int pcbNeeded,
out int pcReturned);
The above is untested, but would be my first cut based on the msdn
documentation. Some things you need to remember... In VB6, a Long is a
32-bit integer. In C#, a long is a 64-bit integer. That means, you
should translate VB6 into C# int's. VB6 Integer is 16-bit that's
equivalent to C#'s short.
You may want to read the documentation on P/Invoke.
-- Tom Shelton [MVP] Powered By Gentoo Linux 1.4 I've never been canoeing before, but I imagine there must be just a few simple heuristics you have to remember... Yes, don't fall out, and don't hit rocks.
- Next message: Bamse: "How to enable audit of files/folders access from .NET code?"
- Previous message: William Ryan eMVP: "Re: Use C# to operate a mobile device"
- In reply to: Kevin: "Win AP question"
- Next in thread: Einar Høst: "Re: Win AP question"
- Reply: Einar Høst: "Re: Win AP question"
- Reply: Kevin: "Re: Win AP question"
- Reply: Kevin: "Re: Win AP question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|