Sign in to follow this  
Followers 0
Danyfirex

Get CLSID from IID

9 posts in this topic

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


 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites



#2 ·  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
3 people like this

Share this post


Link to post
Share on other sites

#3 ·  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

 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

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.

1 person likes this

Share this post


Link to post
Share on other sites

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


 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

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.

2 people like this

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

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
1 person likes this

Share this post


Link to post
Share on other sites

Very interesting topic.
Thanks to all participating in them

Cheers
mLipok

1 person likes this

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0