Jump to content
Sign in to follow this  
frank10

AutoitObject: ObjCreate or WrapperCreate?

Recommended Posts

frank10

I'm at the beginning with AutoitObject with some DirectShow objects.

I haven't understood well when to use the WrapperCreate or the ObjCreate functions.

I saw from an example of trancexx that one time she used:

$oGraphBuilder = _AutoItObject_ObjCreate($sCLSID_FilterGraph, $sIID_IGraphBuilder, $dtagIGraphBuilder)

but in another obj she used the WrapperCreate:

$oVideoWindow = _AutoItObject_WrapperCreate($pVideoWindow, $dtagIVideoWindow)

So, if I have this DS C++ code to translate to autoit:

// Create the capture graph builder helper object
    hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL,
        CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,
        (void **)&pBuild );

What should I use?

More, where I find the value for IID_ICaptureGraphBuilder2?

At the moment I found only the CLSID ICaptureGraphBuilder, not the IID_ICaptureGraphBuilder2.

here I found some Info on ICaptureGraphBuilder2, so how to convert these methods to the $tagCaptureBuilder?

I made this:

const  $CLSCTX_INPROC_SERVER     = 0x1
    local $sCLSID_ICaptureGraphBuilder = '{BF87B6E0-8C27-11D0-B3F0-00AA003761C5}'
    local $tIID_ICaptureGraphBuilder = _AutoItObject_CLSIDFromString( $sCLSID_ICaptureGraphBuilder );
    local $pBuild = 0
    _AutoItObject_CoCreateInstance ($sCLSID_ICaptureGraphBuilder, 0,
        $CLSCTX_INPROC_SERVER,   --------------   ,
        pBuild );

; Define interface
local $tagCaptureBuilder = "QueryInterface hresult(ptr;ptr*);" & _
        "AddRef ulong();" & _
        "Release ulong();" & _
        "ControlStream hresult( ------------ );" & _          ; ????
        "SetFiltergraph hresult(  ptr  );"                       ; ????

Global $oCaptureBuilder2 = _AutoItObject_WrapperCreate($pBuild, $tagCaptureBuilder)  ;   or ObjCreate ???
Edited by frank10

Share this post


Link to post
Share on other sites
ProgAndy

If you already have the pointer, then use the wrapper. If you are using CoCreateInstance, replace it with ObjCreate. IID_ICaptureGraphBuilder2 and CLSID_ICaptureGraphBuilder2 can be found in your API header files. sometimes a google search with #define, GUID, or DEFINE_GUID can help, too :oops: It is the same with the vtable definition.

Btw, here are all definitions: http://www.koders.com/cpp/fid33F0A2A49B7370DA724199259330C38A93C1DE21.aspx#L5839

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
frank10

thank you for the explanation and link: very useful.

But I'm a bit confused, still.

In the help file of autoitObject, I see that CoCreateInstance is associated with a WrapperCreate. In fact it uses the pointer obtained with the CoCreateInstance.

So CoCreateInstance --> WrapperCreate

pointer with noCoCreate --> WrapperCreate

and finally,

no pointers but sCLSID and sIID --> ObjCreate

So I can create an object in three equivalent ways:

1:

local  $sCLSID_ICaptureGraphBuilder2 =   '{BF87B6E1-8C27-11D0-B3F0-00AA003761C5}'
    Local $sIID_ICaptureGraphBuilder2      =   '{93e5a4e0-2d50-11d2-abfa-00a0c9c6e38d}'
 
; Define interface
local $tagCaptureBuilder2 = "QueryInterface hresult(ptr;ptr*);" &      etc...

Global $oCaptureBuilder2 = _AutoItObject_ObjCreate($sCLSID_ICaptureGraphBuilder2 , $sIID_ICaptureGraphBuilder2 , $tagCaptureBuilder2)

2:

const  $CLSCTX_INPROC_SERVER     = 0x1
    local  $tCLSID_ICaptureGraphBuilder2 =   _AutoItObject_CLSIDFromString('{BF87B6E1-8C27-11D0-B3F0-00AA003761C5}')
    Local $tIID_ICaptureGraphBuilder2      =  _AutoItObject_CLSIDFromString('{93e5a4e0-2d50-11d2-abfa-00a0c9c6e38d}')

    local $pBuild = 0
    _AutoItObject_CoCreateInstance (DllStructGetPtr($tCLSID_ICaptureGraphBuilder2), 0,
        $CLSCTX_INPROC_SERVER, DllStructGetPtr($tIID_ICaptureGraphBuilder2),
        pBuild );

local $tagCaptureBuilder2 = "QueryInterface hresult(ptr;ptr*);" & etc...
       
Global $oCaptureBuilder2 = _AutoItObject_WrapperCreate($pBuild, $tagCaptureBuilder2)

3:

local $tIID_ICaptureGraphBuilder2   = _AutoItObject_CLSIDFromString('{93e5a4e0-2d50-11d2-abfa-00a0c9c6e38d}');

Local $pCapGraphBuild2
; Get pointer to ICaptureGraphBuilder2 interface
$aCall = $oGraphBuilder.QueryInterface(Number(DllStructGetPtr($tIID_ICaptureGraphBuilder2)), 0)
If IsArray($aCall) And $aCall[2] Then
  $pCapGraphBuild2 = $aCall[2]
Else
  Return SetError(4, 0, False)
EndIf

local $tagCaptureBuilder2 = "QueryInterface hresult(ptr;ptr*);" & etc...
       
