Jump to content

Recommended Posts

Posted

Hi mate. I've been playing with ObjCreateInterface. And I can get some CLSID from IID. (I don't understand how to get it) I look into msdn and find nothing. for example I see this interface http://msdn.microsoft.com/en-us/library/windows/desktop/ms687223(v=vs.85).aspx#methods look at the end and see 

IID

IID_IPersistFile is defined as 0000010b-0000-0000-C000-000000000046

But I can't find the CLSID.

The simple question is:  ¿how can I get the CLSID from IID?

Saludos

  • Solution
Posted (edited)

The simple answer is: You don't get a CLSID from a IID.

A CLSID is a GUID identifying a COM class.

An IID is a GUID identifying a COM interface.

A COM class (or object) typically implements several COM interfaces. When using a COM class you must both specify an identifier for the COM class, and an identifier for the actual COM interface.

The most common way to create a COM interface, is to use QueryInterface to get a pointer for the interface object, and then create the interface with ObjCreateInterface.

Here's a random example:

$oIShellView.QueryInterface( $tRIID_IFolderView, $pIFolderView )
$oIFolderView = ObjCreateInterface( $pIFolderView, $sIID_IFolderView, $dtag_IFolderView )

I think IPersistFile is mostly used in connection with other interfaces, and it would probably be created with QueryInterface.

Edited by LarsJ
Posted (edited)

Thank you for your answer :)

I did not got how to implemente/create IPersistFile.

saludos

Edit: I got it. I did not read well.

saludos

Edited by Danyfirex
Posted

This is an example with the Shell Link object:

 

#include <WinAPI.au3>

Global Const $CLSID_ShellLink = "{00021401-0000-0000-C000-000000000046}"
Global Const $sIID_IShellLinkW = "{000214F9-0000-0000-C000-000000000046}"
Global Const $dtag_IShellLinkW = _
  "GetPath hresult();" & _
  "GetIDList hresult();" & _
  "SetIDList hresult();" & _
  "GetDescription hresult();" & _
  "SetDescription hresult();" & _
  "GetWorkingDirectory hresult();" & _
  "SetWorkingDirectory hresult();" & _
  "GetArguments hresult();" & _
  "SetArguments hresult();" & _
  "GetHotkey hresult();" & _
  "SetHotkey hresult();" & _
  "GetShowCmd hresult();" & _
  "SetShowCmd hresult();" & _
  "GetIconLocation hresult();" & _
  "SetIconLocation hresult();" & _
  "SetRelativePath hresult();" & _
  "Resolve hresult();" & _
  "SetPath hresult();"

Global Const $dtag_IPersist = _
  "GetClassID hresult();"

Global Const $sIID_IPersistFile = "{0000010b-0000-0000-C000-000000000046}"
Global Const $tRIID_IPersistFile = _WinAPI_GUIDFromString( $sIID_IPersistFile )
Global Const $dtag_IPersistFile = $dtag_IPersist & _ ; Inherits from IPersist
  "IsDirty hresult();" & _
  "Load hresult();" & _
  "Save hresult();" & _
  "SaveCompleted hresult();" & _
  "GetCurFile hresult();"
 
Opt( "MustDeclareVars", 1 )

MainFunc()


Func MainFunc()
  Local $oIShellLinkW = ObjCreateInterface( $CLSID_ShellLink , $sIID_IShellLinkW, $dtag_IShellLinkW )
  If Not IsObj( $oIShellLinkW ) Then Return ConsoleWrite( "$oIShellLinkW ERR" & @CRLF )
  ConsoleWrite( "$oIShellLinkW OK" & @CRLF )

  Local $pIPersistFile, $oIPersistFile
  $oIShellLinkW.QueryInterface( $tRIID_IPersistFile, $pIPersistFile )
  $oIPersistFile = ObjCreateInterface( $pIPersistFile, $sIID_IPersistFile, $dtag_IPersistFile )
  If Not IsObj( $oIPersistFile ) Then Return ConsoleWrite( "$oIPersistFile ERR" & @CRLF )
  ConsoleWrite( "$oIPersistFile OK" & @CRLF )
EndFunc

As you can see, the interface description strings are incomplete.

Posted

yes I see. I made mine one already (I should change some parameters I made it for testing.)

local $stagIShellLink="getpath hresult(long;long;long;long); " & _
  "getidlist hresult(long); " & _
  "setidlist hresult(long); " & _
  "getdescription hresult(long;long); " & _
  "setdescription hresult(wstr); " & _
  "getworkingdirectory hresult(long;long); " & _
  "setworkingdirectory hresult(long); " & _
  "getarguments hresult(long;long); " & _
  "setarguments hresult(ptr); " & _
  "gethotkey hresult(long); " & _
  "sethotkey hresult(word); " & _
  "getshowcmd hresult(long); " & _
  "setshowcmd hresult(int); " & _
  "geticonlocation hresult(long;long;long); " & _
  "seticonlocation hresult(wstr;int); " & _
  "setrelativepath hresult(long;long); " & _
  "resolve hresult(long;long); " & _
  "setpath hresult(wstr)"


Local $stagIPersistFile="GetClassID hresult(long); IsDirty hresult(); Load hresult(long;long); Save hresult(wstr;bool); SaveCompleted hresult(long); GetCurFile hresult(long)"

You really Helped me a lot. 

thank you very much  LarsJ

saludos

Posted

You actually don't need to call QueryInterface by yourself because ObjCreateInterface will do that for you by definition. So, just call ObjCreateInterface for $sIID_IPersistFile on ShellLink object.

To furher reduce the code, it should be obvious after that being said, that you can simply call ObjCreateInterface with $CLSID_ShellLink as CLSID, $sIID_IPersistFile as IID and $tagIPersistFile interface description to get (wanted) IPersistFile object.

♡♡♡

.

eMyvnE

Posted

You are right. This is much, much better:

Global Const $CLSID_ShellLink = "{00021401-0000-0000-C000-000000000046}"

Global Const $dtag_IPersist = _
  "GetClassID hresult();"

Global Const $sIID_IPersistFile = "{0000010b-0000-0000-C000-000000000046}"
Global Const $dtag_IPersistFile = $dtag_IPersist & _ ; Inherits from IPersist
  "IsDirty hresult();" & _
  "Load hresult();" & _
  "Save hresult();" & _
  "SaveCompleted hresult();" & _
  "GetCurFile hresult();"
 
Opt( "MustDeclareVars", 1 )

MainFunc()


Func MainFunc()
  Local $oIPersistFile = ObjCreateInterface( $CLSID_ShellLink, $sIID_IPersistFile, $dtag_IPersistFile )
  If Not IsObj( $oIPersistFile ) Then Return ConsoleWrite( "$oIPersistFile ERR" & @CRLF )
  ConsoleWrite( "$oIPersistFile OK" & @CRLF )
EndFunc
Posted

Very interesting topic.
Thanks to all participating in them

Cheers
mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...