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!
// Component structures for IActiveDeskTop
// Declare ActiveDesktop as a COM coclass
/// The main entry point for the application.
static void Main(string args)
ShellTypeLib.ActiveDesktop MyDesktop = new ShellTypeLib.ActiveDesktop();
ShellTypeLib.IActiveDesktop IDesk = (ShellTypeLib.IActiveDesktop) MyDesktop;
I have randomly taken one method GetDesktopItemCount that wasn't working with your code, and got it to work thanks to slight modifications :
- declare this method as :
uint GetDesktopItemCount(outint lpiCount);
- use it :
int nbdesktops = 0;
uint hresult = IDesk.GetDesktopItemCount(out nbdesktops);
In other words, - IActiveDesktop is not a dispatch interface, so you must consume the HRESULT value in return. - out values are marshalled with the out attribute.
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
With respect, that doesn't appear to be working either! I declared the GetDesktopItemCount as you did and then called in in my main program but I noticed that if I set nbdesktops to say 10 then after the function it is still 10! Also the HRESULT returned is non-zero even though no exception is thrown (it returns 0x129ADC which I don't know how to look up). Also what happened to the unit dwReserved parameter?
I declared the GetWallpaper function as:
uint SetWallpaper(string pwszWallpaper, uint dwReserved);
and it now seems to not throw an exception and even returns 0, but doesn't seem to actually do anything . I suspect that nothing will happen until I call the ApplyChanges method but that one still isn't working
Apologies for reposting the question. I posted it first in the .NET forum. I am desperate to get an answer prompting me to post here again.
I created a .NET web service that was to be consumed by a .NET web application.
Now I have a problem. I made a session variable in the Web Service and stored the instance of the Web Service in a session variable in the Web application.
I have two problems
1. The session variable in the Web service is lost in subsequent calls.
2. The WebService object in the Web app session is NULL in every submit from the browser.
Have anyone implemented something like this? Is this the correct way to implement a state-ful Web Service?
The web application starts a new session every time a web method on the WebService is called, even though I have created an instance of the Web Service in the Session_Start and kept it in a Session Variable.
Thomas George wrote: The web application starts a new session every time a web method on the WebService is called, even though I have created an instance of the Web Service in the Session_Start and kept it in a Session Variable.
SOmething sounds funny. Remember any session variables will only be there for the duration of the session. Maybe the session gets reset somewhere . Try adding breakpoints at session start/end events and see what happens....
When I was looking at it, it looked very helpful indeed, much better than the "few" examples on MSDN.
Thomas George wrote: Nice talking to you though. Got me thinking on a lot of things. I work here alone and I need someone to talk to about tech stuff once in a while .
Thanx again I work from home, but prefer to work alone, with some online help. Unfortunately my free GPRS connection comes to an end this month, so daytime will be a bit lonely untill ADSL becomes available in my area (local peak phone calls are probably the highest in the world (i dont even want to mention the cost per MB for GPRS once this free trial ends )).
The code in the previous post is for the web application. Web service objects created in an app by default is sessionless ie, it does not store the cookies. We just create a cookie container and ,wow, it is like invoking from a browser...
When a web application becomes the client for a webservice, that has state, the web application should identify the session in every request to the web service. Normally, this does not happen because the Web application does not store cookies. But, the Web service proxy object inside the web application can store the cookie, if one is created by the user.
The web service by default does not manage states - because it is a performance overhead. So, we have to explicitly enable session support for each web method that needs it, so that the session is loaded for the particular web method call (an extra load which we ask the ASP.NET framework to do by the EnableSession=true directive).