J
Jostein Leira
I'm trying to install a print monitor with a deployment project in Visual
Studio 2008, but I have problems calling theWin32 AddMonitor method.
I have included the monitor dll file in the system folder group, and the
file is present in the c:\windows\system32 folder when the AddMonitor()
method is called.
When I run the installation (msi-file), AddMonitor() always return 0. I get
the following error messages from GetLastWin32Error() dependent on what I
pass as pEnvironment and OS;
mi2.pEnvironment = "Windows NT x86"
XP:"The system could not find the environment option that was entered"
W2k3: "The system cannot find the file specified"
mi2.pEnvironment = "Windows 4.0"
w2k3 & XP: "The environment specified is invalid"
mi2.pEnvironment = null
XP: "The system cannot find message text for message number 0x%1 in the
message file for %2"
w2k3: "The system cannot find the file specified"
I suspect that there is something wrong with my PInvoke signatures due to
the error messages above, but I'm open to any suggestions.
Most of Installer1.cs:
========================
[RunInstaller(true)]
public partial class Installer1 : Installer
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MONITOR_INFO_2
{
public string pName;
public string pEnvironment;
public string pDLLName;
}
[DllImport("winspool.drv", SetLastError = true, CharSet =
CharSet.Auto)]
private static extern Int32 AddMonitor(String pName, UInt32 Level,
ref MONITOR_INFO_2 pMonitors);
public Installer1()
{
InitializeComponent();
}
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
MONITOR_INFO_2 mi2 = new MONITOR_INFO_2();
StringBuilder buffer = new StringBuilder();
mi2.pName = "ControlPrint";
//mi2.pEnvironment = "Windows NT x86";// Orig envi, Error
XP:"The system could not find the environment option that was entered".
W2k3: "The system cannot find the file specified"
//mi2.pEnvironment = "Windows 4.0"; // Error w2k3 & XP: "The
environment specified is invalid",
mi2.pEnvironment = null; // Error XP: "The system
cannot find message text for message number 0x%1 in the message file for
%2". w2k3: "The system cannot find the file specified"
mi2.pDLLName = "wlpmon.dll";
try
{
if (AddMonitor(null, 2, ref mi2) == 0)
{
string errorMessage = new
Win32Exception(Marshal.GetLastWin32Error()).Message;
MessageBox.Show(String.Format("Adding monitor returned
false. Got Error:{0}", errorMessage), "Install point", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
else
MessageBox.Show("Commiting ControlPrint
installation\n\nMonitor added successfully.", "Install point",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception e)
{
MessageBox.Show(String.Format("Got excepiton:\n\n{0}",
e.ToString()), "Install point", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
========================
Best regards
Jostein Leira
Innoventure Net Solutions AS
Studio 2008, but I have problems calling theWin32 AddMonitor method.
I have included the monitor dll file in the system folder group, and the
file is present in the c:\windows\system32 folder when the AddMonitor()
method is called.
When I run the installation (msi-file), AddMonitor() always return 0. I get
the following error messages from GetLastWin32Error() dependent on what I
pass as pEnvironment and OS;
mi2.pEnvironment = "Windows NT x86"
XP:"The system could not find the environment option that was entered"
W2k3: "The system cannot find the file specified"
mi2.pEnvironment = "Windows 4.0"
w2k3 & XP: "The environment specified is invalid"
mi2.pEnvironment = null
XP: "The system cannot find message text for message number 0x%1 in the
message file for %2"
w2k3: "The system cannot find the file specified"
I suspect that there is something wrong with my PInvoke signatures due to
the error messages above, but I'm open to any suggestions.
Most of Installer1.cs:
========================
[RunInstaller(true)]
public partial class Installer1 : Installer
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MONITOR_INFO_2
{
public string pName;
public string pEnvironment;
public string pDLLName;
}
[DllImport("winspool.drv", SetLastError = true, CharSet =
CharSet.Auto)]
private static extern Int32 AddMonitor(String pName, UInt32 Level,
ref MONITOR_INFO_2 pMonitors);
public Installer1()
{
InitializeComponent();
}
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
MONITOR_INFO_2 mi2 = new MONITOR_INFO_2();
StringBuilder buffer = new StringBuilder();
mi2.pName = "ControlPrint";
//mi2.pEnvironment = "Windows NT x86";// Orig envi, Error
XP:"The system could not find the environment option that was entered".
W2k3: "The system cannot find the file specified"
//mi2.pEnvironment = "Windows 4.0"; // Error w2k3 & XP: "The
environment specified is invalid",
mi2.pEnvironment = null; // Error XP: "The system
cannot find message text for message number 0x%1 in the message file for
%2". w2k3: "The system cannot find the file specified"
mi2.pDLLName = "wlpmon.dll";
try
{
if (AddMonitor(null, 2, ref mi2) == 0)
{
string errorMessage = new
Win32Exception(Marshal.GetLastWin32Error()).Message;
MessageBox.Show(String.Format("Adding monitor returned
false. Got Error:{0}", errorMessage), "Install point", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
else
MessageBox.Show("Commiting ControlPrint
installation\n\nMonitor added successfully.", "Install point",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception e)
{
MessageBox.Show(String.Format("Got excepiton:\n\n{0}",
e.ToString()), "Install point", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
========================
Best regards
Jostein Leira
Innoventure Net Solutions AS