Keith,
Assuming that the definition here is correct, this is how I would
translate it:
[DllImport("dll name", CharSet=CharSet.Auto)]
static extern bool EnumPrintProcessors(
string pName,
string pEnvironment,
[MarshalAs(UnmanagedType.U4)]
int Level,
IntPtr pPrintProcessorInfo,
[MarshalAs(UnmanagedType.U4)]
int cbBuf,
[MarshalAs(UnmanagedType.U4)]
ref int pcbNeeded,
[MarshalAs(UnmanagedType.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.com
"Keith M" <ke***********@nospam.amsjv.com> wrote in message
news:42********@glkas0286.greenlnk.net...
Could some kind soul illustrate how I can call the EnumPrintProcessors
Win32
API from c# code?
BOOL EnumPrintProcessors(
LPTSTR pName, // print server name
LPTSTR pEnvironment, // environment name
DWORD Level, // information level
LPBYTE pPrintProcessorInfo, // 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 pPrintProcessorInfo 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