Question Creating a new desktop

Anthraxx

New member
Joined
Aug 15, 2008
Messages
2
Programming Experience
3-5
Hi, I'm trying to get something done in vb.net which I've already done in vb6 (lost the code): creating a new desktop and switching to it. I have a C# code (written by somebody else, got it from http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=5277&lngWId=10) which works very well. I've tried to manually convert the code to vb.net, but everytime I run the app, I get an error of which I cannot find the source. Somehow I'm doing something wrong, but I can't tell what.

The C# code is:
VB.NET:
            static void CreateNewDesktop()
            {
                DesktopThreadID = GetThreadDesktop(GetCurrentThreadId());
                DesktopInputID = OpenInputDesktop(0, false, DESKTOP_SWITCHDESKTOP);
                DesktopHandle = CreateDesktop(DesktopName, "", 0, 0, GENERIC_ALL, 0);
                if (DesktopHandle != 0)
                {
                    SetThreadDesktop(DesktopHandle);
                    SwitchDesktop(DesktopHandle);
                    System.IO.File.WriteAllText(Application.StartupPath + "\\Desktop.Dif", DesktopInputID.ToString() + "|" + DesktopThreadID.ToString() + "|" + DesktopHandle.ToString());
                }
            }




I've manually converted this to the following vb.net code:

VB.NET:
    Public Function Create(ByVal Name As String, Optional ByVal AutoSwitch As Boolean = False) As Integer
        DesktopThreadID = GetThreadDesktop(GetCurrentThreadId)
        DesktopInputID = OpenInputDesktop(0, False, DESKTOP_SWITCHDESKTOP)
        DesktopHandle = CreateDesktop(Name, "", 0, 0, GENERIC_ALL, 0)
        If DesktopHandle <> 0 Then
            SetThreadDesktop(DesktopHandle)
            SwitchDesktop(DesktopHandle)
            Return 1
        End If
    End Function



Never mind the API calls, the're all in place ;)
The System.IO.File.WriteAllText line is not important to me...

Can somebody tell me what I'm doing wrong?
Thank you :D
 
A couple of things to check

VB.NET:
 ..GetThreadDesktop(GetCurrentThreadId[b]()[/b])

VB.NET:
CreateDesktop(Name, [b]Nothing[/b], 0, 0, GENERIC_ALL, 0)
 
Back
Top