Re: Win AP question

From: Tom Shelton (tom_at_mtogden.com)
Date: 04/16/04


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.


Relevant Pages

  • Re: GDI zoom
    ... You can do things on the same levels with dot net. ... create a pen object and use that to draw a line just like with the api. ... vb6 you set the drawcolor and use the line command. ... time is coming when we don't get to run an exe on the end user's machine. ...
    (microsoft.public.vb.general.discussion)
  • Re: How to get data from CMD line
    ... Kevin, since you don't have any API exposure, I cobbled together an example ... and parse in Excel. ... For example if my output below is in the CMD window I want to capture the ...
    (microsoft.public.excel.programming)
  • Re: To rotate screen under WinXP
    ... VB.NET (I don't see any big differents to call API from both). ... forum is for call Windows APIs from VB6. ... case for all newsgroups with ".vb." ... And these for more general .NET questions ...
    (microsoft.public.vb.winapi)
  • How can I distribute a compiled .NET assembly object?
    ... referenced as late bound and I pre-install objects like SQL Server and IE ... But I did use the VB6 upgrade. ... Is is a wrong assumption to think that a compiled .NET program works on any ... Additionally I use a bunch of API calls: ...
    (microsoft.public.dotnet.academic)
  • Re: One thing I noticed
    ... impossible to do your sprites without autoredraw and I conclusively proved ... in .net where it requires api in vb6. ... just that dot net is more powerful because it does it ...
    (microsoft.public.vb.general.discussion)