473,804 Members | 4,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Interop - EnumPrintProces sors

Could some kind soul illustrate how I can call the EnumPrintProces sors Win32
API from c# code?

BOOL EnumPrintProces sors(
LPTSTR pName, // print server name
LPTSTR pEnvironment, // environment name
DWORD Level, // information level
LPBYTE pPrintProcessor Info, // processor data buffer
DWORD cbBuf, // size of data buffer
LPDWORD pcbNeeded, // bytes received or required
LPDWORD pcReturned // number of processors
);I am having particular trouble with the pPrintProcessor Info parameter.

This is defined as an LPBYTE and will eventually end up with an array of
PRINTPROCESSOR_ INFO_1 structures within it.

I cant quite translate this concept into C#

Thanks for any assistance, I have been trawling round msdn and the net to
little avail.

--
KM
Nov 17 '05 #1
3 3200
Keith,

Assuming that the definition here is correct, this is how I would
translate it:

[DllImport("dll name", CharSet=CharSet .Auto)]
static extern bool EnumPrintProces sors(
string pName,
string pEnvironment,
[MarshalAs(Unman agedType.U4)]
int Level,
IntPtr pPrintProcessor Info,
[MarshalAs(Unman agedType.U4)]
int cbBuf,
[MarshalAs(Unman agedType.U4)]
ref int pcbNeeded,
[MarshalAs(Unman agedType.U4)]
ref int pcReturned);

The reason for the cbBuf parameter being declared as IntPtr is that the
P/Invoke layer can not marshal values back for c-style arrays (it will only
marshal back the first element). In order to make this work, you will have
to allocate unmanaged memory (through the static methods on the Marshal
class) and then pass that IntPtr through to the function. Upon return, you
can use the static PtrToStructure method on the Marshal class to get the
managed representation of the structure. Then, you have to release the
unmanaged memory.

You can also use unsafe code to do this, but it would be hard to
recommend how without seeing the structure of the PRINTPROCESSOR_ INFO_1
structure.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Keith M" <ke***********@ nospam.amsjv.co m> wrote in message
news:42******** @glkas0286.gree nlnk.net...
Could some kind soul illustrate how I can call the EnumPrintProces sors
Win32
API from c# code?

BOOL EnumPrintProces sors(
LPTSTR pName, // print server name
LPTSTR pEnvironment, // environment name
DWORD Level, // information level
LPBYTE pPrintProcessor Info, // processor data buffer
DWORD cbBuf, // size of data buffer
LPDWORD pcbNeeded, // bytes received or required
LPDWORD pcReturned // number of processors
);I am having particular trouble with the pPrintProcessor Info parameter.

This is defined as an LPBYTE and will eventually end up with an array of
PRINTPROCESSOR_ INFO_1 structures within it.

I cant quite translate this concept into C#

Thanks for any assistance, I have been trawling round msdn and the net to
little avail.

--
KM

Nov 17 '05 #2

"Keith M" <ke***********@ nospam.amsjv.co m> wrote in message
news:42******** @glkas0286.gree nlnk.net...
Could some kind soul illustrate how I can call the EnumPrintProces sors
Win32
API from c# code?

BOOL EnumPrintProces sors(
LPTSTR pName, // print server name
LPTSTR pEnvironment, // environment name
DWORD Level, // information level
LPBYTE pPrintProcessor Info, // processor data buffer
DWORD cbBuf, // size of data buffer
LPDWORD pcbNeeded, // bytes received or required
LPDWORD pcReturned // number of processors
);I am having particular trouble with the pPrintProcessor Info parameter.

This is defined as an LPBYTE and will eventually end up with an array of
PRINTPROCESSOR_ INFO_1 structures within it.

I cant quite translate this concept into C#

Thanks for any assistance, I have been trawling round msdn and the net to
little avail.

--
KM


Why using PInvoke when it's that easy to do using System.Manageme nt and WMI
classes.
Herewith a small sample...

using System.Manageme nt ;
....
GetPropPrinter( "somePrinterDev ice"); // UNC path or local printer name

static int GetPropPrinter( string printerDevice)
{
string path = "win32_printer. DeviceId='" + printerDevice + "'";
using (ManagementObje ct printer = new ManagementObjec t(path))
{
printer.Get();
PropertyDataCol lection printerProperti es = printer.Propert ies;
foreach (PropertyData printerProperty in printerProperti es ) {
if(printerPrope rty.Value !=null) // Show only non-null property values
Console.WriteLi ne("Property = {0}\t Value = {1}",
printerProperty .Name, printerProperty .Value);
}
}
}

