Bug in ReadShellLink? CompilerError

Just starting out? Need help? Post your questions and find answers here.
SteffenSperling
User
User
Posts: 12
Joined: Tue Mar 27, 2018 6:16 pm

Bug in ReadShellLink? CompilerError

Post by SteffenSperling »

Hi ALL,

I tryed to run codeexamples in different Topic s about readShellLink but allways there is a Compiler Error: 'wrong ParameterType: string expected'
But in the Microsoft description is a Pointer to a String:

HRESULT Load(
[in] LPCOLESTR pszFileName, <====================
[in] DWORD dwMode
);

If I give a String to the Parameter no results cames back.

Does somebody has any idea whats wrong or what can I do?
Perhaps I can declare my own structure?

The Code:

Code: Select all

Procedure.s ShortcutTarget(ShortcutFile$)
  Result$ = ""
  
  CoInitialize_(0)
  If CoCreateInstance_(?CLSID_ShellLink, 0, 1,?IID_IShellLink, @ShellLink.IShellLinkA) = #S_OK
    
    If ShellLink\QueryInterface(?IID_IPersistFile, @LinkFile.IPersistFile) = #S_OK
    
      *buffer = AllocateMemory(1000)
      If *buffer
      
        MultiByteToWideChar_(#CP_ACP, 0, @ShortcutFile$, -1, *buffer, 1000) 
        
        If LinkFile\Load(*buffer, 0) = #S_OK ; [color=#FF4000]<-------------- this Line CompilerError
[/color]        
          If ShellLink\Resolve(0, 1) = #S_OK
          
            RtlZeroMemory_(*buffer, 1000)
            ShellLink\GetPath(*buffer, 1000, 0, 0)
            Result$ = PeekS(*buffer)              
          
          EndIf
        
        EndIf
      
        FreeMemory(*buffer)
      EndIf
    
      LinkFile\Release()
    EndIf

    ShellLink\Release()  
  EndIf
  
  CoUninitialize_()
  
  ProcedureReturn Result$

  DataSection
    CLSID_ShellLink:
      ; 00021401-0000-0000-C000-000000000046
      Data.l $00021401
      Data.w $0000,$0000      
      Data.b $C0,$00,$00,$00,$00,$00,$00,$46
      
    IID_IShellLink:
      ; DEFINE_SHLGUID(IID_IShellLinkA,         0x000214EEL, 0, 0);
      ; C000-000000000046
      Data.l $000214EE
      Data.w $0000,$0000
      Data.b $C0,$00,$00,$00,$00,$00,$00,$46
      
    IID_IPersistFile:
      ; 0000010b-0000-0000-C000-000000000046
      Data.l $0000010b
      Data.w $0000,$0000
      Data.b $C0,$00,$00,$00,$00,$00,$00,$46
  EndDataSection
EndProcedure


ShortcutFile$ = 'BenMitBrille1.jpg.lnk'
Debug ShortcutTarget(ShortcutFile$)
; IDE Options = PureBasic 5.62 (Windows - x64)
; CursorPosition = 13
; FirstLine = 9
; Folding = -
; EnableThread
; EnableXP
; EnableAdmin
; EnableOnError
; HideErrorLog
; EnableCompileCount = 0
; EnableBuildCount = 0
Steffen
infratec
Always Here
Always Here
Posts: 6866
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Bug in ReadShellLink? CompilerError

Post by infratec »

From Sicro:

Code: Select all

EnableExplicit

Procedure.s ShortcutTarget(ShellLinkFilePath.s)
  
  ; Sicro - German forum : http://www.purebasic.fr/german/viewtopic.php?f=6&t=23674
  
  Protected RetVal.s = Space(#MAX_PATH + 1)
  Protected LinkFile.IPersistFile
  
  CompilerSelect #PB_Compiler_Unicode
    CompilerCase #True:  Protected ShellLink.IShellLinkW
    CompilerCase #False: Protected ShellLink.IShellLinkA
  CompilerEndSelect
  
  CoInitialize_(0)
  
  If CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLink, @ShellLink) = #S_OK
    If ShellLink\QueryInterface(?IID_IPersistFile, @LinkFile) = #S_OK
      If LinkFile\Load(ShellLinkFilePath, 0) = #S_OK
        If ShellLink\Resolve(0, 1) = #S_OK
          CompilerSelect #PB_Compiler_Unicode
            CompilerCase #True:  ShellLink\GetPath(@RetVal, #MAX_PATH, 0, 0)
            CompilerCase #False: ShellLink\GetPath(RetVal, #MAX_PATH, 0, 0)
          CompilerEndSelect
        EndIf
      EndIf
      LinkFile\Release()
    EndIf
    ShellLink\Release()
  EndIf
  
  CoUninitialize_()
  
  ProcedureReturn RetVal
  
  DataSection
    
    CLSID_ShellLink:
    ; 00021401-0000-0000-C000-000000000046
    Data.l $00021401
    Data.w $0000,$0000
    Data.b $C0,$00,$00,$00,$00,$00,$00,$46
    
    IID_IShellLink:
    CompilerIf #PB_Compiler_Unicode ; IID_IShellLinkW : 000214F9-0000-0000-C000000000000046
      Data.l $000214F9
    CompilerElse                    ; IID_IShellLinkA : 000214EE-0000-0000-C000000000000046
      Data.l $000214EE
    CompilerEndIf
    Data.w $0000,$0000
    Data.b $C0,$00,$00,$00,$00,$00,$00,$46
    
    IID_IPersistFile:
    ; 0000010b-0000-0000-C000-000000000046
    Data.l $0000010b
    Data.w $0000,$0000
    Data.b $C0,$00,$00,$00,$00,$00,$00,$46
    
  EndDataSection
  
EndProcedure


Debug ShortcutTarget("C:\Users\Public\Desktop\PuTTY.lnk")
SteffenSperling
User
User
Posts: 12
Joined: Tue Mar 27, 2018 6:16 pm

Re: Bug in ReadShellLink? CompilerError

Post by SteffenSperling »

... cool Thank You :)
Post Reply