Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

How to get a string from VT_BYREF|VT_BSTR variant with AHK_L


  • Please log in to reply
5 replies to this topic
elgin
  • Guests
  • Last active:
  • Joined: --
Hi,

I am trying to work with an event that passes it's values as VT_BYREF|VT_BSTR variants (type 0x4008) to AHK_L.

Is there any way to retrieve the actual string from this variant?

elgin
  • Guests
  • Last active:
  • Joined: --
bump.

Does anyone know?

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Do you have any sort of example?

elgin
  • Guests
  • Last active:
  • Joined: --
It's a bit hard to give a really useful example on that one...

It concerns the CommandRecognize event of the Dragon.DgnVCmd.1 COM control of Dragon Naturally Speaking Professional defined as follows:

Syntax:
Visual Basic
CommandRecognize( Command As String, ID As Long, Action As String, ListResults As DgnStrings )


C++

void CommandRecognize( BSTR * Command, long * ID, BSTR * Action, struct IDgnStrings * * ListResults );

The C++ version seems to be what I get as variants in AHK. The "Action" is what interests me most, maybe also the ByRef to the ListResults but I guess that would be resolved in a similar fashion.

Thanks a lot for taking a look.

Elgin
  • Members
  • 79 posts
  • Last active: Dec 18 2015 08:07 PM
  • Joined: 29 Jul 2011
Thanks to Lexikos' post here:
http://www.autohotke...pic.php?t=74970

I finally got this working and wanted to share how it's done for future reference.

This script creates the speech commands "one apple", " one banana", "no apple" and "no banana" in Dragon Naturally Speaking and displays a message box when one of the commands is spoken:

#Persistent
OnExit, CleanUp


DVC:= ComObjCreate("Dragon.DgnVCmd")
DVC.Register("", 1)

DMnu:= DVC.MenuCreate("SomeRuleName", "", 0, "", 1)
DMnu.hWndMenu:=0
DMnu.Active:=True

LStr:=COMObjCreate("Dragon.DgnStrings")
Lstr.Add("banana")
Lstr.Add("apple")
DMnu.ListSetStrings("fruit", Lstr)
ObjRelease(Lstr)
DMnu.Add(72, "one <fruit>","SomeCategory","SomeDescription","Action1",0)
DMnu.Add(73, "no <fruit>","SomeCategory","SomeDescription","Action2",0)
ComObjConnect(DVC, "On_")
Return

On_CommandRecognize(pcom,pID,pact,plist)
{
   commandptr := NumGet(ComObjValue(pcom),0,"Ptr")
   command := StrGet(commandptr)
   id := NumGet(ComObjValue(pID),0,"int")
   actptr := NumGet(ComObjValue(pact),0,"Ptr")
   act := StrGet(actptr)

   listp := NumGet(ComObjValue(plist),0,"Ptr")
   lp := ComObject(9,listp,1)
   listcnt := lp.Count
   if listcnt>0
   {
     listit := lp.Item(1)
   }
   else listit:=""

   MsgBox, Command: %command%`r`nID: %id%`r`nAction: %act%`r`nList item 1: %listit%`r`nwas recognized.
}


CleanUp:
DVC.UnRegister()
ObjRelease(DVC)
ExitApp


Wade Hatler
  • Members
  • 40 posts
  • Last active: Nov 06 2014 10:46 PM
  • Joined: 28 Sep 2004
Thanks for this. I've been all morning trying to figure this out, and this got me reasonably close.

It seems to require a minor change to work on my system. I'm guessing it's because this code was written to handle the default ANSI code page, and my system is defaulting everything Unicode. I'm not sure exactly why – it could be because I have a slightly different interface, or it could be because I'm running a 64-bit system.

At any rate, I had to make the following changes to get the by reference BSTR to work:
On_CommandRecognize(pcom,pID,pact,plist)
{
   commandptr := NumGet(ComObjValue(pcom),0,"Ptr")
   command := StrGet(commandptr, "UTF-16")
The key is the UTF-16 Encoding for StrGet.