Page 1 of 1

GetDesktopName

Posted: Wed Oct 11, 2006 8:55 pm
by PWS32
Hello, please help me to translate this VB Code to Purebasic

Code: Select all

Public Function GetDesktopName() As String
Dim hDesktop As Long
Dim lR As Long
Dim lSize As Long
Dim sBuff As String
Dim iPos As Long
   
   hDesktop = OpenInputDesktop(0, False, DESKTOP_READOBJECTS)
   If Not (hDesktop = 0) Then
      lSize = (Len(m_sDesktop) + 1) * 2
      ReDim bBuff(0 To lSize - 1) As Byte
      lR = GetUserObjectInformation(hDesktop, UOI_NAME, bBuff(0), lSize, lSize)
      sBuff = bBuff
      iPos = InStr(sBuff, vbNullChar)
      If (iPos > 1) Then
         sBuff = Left(sBuff, iPos - 1)
      End If
      GetDesktopName = sBuff
      CloseHandle hDesktop
   End If
End Function 

Posted: Wed Oct 11, 2006 9:17 pm
by srod
I think the following is essentially what you need. It won't run 'as is' because of the missing variable 'm_sDesktop' and you'll have to double check the buffer size etc.

Code: Select all

#UOI_NAME = $2

Procedure.s GetDesktopName()
  Protected hDesktop, lR, lSize, sBuff.s, iPos
  hDesktop = OpenInputDesktop_(0, #False, #DESKTOP_READOBJECTS) 
  If hDesktop
    lSize = (Len(m_sDesktop) + 1) * 2 
    sBuff=Space(lSize+1)
    lR = GetUserObjectInformation_(hDesktop, #UOI_NAME, @sBuff, lSize, @lSize) 
    CloseHandle_(hDesktop)  ; Should this be CloseDesktop_() ?
   EndIf 
  ProcedureReturn sBuff
EndProcedure

Posted: Wed Oct 11, 2006 9:22 pm
by ts-soft

Code: Select all

buffer.s = Space(255)
hDesktop = OpenInputDesktop_(0, #False, #DESKTOP_READOBJECTS)
If hDesktop
  GetUserObjectInformation_(hDesktop, 2, @buffer, 255, 0)
  CloseHandle_(hDesktop)
  Debug buffer
EndIf
not perfect, but it works

Posted: Wed Oct 11, 2006 9:45 pm
by PWS32
Hi srod and ts-soft, many thanks! this works fine for me