I managed to convert the Shobjidl.h file to a .tlb file, which when viewed in Microsoft's OLE viewer gives me this
[
uuid(C2CF3110-460E-4FC1-B9D0-8A1C0C9CC4BD)
]
coclass DesktopWallpaper {
[default] interface IDesktopWallpaper;
};
and
[
odl,
uuid(B92B56A9-8B55-4E14-9A89-0199BBB6F93B)
]
interface IDesktopWallpaper : IUnknown {
HRESULT _stdcall SetWallpaper(
[in] LPWSTR monitorID,
[in] LPWSTR wallpaper);
HRESULT _stdcall GetWallpaper(
[in] LPWSTR monitorID,
[out] LPWSTR* wallpaper);
HRESULT _stdcall GetMonitorDevicePathAt(
[in] unsigned int monitorIndex,
[out] LPWSTR* monitorID);
HRESULT _stdcall GetMonitorDevicePathCount([out] unsigned int* count);
HRESULT _stdcall GetMonitorRECT(
[in] LPWSTR monitorID,
[out] tagRECT* displayRect);
HRESULT _stdcall SetBackgroundColor([in] unsigned long color);
HRESULT _stdcall GetBackgroundColor([out] unsigned long* color);
HRESULT _stdcall SetPosition([in] DESKTOP_WALLPAPER_POSITION position);
HRESULT _stdcall GetPosition([out] DESKTOP_WALLPAPER_POSITION* position);
HRESULT _stdcall SetSlideshow([in] IShellItemArray* items);
HRESULT _stdcall GetSlideshow([out] IShellItemArray** items);
HRESULT _stdcall SetSlideshowOptions(
[in] DESKTOP_SLIDESHOW_OPTIONS options,
[in] unsigned int slideshowTick);
HRESULT _stdcall GetSlideshowOptions(
[out] DESKTOP_SLIDESHOW_OPTIONS* options,
[out] unsigned int* slideshowTick);
HRESULT _stdcall AdvanceSlideshow(
[in] LPWSTR monitorID,
[in] DESKTOP_SLIDESHOW_DIRECTION direction);
HRESULT _stdcall GetStatus([out] DESKTOP_SLIDESHOW_STATE* state);
HRESULT _stdcall Enable([in] long Enable);
};
I have converted what I think the code should be and got this
[ComImport, Guid("C2CF3110-460E-4fc1-B9D0-8A1C0C9CC4BD")]
class IDesktopWallpaper
{
}
// Declare IMediaControl as a COM interface which
// derives from the IDispatch interface.
[Guid("B92B56A9-8B55-4E14-9A89-0199BBB6F93B"), //B92B56A9-8B55-4E14-9A89-0199BBB6F93B
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] //try InterfaceIsDual if needed
interface DesktopWallpaperInterface
{
// Note that the members of IUnknown and Interface are NOT
// listed here
//
void AdvanceSlideshow(
[In] string monitorID,
[In] DESKTOP_SLIDESHOW_DIRECTION direction);
void Enable(out bool enable); /*use "out" or get AccessViolationException */
void GetBackgroundColor([Out] COLORREF color);
void GetMonitorDevicePathAt([In] int monitorIndex, [Out] string monitorID); //might be IntPtr?
void GetMonitorDevicePathCount(out uint count);
void GetMonitorRECT([In] string monitorID, [Out] RECT displayRect);
void GetPosition([Out] DESKTOP_WALLPAPER_POSITION position);
void GetSlideshow([Out] object items);
/*void GetSlideshow([Out] IShellItemArray items); */
void GetSlideshowOptions([Out] DESKTOP_SLIDESHOW_OPTIONS options, [Out] uint slideshowTick);
void GetStatus([Out] DESKTOP_SLIDESHOW_STATE state);
void GetWallpaper([In] string monitorID, [Out] string wallpaper);
void SetBackgroundColor([In] COLORREF color);
void SetPosition([In] DESKTOP_WALLPAPER_POSITION position);
void SetSlideshow([In] object items);
/* void SetSlideshow([In] IShellItemArray items); */
void SetSlideshowOptions([In] DESKTOP_SLIDESHOW_OPTIONS options, [In] uint slideshowTick);
void SetWallpaper([In] string monitorID, [In] string wallpaper);
}
[StructLayout(LayoutKind.Sequential)]
struct RECT
{
public int left, top, right, bottom;
}
public enum SIGDN : uint
{
NORMALDISPLAY = 0,
PARENTRELATIVEPARSING = 0x80018001,
PARENTRELATIVEFORADDRESSBAR = 0x8001c001,
DESKTOPABSOLUTEPARSING = 0x80028000,
PARENTRELATIVEEDITING = 0x80031001,
DESKTOPABSOLUTEEDITING = 0x8004c000,
FILESYSPATH = 0x80058000,
URL = 0x80068000
}
[Flags]
public enum DESKTOP_SLIDESHOW_DIRECTION : int
{
DSD_FORWARD = 0,
DSD_BACKWARD = 1
}
[Flags]
public enum DESKTOP_WALLPAPER_POSITION : int
{
DWPOS_CENTER = 0,
DWPOS_TILE = 1,
DWPOS_STRETCH = 2,
DWPOS_FIT = 3,
DWPOS_FILL = 4,
DWPOS_SPAN = 5
}
[Flags]
public enum DESKTOP_SLIDESHOW_OPTIONS : int
{
DSO_SHUFFLEIMAGES = 0x1
}
[Flags]
public enum DESKTOP_SLIDESHOW_STATE : int
{
DSS_ENABLED = 0x1,
DSS_SLIDESHOW = 0x2,
DSS_DISABLED_BY_REMOTE_SESSION = 0x4
}
[StructLayout(LayoutKind.Sequential)]
struct COLORREF
{
public byte R;
public byte G;
public byte B;
}
Right now I'm interested in getting the following methods working:
Enable(..)
SetWallpaper(..)
GetMonitorDevicePathCount(..)
This is the code I am using to try and get this to work
IDesktopWallpaper dw = new IDesktopWallpaper(); DesktopWallpaperInterface wallpaper = (DesktopWallpaperInterface)dw; bool enable = true; wallpaper.Enable(out enable); string wallp = @"PATH_TO_IMAGE_FILE"; string empty = String.Empty; wallpaper.SetWallpaper(null, wallp); /*sets the wallpaper to a random colour */ uint monitorCount =0; wallpaper.GetMonitorDevicePathCount(out monitorCount); /*causes ArgumentException*/
GetMonitorDevicePathCount gives me an ArgumentException
But so does changing the interface to int, IntPtr, UintPointer and Uint32
If I change the line
wallpaper.SetWallpaper(null, wallp);
to
wallpaper.SetWallpaper(empty, wallp);
then the screen is not changed to a random colour, but the wallpaper is not changed
I am really struggling to get this to work, does anyone have any ideas on what could be going wrong?
Am am using Windows 8 x64 in Visual Studio 2010 compiling a .Net 3.5 target framework as a Windows Application
The current build settings are for Debug Any CPU
However I have tried using x86 and x64 both produce the same result.
It's got to the point where I'm going to take just about any advice you have for me now, I just want to get this to work.
If you want any more information please just ask
Thanks

New Topic/Question
Reply



MultiQuote






|