Sign in to follow this  
Followers 0
wslh

How to use DllCall with an OLESTR ?

10 posts in this topic

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

Share this post


Link to post
Share on other sites



No, you need to pass LPCOLESTR.

That's the same as "wstr".

Btw, you are calling it wrong.


♡♡♡

.

eMyvnE

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

No, you need to pass LPCOLESTR.

That's the same as "wstr".

Btw, you are calling it wrong.

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

Can you drop the line?

Thanks,

wslh

Share this post


Link to post
Share on other sites

Thanks water but I don't want to create an Outlook instance.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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...

Share this post


Link to post
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.


♡♡♡

.

eMyvnE

Share this post


Link to post
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

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