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