B
Brad M
Hi there,
I am trying to retrieve a list of installed printer port monitors, this
was relatively easy in c++, but I can't seem to figure out the API call
in c#.
From MSDN the API call is...
BOOL EnumMonitors(
LPTSTR pName, // [in] server name
DWORD Level, // [in] information level
LPBYTE pMonitors, // [out] monitor information buffer
DWORD cbBuf, // [in] size of monitor information buffer
LPDWORD pcbNeeded, // [out] bytes received or required
LPDWORD pcReturned // [out] number of monitors received
);
So I have translated this into c#(probably incorrectly) as...
[DllImport("winspool.drv", CharSet=CharSet.Auto,SetLastError=true)]
private static extern bool EnumMonitors(string pName, uint Level,
[Out] out byte[] pMonitors,uint cbBuf,
[Out] out uint cbNeeded,
[Out] out uint cbReturned);
I could be way off here, but I have been successfull at getting most of
the other printer API calls working this way.
Then try and call it...
byte[] buff = new byte[4098];
uint b,n,r;
b=4098;
n=0;
r=0;
if (!EnumMonitors(null,1,out buff,b,out n,out r))
{
System.ComponentModel.Win32Exception error = new
System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
Console.WriteLine(error.Message);
}
else
{
Console.WriteLine("Success");
}
This just seems to hang and not return...
I am not sure if I should use byte[] for pMonitors or create a new
struct for MONITOR_INFO_1.
Anyone out there like to point me in the right direction?
Regards,
Brad
I am trying to retrieve a list of installed printer port monitors, this
was relatively easy in c++, but I can't seem to figure out the API call
in c#.
From MSDN the API call is...
BOOL EnumMonitors(
LPTSTR pName, // [in] server name
DWORD Level, // [in] information level
LPBYTE pMonitors, // [out] monitor information buffer
DWORD cbBuf, // [in] size of monitor information buffer
LPDWORD pcbNeeded, // [out] bytes received or required
LPDWORD pcReturned // [out] number of monitors received
);
So I have translated this into c#(probably incorrectly) as...
[DllImport("winspool.drv", CharSet=CharSet.Auto,SetLastError=true)]
private static extern bool EnumMonitors(string pName, uint Level,
[Out] out byte[] pMonitors,uint cbBuf,
[Out] out uint cbNeeded,
[Out] out uint cbReturned);
I could be way off here, but I have been successfull at getting most of
the other printer API calls working this way.
Then try and call it...
byte[] buff = new byte[4098];
uint b,n,r;
b=4098;
n=0;
r=0;
if (!EnumMonitors(null,1,out buff,b,out n,out r))
{
System.ComponentModel.Win32Exception error = new
System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
Console.WriteLine(error.Message);
}
else
{
Console.WriteLine("Success");
}
This just seems to hang and not return...
I am not sure if I should use byte[] for pMonitors or create a new
struct for MONITOR_INFO_1.
Anyone out there like to point me in the right direction?
Regards,
Brad