Click here to Skip to main content
15,885,278 members
Home / Discussions / C#
   

C#

 
GeneralRe: Beginner C# questions Pin
James T. Johnson19-Sep-02 0:06
James T. Johnson19-Sep-02 0:06 
GeneralRe: Beginner C# questions Pin
leppie19-Sep-02 0:31
leppie19-Sep-02 0:31 
GeneralDataGrid Pin
vikramlinux18-Sep-02 18:03
vikramlinux18-Sep-02 18:03 
GeneralHanging web request Pin
afronaut18-Sep-02 13:23
afronaut18-Sep-02 13:23 
GeneralRe: Hanging web request Pin
Paul Riley18-Sep-02 13:31
Paul Riley18-Sep-02 13:31 
GeneralRe: Hanging web request Pin
afronaut18-Sep-02 13:32
afronaut18-Sep-02 13:32 
GeneralRe: Hanging web request Pin
afronaut19-Sep-02 5:24
afronaut19-Sep-02 5:24 
GeneralManaged interface for IActiveDesktop Pin
Wjousts18-Sep-02 11:59
Wjousts18-Sep-02 11:59 
I've been trying to write a managed interface for IActiveDesktop so I can use it to change the desktop wallpaper from a C# program. My source as it is at the moment is shown below. When I try and use any of the methods in the IActiveDesktop interface I get exceptions being thrown, mostly System.NullReferenceException but sometimes System.ArgumentException. I suspect something is wrong with my managed interface, but I'm not sure what. I've played around with changing the marshalling, but haven't hit on the answer yet. Any help would be greatly appreciated. I know there are easier ways to change the wallpaper, but I'm determined to figure this thing out now!

Thanks

----------------------------
using System;
using System.Runtime.InteropServices;

namespace ShellTypeLib
{
// Component structures for IActiveDeskTop

[StructLayout(LayoutKind.Sequential)]
struct COMPONENT
{
uint dwSize;
uint dwID;
int iComponentType;
bool fChecked;
bool fDirty;
bool fNoScroll;
COMPPOS cpPos;
char[] wszFriendlyName;
char[] wszSource;
}

[StructLayout(LayoutKind.Sequential)]
struct COMPPOS
{
uint dwSize;
int iLeft;
int iTop;
uint dwWidth;
uint dwHeight;
int izIndex;
bool fCanResize;
bool fCanResizeX;
bool fCanResizeY;
int iPreferredLeftPercent;
int iPreferredTopPercent;
}

[StructLayout(LayoutKind.Sequential)]
struct COMPONENTSOPT
{
uint dwSize;
bool fEnableComponents;
bool fActiveDesktop;
}

[StructLayout(LayoutKind.Sequential)]
struct WALLPAPEROPT
{
uint dwSize;
uint dwStyle;
}


// Declare IActiveDesktop interface
[Guid("F490EB00-1240-11D1-9888-006097DEACF9")]
interface IActiveDesktop
{
void ApplyChanges(uint dwFlags);
void GetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string pwszWallpaper, uint cchWallpaper, uint dwReserved);
void SetWallpaper(string pwszWallpaper, uint dwReserved);
void GetWallpaperOptions(ref WALLPAPEROPT pwpo,uint dwReserved);
void SetWallpaperOptions(ref WALLPAPEROPT pwpo, uint dwReserved);
void GetPattern([MarshalAs(UnmanagedType.LPWStr)] string pwszPattern, uint cchPattern, uint dwReserved);
void SetPattern([MarshalAs(UnmanagedType.LPWStr)] string pwszPattern, uint dwReserved);
void GetDesktopItemOptions(ref COMPONENTSOPT pco, uint dwReserved);
void SetDesktopItemOptions(ref COMPONENTSOPT pcomp, uint dwReserved);
void AddDesktopItem(ref COMPONENT pcomp, uint dwReserved);
void AddDesktopItemWithUI(IntPtr hwnd, ref COMPONENT pcomp, uint dwReserved);
void ModifyDesktopItem(ref COMPONENT pcomp, uint dwFlags);
void RemoveDesktopItem(ref COMPONENT pcomp, uint dwReserved);
void GetDesktopItemCount(int lpiCount, uint dwReserved);
void GetDesktopItem(int nComponent, ref COMPONENT pcomp, uint dwReserved);
void GetDesktopItemByID(uint dwID, ref COMPONENT pcomp, uint dwReserved);
void GenerateDesktopItemHtml([MarshalAs(UnmanagedType.LPWStr)] string pwszFileName, ref COMPONENT pcomp, uint dwReserved);
void AddUrl(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszSource, ref COMPONENT pcomp, uint dwFlags);
void GetDesktopItemBySource([MarshalAs(UnmanagedType.LPWStr)] string pszSource, ref COMPONENT pcomp, uint dwReserved);
}

// Declare ActiveDesktop as a COM coclass
[ComImport, Guid("75048700-EF1F-11D0-9888-006097DEACF9")]
class ActiveDesktop
{

}
}

namespace Wallpaper_test
{
class Class1
{
///
/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{
ShellTypeLib.ActiveDesktop MyDesktop = new ShellTypeLib.ActiveDesktop();
ShellTypeLib.IActiveDesktop IDesk = (ShellTypeLib.IActiveDesktop) MyDesktop;

IDesk.SetWallpaper("Test.bmp",0);
IDesk.ApplyChanges(1);
}
}
}
GeneralRe: Managed interface for IActiveDesktop Pin
Stephane Rodriguez.18-Sep-02 20:44
Stephane Rodriguez.18-Sep-02 20:44 
GeneralRe: Managed interface for IActiveDesktop Pin
Wjousts19-Sep-02 15:50
Wjousts19-Sep-02 15:50 
GeneralRe: Managed interface for IActiveDesktop Pin
Okeno Palmer28-Dec-03 18:50
Okeno Palmer28-Dec-03 18:50 
QuestionRelease date of .NET 1.1? Pin
leppie18-Sep-02 4:50
leppie18-Sep-02 4:50 
GeneralWeb Service question (C#) Pin
User 988518-Sep-02 4:50
User 988518-Sep-02 4:50 
GeneralWeb Service question (C#) - addl info Pin
User 988518-Sep-02 4:55
User 988518-Sep-02 4:55 
GeneralRe: Web Service question (C#) Pin
leppie18-Sep-02 4:57
leppie18-Sep-02 4:57 
GeneralRe: Web Service question (C#) Pin
Ray Cassick18-Sep-02 5:20
Ray Cassick18-Sep-02 5:20 
GeneralRe: Web Service question (C#) Pin
leppie18-Sep-02 5:59
leppie18-Sep-02 5:59 
GeneralRe: Web Service question (C#) Pin
User 988518-Sep-02 5:28
User 988518-Sep-02 5:28 
GeneralRe: Web Service question (C#) Pin
leppie18-Sep-02 5:53
leppie18-Sep-02 5:53 
GeneralRe: Web Service question (C#) Pin
User 988518-Sep-02 6:39
User 988518-Sep-02 6:39 
GeneralRe: Web Service question (C#) Pin
leppie18-Sep-02 6:46
leppie18-Sep-02 6:46 
GeneralRe: Web Service question (C#) Pin
User 988518-Sep-02 6:54
User 988518-Sep-02 6:54 
GeneralRe: Web Service question (C#) Pin
leppie18-Sep-02 7:12
leppie18-Sep-02 7:12 
GeneralRe: Web Service question (C#) Pin
User 988518-Sep-02 6:56
User 988518-Sep-02 6:56 
GeneralRe: Web Service question (C#) Pin
leppie18-Sep-02 7:17
leppie18-Sep-02 7:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.