Jump to content

How to use DllCall with an OLESTR ?


wslh
 Share

Recommended Posts

Hi,

I want to check if Outlook is present, as part of the process I use:

$clsid = DllCall ("Ole32.dll","ULONG_PTR", "CLSIDFromProgID", "wstr", "Outlook.Application")

but I need to pass an OLESTR instead of an wstr, how can I accomplish that?

Also, how do I check if $clsid is null? I use IsPtr function to do that. Is this correct?

Thanks,

wslh

Link to comment
Share on other sites

The Outlook UDF uses ObjCreate to connect to Outlook. So you could write:

Local $oOutlook = ObjCreate("Outlook.Application")
If @error Or Not IsObj($oOutlook) Then MsgBox(0,"","Error opening Outlook")

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

But how I can do that? there is not LPCOLESTR in the help's parameter list.

Can you drop the line?

Thanks,

wslh

Func _WinAPI_CLSIDFromProgID($sProgID)
    Local $tGUID = DllStructCreate($tagGUID)
    Local $aCall = DllCall("ole32.dll", "long", "CLSIDFromProgID", "wstr", $sProgID, "ptr", DllStructGetPtr($tGUID))
    If @error Or $aCall[0] Then Return SetError(1, 0, 0)
    Return $tGUID
EndFunc

Just check if 0 is returned or not.

edit: actually don't check 0 (there is a bug in AutoIt with dllstruct type). Check it like this:

If IsDllStruct(_WinAPI_CLSIDFromProgID("Outlook.Application")) Then...
Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Using the information from MSDN and the AutoIT tool "h2au3" (it converts C-headers to Autoit) I get the following:

Func CLSIDFromProgID ($lpszProgID, $lpclsid)

    Local $aRes = DllCall ($ole32dll, "LONG", "CLSIDFromProgID", _
                                "PTR", $lpszProgID, _
                                "PTR", $lpclsid)
    Return $aRes[0]

EndFunc

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Sorry trancexx, It doesn't work for me.

$tagGUID must be created before the DLLStructCreate?

Thanks,

wslh

Func _WinAPI_CLSIDFromProgID($sProgID)
    Local $tGUID = DllStructCreate($tagGUID)
    Local $aCall = DllCall("ole32.dll", "long", "CLSIDFromProgID", "wstr", $sProgID, "ptr", DllStructGetPtr($tGUID))
    If @error Or $aCall[0] Then Return SetError(1, 0, 0)
    Return $tGUID
EndFunc

Just check if 0 is returned or not.

edit: actually don't check 0 (there is a bug in AutoIt with dllstruct type). Check it like this:

If IsDllStruct(_WinAPI_CLSIDFromProgID("Outlook.Application")) Then...

Link to comment
Share on other sites

Open freaking help file and type $tagGUID.

If for example you would #include <WinApi.au3> (as the name of the function suggest) there would be no issues.

Use imagination, not to say head.

Sorry trancexx, I know that it sounds lazy, but because I am an AutoIt newbie $tagGUID seemed like a local variable to me and I didn't realize it was a global definition.

Thank You,

wslh

Link to comment
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
 Share

  • Recently Browsing   0 members

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