GetDesktopName

Just starting out? Need help? Post your questions and find answers here.
PWS32
User
User
Posts: 85
Joined: Sat May 10, 2003 1:02 pm
Location: Germany

GetDesktopName

Post 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 
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
PWS32
User
User
Posts: 85
Joined: Sat May 10, 2003 1:02 pm
Location: Germany

Post by PWS32 »

Hi srod and ts-soft, many thanks! this works fine for me
Post Reply