Global $oCaptureBuilder2 = _AutoItObject_WrapperCreate($pCapGraphBuild2, $tagCaptureBuilder2)

In every case I need at least the $sIID.

If I find the $sCLSID too, it's faster with objCreate, otherwise I need to poke a bit to find a pointer for the WrapperCreate.

Am I right?

The only thing is I don't see which use for CoCreateInstance (2°) because I need to create two struct from sCLSID and sIID, then extract their pointers and then use the resulting pointer for the WrapperCreate, but at this point, if I have both sCLSID and sIID, I can use directly the ObjCreate, like in 1°. Isn't it?

Share this post


Link to post
Share on other sites
ProgAndy

If you use _AutoItObject_CoCreateInstance, you need a call to WrapperCreate afterwards. In most cases, you can replace those two calls with the newer _AutoItObject_ObjCreate, if you don't need the extra parameters offered by CoCreateInstance.

PS: In the AutoIt beta, ObjCreateInterface covers the functionality of both functions from AutoItObject.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
frank10

Ok.

This

HRESULT ControlStream(
  [in]  const GUID *pCategory,
  [in]  const GUID *pType,
  [in]  IBaseFilter *pFilter,
  [in]  REFERENCE_TIME *pstart,
  [in]  REFERENCE_TIME *pstop,
  [in]  WORD wStartCookie,
  [in]  WORD wStopCookie
);

and this:

HRESULT SetFiltergraph(
  [in]  IGraphBuilder *pfg
);
pfg [in]   Pointer to the filter graph's IGraphBuilder interface.

could be converted like this?

local $tagCaptureBuilder = "QueryInterface hresult(ptr;ptr*);" & _
        "AddRef ulong();" & _
        "Release ulong();" & _
        "ControlStream hresult( ptr*;ptr*;ptr*;ptr*;ptr*;dword;dword );" & _
        "SetFiltergraph hresult( ptr* );"

SetFilterGraph is correct with ptr*?

Edited by frank10

Share this post


Link to post
Share on other sites
ProgAndy

It should be

local $tagCaptureBuilder = "QueryInterface hresult(ptr;ptr*);" & _
        "AddRef ulong();" & _
        "Release ulong();" & _
        "ControlStream hresult( ptr;ptr;ptr;ptr;ptr;ushort;ushort );" & _
        "SetFiltergraph hresult( ptr );"


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
trancexx

Remember that v-table order is important. Try this:

;===============================================================================
#interface "ICaptureGraphBuilder2"
Global Const $sCLSID_CaptureGraphBuilder2 = "{BF87B6E1-8C27-11D0-B3F0-00AA003761C5}"
Global Const $sIID_ICaptureGraphBuilder2 = "{93E5A4E0-2D50-11D2-ABFA-00A0C9C6E38D}"
; Definition
Global Const $tagICaptureGraphBuilder2 = "SetFiltergraph hresult(ptr);" & _
        "GetFiltergraph hresult(ptr*);" & _
        "SetOutputFileName hresult(clsid;wstr;ptr*;ptr*);" & _
        "FindInterface hresult(clsid;clsid;ptr;clsid;ptr*);" & _
        "RenderStream hresult(clsid;clsid;ptr;ptr;ptr);" & _
        "ControlStream hresult(clsid;clsid;ptr;ptr;ptr;word;word);" & _
        "AllocCapFile hresult(wstr;uint64);" & _
        "CopyCaptureFile hresult(wstr;wstr;int;ptr*);" & _
        "FindPin hresult(ptr;int;clsid;clsid;bool;int;ptr*);"
;===============================================================================

Local $oCaptureGraphBuilder2 = ObjCreateInterface($sCLSID_CaptureGraphBuilder2, $sIID_ICaptureGraphBuilder2, $tagICaptureGraphBuilder2)

ConsoleWrite(IsObj($oCaptureGraphBuilder2) & @CRLF)

; Call some method just for testing
$oCaptureGraphBuilder2.AllocCapFile(@ScriptDir & "bzzzz.txt", 1234)
ConsoleWrite(@error & @CRLF)

It should create a file in your script's dir called bzzzz.txt. Open it and at the end it will be a message.

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
frank10

I tried your script adapting it to the autoitObject syntax because I haven't the beta: (it caused a problem with PacketX that I need to work with, so I'm still with official 3.3.6.1.)

It crashes after the call to AllocCapFile, it correctly creates the obj, @error = 0 but it doesn't create the file and crashes.

Where did you find the correct order vtable? I tried searching with no luck in google and koders. In msdn they are in different order, only an unorder list of methods.

BTW:

I don't see clsid in the list of recognized types in autoit dllcall help, maybe is the beta?

In ControlStream I put dword even if it declares word, because followin his link EC_STREAM_CONTROL_STARTED there is DWORD.

Edited by frank10

Share this post


Link to post
Share on other sites
trancexx

Switch to latest beta. PacketX problems shouldn't exist there.

v-table order is from ProgAndy's link.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
frank10

Thank you trancexx, I tried the beta and packetx works well. So good!

Now your script works fine and: 'Hello world'.

Found the vtable: i was searching in the same site, but didn't saw it... Thank you.

Is it not necessary to declare the first three methods relative to the iUnknown?

Maybe it is sufficient to declare them only in IgraphBuilder and use them from there?

Share this post


Link to post
Share on other sites
frank10

I read the objCreateInterface doc in beta, so it has the last flag to inherit the iUnknown's interface. Good.

Also clsid is there.

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  

×