Willy.
Nov 17 '05 #3
Thanks for that. the PtrToStructure call would seem to be appropriate.

Unfortunately I cant see how to use it with an array of structures,
allocated as an array of bytes, coming back in.

From the documentation:
"The buffer must be large enough to receive the array of structures and any
strings to which the structure members point. "

So if I got back an array with 2 structures represented within, how would I
get them into two PRINTPROCESSOR_ INFO_1
structures?

PRINTPROCESSOR_ INFO_1 by the way is defined thus:

typedef struct _PRINTPROCESSOR _INFO_1
{
LPTSTR pName;
}
Thanks
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:u6******** *****@TK2MSFTNG P15.phx.gbl...
Keith,

Assuming that the definition here is correct, this is how I would
translate it:

[DllImport("dll name", CharSet=CharSet .Auto)]
static extern bool EnumPrintProces sors(
string pName,
string pEnvironment,
[MarshalAs(Unman agedType.U4)]
int Level,
IntPtr pPrintProcessor Info,
[MarshalAs(Unman agedType.U4)]
int cbBuf,
[MarshalAs(Unman agedType.U4)]
ref int pcbNeeded,
[MarshalAs(Unman agedType.U4)]
ref int pcReturned);

The reason for the cbBuf parameter being declared as IntPtr is that the P/Invoke layer can not marshal values back for c-style arrays (it will only marshal back the first element). In order to make this work, you will have to allocate unmanaged memory (through the static methods on the Marshal
class) and then pass that IntPtr through to the function. Upon return, you can use the static PtrToStructure method on the Marshal class to get the
managed representation of the structure. Then, you have to release the
unmanaged memory.

You can also use unsafe code to do this, but it would be hard to
recommend how without seeing the structure of the PRINTPROCESSOR_ INFO_1
structure.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

Nov 17 '05 #4

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

Similar topics

0
2364
by: roy | last post by:
I try to call com written in VB 6.0. When I use VS.net Studio to do the debuging, some time it works fine, some time I got the following message: Server Error in '/GISOnlineReservation' Application. ----------------------------------------------------------- --------------------- Configuration Error Description: An error occurred during the processing of a
0
1570
by: roy | last post by:
I try to call com written in VB 6.0., some time it works fine, some time I got the following message: Server Error in '/GISOnlineReservation' Application. ----------------------------------------------------------- --------------------- Configuration Error Description: An error occurred during the processing of a configuration file required to service this request.
0
2294
by: keefah | last post by:
Hi, I'm writing a C# web app that uses Outlook to send email. I use a reference to the Microsoft Outlook 11.0 Object Library, but it's giving me problems. I tracked down some stuff on the Net about the global assembly cache (GAC) and primary interop assemblies (PIA) and so forth, and did all the recommendations, in terms of tweeking Office, installing the .NET Office stuff for framework 1.1, etc. I got it to the point where it compiles ok,...
0
2794
by: lacour | last post by:
I can't seem to figure out the difference between adding a COM dll reference in VS2003 and by using TLBIMP. I have a COM dll that references another COM dll, and I want the syntax of my interop-filenames to be interop.<NameOfCOMDLL>.dll I now make the first interop file tlbimp COM1.dll /out:interop.COM1.dll /namespace:COM1
8
3426
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be added. Converting the type library to a .Net assembly failed. A depended type library 'CDO' could not be converted to a .NET assembly. A dependent type library 'ADODB' could not be converted to a .NET assembly. Item has already been added." ...
7
10966
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed this screen below. Please help, thanks in advance... Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify...
2
7307
by: JC | last post by:
Anybody knows what problem has this code? I think, in the Garbage Collector? You know the Solution? The program in the test's case, whit 350 contacts, run OK before number 86. The error is a "Array index out of bounds". Microsoft.Office.Interop.Outlook._Application olApp = new Microsoft.Office.Interop.Outlook.ApplicationClass(); Microsoft.Office.Interop.Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
1
2872
by: allbelonging | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox and server (Exchange server mail box) to connect and then save the mailitems(from Inbox or any other folder) based on a filter to a*.msg file. I want to achieve this using only one Interop dll if this is possible. Tried so far:
0
2060
by: Tina | last post by:
I've gotten this before where it says there is a problem with Interop.MSDASC but I can't remember what causes this. This is a 1.1 app I'm trying to debug in vs2005. It was running yesterday just fine. Help! T Server Error in '/VT.Users' Application. -------------------------------------------------------------------------------- Configuration Error
0
10593
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9163
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7626
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3000
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.