I'm trying to add a DeskBand object to the system tray programmatically using this code:
[ComImport, Guid("6D67E846-5B9C-4db8-9CBC-DDE12F4254F1"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ITrayDeskband
{
[PreserveSig]
int ShowDeskBand([In, MarshalAs(UnmanagedType.Struct)] ref Guid clsid);
[PreserveSig]
int HideDeskBand([In, MarshalAs(UnmanagedType.Struct)] ref Guid clsid);
[PreserveSig]
int IsDeskBandShown([In, MarshalAs(UnmanagedType.Struct)] ref Guid clsid);
[PreserveSig]
int DeskBandRegistrationChanged();
}
private void ShowDeskBand()
{
ITrayDeskband obj = null;
Type trayDeskbandType = System.Type.GetTypeFromCLSID(new Guid("E6442437-6C68-4f52-94DD-2CFED267EFB9"));
try
{
Guid deskbandGuid = new Guid("FE0829F8-EDFA-46B6-87E0-636C8D953E33"); // My Deskband | TestToolbar
obj = (ITrayDeskband)Activator.CreateInstance(trayDeskbandType);
obj.DeskBandRegistrationChanged();
int hr = obj.ShowDeskBand(ref deskbandGuid);
if (hr != 0)
{
throw new Exception("Error while trying to show deskband: " + hr);
}
obj.DeskBandRegistrationChanged();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
if (obj != null && Marshal.IsComObject(obj))
Marshal.ReleaseComObject(obj);
}
}
Source: http://www.pinvoke.net/default.aspx/Interfaces/ITrayDeskband.html
My DeskBand object is created from the "BandObjectsLib" from this sample: http://www.codeproject.com/Articles/14141/Band-Objects-NET-2-0-Redux
It looks like this:
[Guid("FE0829F8-EDFA-46B6-87E0-636C8D953E33")]
[BandObject("TestToolbar", BandObjectStyle.Horizontal | BandObjectStyle.TaskbarToolBar, HelpText = "Testing this toolbar")]
public class TestToolbar : BandObject
{
public TestToolbar()
{
ProgressBar pb = new ProgressBar();
pb.Maximum = 100;
pb.Minimum = 0;
pb.Value = 50;
this.Controls.AddRange(new System.Windows.Forms.Control[] { pb });
}
}
However, when trying to add the DeskBand object all I get is my exception telling me the error code: -2147467259 This error code translates to a 0x80004005 and according to MSDN that is an E_FAIL: http://msdn.microsoft.com/en-us/library/windows/desktop/aa378137.aspx
I'm basicly stuck here since this is honestly not my area of expertise. I was hoping that there was someone who might be more experienced and could help me out? Thanks in advance!
You have to register your DLL (install your MSI or use regasm) in order for your code to work.