Adding Script to WM9 in Post Processing - Please Help

Adding Script to WM9 in Post Processing - Please Help

Post by Nicholas Pappa » Wed, 26 Mar 2003 04:41:36



        Hello all.

        I am having some troubles with adding a Script event to an
existing ASF file.  The file is created by PowerPoint (2002/XP version)
with the "Online Broadcasts" feature.
        Based on the docs, I used some code from the MetadataEdit sample
program to try and use the Metadata Editor to add a script event to the
file.  The file has a few existing Script events (slide changes), and the
MetadataEdit program does return "True" that a Script exists.  Despite
this, I can not seem to use the direct script functions.
        Using the "EditorOpenFile" function from MetadataEdit, I create a
header reference and then call "pHeaderInfo->GetScriptCount(wScriptCount)"
-- which return 0, without fail.  Then I make a call to add a new Script
event, "pHeaderInfo->AddScript(L"URL", L"http://www.msdn.com", 1000)", but
when I play the file back, the event is not triggered.
        If anyone could please help me locate the program with my code, I
would *greatly* appreciate it!  I've been trying different variations for
over a week now with no success, which is very frustrating.

        I've included the bulk of my code below, which is mostly code
straight out of the MetadataEdit sample program.
        Any help is greatly appreciated!  I'll owe you a beer! ;)

        Nick

--- Code Below ---
//------------------------------------------------------------------------------
// Name: EditorOpenFile()
// Desc: Creates metadata editor, opens file, and gets header info
interface.
//------------------------------------------------------------------------------
HRESULT EditorOpenFile( WCHAR* pwszInFile,
                        IWMMetadataEditor ** ppEditor,
                        IWMHeaderInfo ** ppHeaderInfo,
                        IWMHeaderInfo3 ** ppHeaderInfo3 )
{
    if( ( NULL == pwszInFile ) ||
        ( NULL == ppEditor ) )
    {
        return( E_INVALIDARG );
    }

    HRESULT hr = S_OK;

    do
    {
        hr = WMCreateEditor( ppEditor );
        if( FAILED( hr ) )
        {
            printf("Could not create Metadata Editor ( hr=0x%08x ).\n",
hr);
            break;
        }

        hr = ( *ppEditor )->Open( pwszInFile );
        if( FAILED ( hr ) )
        {
            printf("Could not open the file %ws ( hr=0x%08x ).\n",
pwszInFile, hr);
            break;
        }

        if( NULL != ppHeaderInfo )
        {
            hr = (*ppEditor)->QueryInterface(IID_IWMHeaderInfo, (void
**)ppHeaderInfo);
            if(FAILED(hr))
            {
                printf("Could not QI for IWMHeaderInfo ( hr=0x%08x ).\n",
hr);
                break;
            }
        }

        if( NULL != ppHeaderInfo3 )
        {
            hr = ( *ppEditor )->QueryInterface( IID_IWMHeaderInfo3,
                                                (void **)ppHeaderInfo3 );
            if( FAILED( hr ) )
            {
                printf("Could not QI for IWMHeaderInfo3 ( hr=0x%08x ).\n",
hr);
                break;
            }
        }
    }
    while( FALSE );

    return( hr );

Quote:}

HRESULT GetScriptCount(WCHAR * pwszInFile) {
    if(pwszInFile == NULL) {
                return(E_INVALIDARG);
    }

    HRESULT hr = S_OK;

    IWMMetadataEditor   * pEditor       = NULL;
    IWMHeaderInfo       * pHeaderInfo   = NULL;
        IWMHeaderInfo3          * pHeaderInfo3  = NULL;

        WORD *wScriptCount = 0;

        hr = EditorOpenFile(pwszInFile, &pEditor, &pHeaderInfo,
&pHeaderInfo3);

        pHeaderInfo->GetScriptCount(wScriptCount);
        printf("count: %d\n", wScriptCount);

        pHeaderInfo->AddScript(L"URL", L"http://www.rightstep.org", 1000);
        return hr;

Quote:}

/**************************************/
int main(int argc, char* argv[]) {
        GetScriptCount(L"test.asf");

        printf("... complete.\n");
        return 0;

Quote:}

 
 
 

Adding Script to WM9 in Post Processing - Please Help

Post by Stuart Wyatt [MS » Thu, 27 Mar 2003 02:40:55


After you add the script, does the script count go up the next time you
check it?  Are you calling Flush and Close on the metadata editor?

The player has scripts turned off by default for security reasons.  Go to
the Security tab under Tools - Options and check that scripts are turned
on..

--
-Stuart

This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:> Hello all.

> I am having some troubles with adding a Script event to an
> existing ASF file.  The file is created by PowerPoint (2002/XP version)
> with the "Online Broadcasts" feature.
> Based on the docs, I used some code from the MetadataEdit sample
> program to try and use the Metadata Editor to add a script event to the
> file.  The file has a few existing Script events (slide changes), and the
> MetadataEdit program does return "True" that a Script exists.  Despite
> this, I can not seem to use the direct script functions.
> Using the "EditorOpenFile" function from MetadataEdit, I create a
> header reference and then call "pHeaderInfo->GetScriptCount(wScriptCount)"
> -- which return 0, without fail.  Then I make a call to add a new Script
> event, "pHeaderInfo->AddScript(L"URL", L"http://www.msdn.com", 1000)", but
> when I play the file back, the event is not triggered.
> If anyone could please help me locate the program with my code, I
> would *greatly* appreciate it!  I've been trying different variations for
> over a week now with no success, which is very frustrating.

> I've included the bulk of my code below, which is mostly code
> straight out of the MetadataEdit sample program.
> Any help is greatly appreciated!  I'll owe you a beer! ;)

> Nick

> --- Code Below ---

//--------------------------------------------------------------------------
----
Quote:> // Name: EditorOpenFile()
> // Desc: Creates metadata editor, opens file, and gets header info
> interface.

//--------------------------------------------------------------------------
----

- Show quoted text -

Quote:> HRESULT EditorOpenFile( WCHAR* pwszInFile,
>                         IWMMetadataEditor ** ppEditor,
>                         IWMHeaderInfo ** ppHeaderInfo,
>                         IWMHeaderInfo3 ** ppHeaderInfo3 )
> {
>     if( ( NULL == pwszInFile ) ||
>         ( NULL == ppEditor ) )
>     {
>         return( E_INVALIDARG );
>     }

>     HRESULT hr = S_OK;

>     do
>     {
>         hr = WMCreateEditor( ppEditor );
>         if( FAILED( hr ) )
>         {
>             printf("Could not create Metadata Editor ( hr=0x%08x ).\n",
> hr);
>             break;
>         }

>         hr = ( *ppEditor )->Open( pwszInFile );
>         if( FAILED ( hr ) )
>         {
>             printf("Could not open the file %ws ( hr=0x%08x ).\n",
> pwszInFile, hr);
>             break;
>         }

>         if( NULL != ppHeaderInfo )
>         {
>             hr = (*ppEditor)->QueryInterface(IID_IWMHeaderInfo, (void
> **)ppHeaderInfo);
>             if(FAILED(hr))
>             {
>                 printf("Could not QI for IWMHeaderInfo ( hr=0x%08x ).\n",
> hr);
>                 break;
>             }
>         }

>         if( NULL != ppHeaderInfo3 )
>         {
>             hr = ( *ppEditor )->QueryInterface( IID_IWMHeaderInfo3,
>                                                 (void **)ppHeaderInfo3 );
>             if( FAILED( hr ) )
>             {
>                 printf("Could not QI for IWMHeaderInfo3 ( hr=0x%08x ).\n",
> hr);
>                 break;
>             }
>         }
>     }
>     while( FALSE );

>     return( hr );
> }

> HRESULT GetScriptCount(WCHAR * pwszInFile) {
>     if(pwszInFile == NULL) {
> return(E_INVALIDARG);
>     }

>     HRESULT hr = S_OK;

>     IWMMetadataEditor   * pEditor       = NULL;
>     IWMHeaderInfo       * pHeaderInfo   = NULL;
> IWMHeaderInfo3 * pHeaderInfo3 = NULL;

> WORD *wScriptCount = 0;

> hr = EditorOpenFile(pwszInFile, &pEditor, &pHeaderInfo,
> &pHeaderInfo3);

> pHeaderInfo->GetScriptCount(wScriptCount);
> printf("count: %d\n", wScriptCount);

> pHeaderInfo->AddScript(L"URL", L"http://www.rightstep.org", 1000);
> return hr;
> }

> /**************************************/
> int main(int argc, char* argv[]) {
> GetScriptCount(L"test.asf");

> printf("... complete.\n");
> return 0;
> }


 
 
 

Adding Script to WM9 in Post Processing - Please Help

Post by Nicholas Pappa » Thu, 27 Mar 2003 03:22:29


Quote:> After you add the script, does the script count go up the next time you
> check it?  Are you calling Flush and Close on the metadata editor?

        That was the problem!  I missed the call to flush() and close()
when I was working on the code.  The events are being placed in the file
now.
        But, I still can not get the correct script count to show up.  
When I try to print it out I always get 0 -- this is the code which
concerns that:

WORD *wScriptCount = 0;
hr = EditorOpenFile(pwszInFile, &pEditor, &pHeaderInfo, &pHeaderInfo3);
pHeaderInfo->GetScriptCount(wScriptCount);
printf("count: %d\n", wScriptCount);

        I've also tried 'pHeaderInfo3' for the pointer to the
GetScriptCount() call.  Am I missing something in here?
        It's been a while since I've worked in the Windows SDK, so maybe
my printf statement is off -- do I need a different reference, other then
'%d' to print out the correct value?

Quote:> The player has scripts turned off by default for security reasons.  Go to
> the Security tab under Tools - Options and check that scripts are turned
> on..

        Yup, noticed that WM9 wasn't firing my events, even on files that
worked before.  Thanks for pointing that out -- one more thing to add to
my instruction manual. :)

        Thank you very much for the response!  It is very nice to finally
have this working!

 
 
 

Adding Script to WM9 in Post Processing - Please Help

Post by Stuart Wyatt [MS » Thu, 27 Mar 2003 04:45:01


GetScriptCount is a WMHeaderInfo method.  The printf should technically be a
%hu since the value is a WORD but that's not the problem.  You're declaring
wScriptCount as a WORD * pointer.  You should declare it as a WORD and then
pass &wScriptCount.

--
-Stuart

This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:> > After you add the script, does the script count go up the next time you
> > check it?  Are you calling Flush and Close on the metadata editor?

> That was the problem!  I missed the call to flush() and close()
> when I was working on the code.  The events are being placed in the file
> now.
> But, I still can not get the correct script count to show up.
> When I try to print it out I always get 0 -- this is the code which
> concerns that:

> WORD *wScriptCount = 0;
> hr = EditorOpenFile(pwszInFile, &pEditor, &pHeaderInfo, &pHeaderInfo3);
> pHeaderInfo->GetScriptCount(wScriptCount);
> printf("count: %d\n", wScriptCount);

> I've also tried 'pHeaderInfo3' for the pointer to the
> GetScriptCount() call.  Am I missing something in here?
> It's been a while since I've worked in the Windows SDK, so maybe
> my printf statement is off -- do I need a different reference, other then
> '%d' to print out the correct value?

> > The player has scripts turned off by default for security reasons.  Go
to
> > the Security tab under Tools - Options and check that scripts are turned
> > on..

> Yup, noticed that WM9 wasn't firing my events, even on files that
> worked before.  Thanks for pointing that out -- one more thing to add to
> my instruction manual. :)

> Thank you very much for the response!  It is very nice to finally
> have this working!

 
 
 

Adding Script to WM9 in Post Processing - Please Help

Post by Nicholas Pappa » Wed, 02 Apr 2003 00:55:14


        Hello all, again.  I have run into another little problem with
this application (or DLL actually) I am trying to write.
        If I have an ASF file ("test.asf"), I can run the program and the
new script events are added -- no troubles!  But, if I then try to run the
program on a different file, the program fails!  Specifically, it fails
when it calls 'pEditor->Flush()'.
        I can run the program 100 times on the *same* file, but as soon as
I alter that file in any way (change the name, move a new file to the same
name, etc...) the program begins to fail.
        I figure I am not closing a reference somewhere, but I can't see
where!

        Can anyone help me out in figuring out why this is the case?  The
problem only comes up if I delete run the program on the file, delete and
move a new file to that name, and try and run the program again.
        I've included the main function of my program below.  Any non-SDK
functions that are called in this function are straight out of the
MetadataEdit sample program.

        Thanks again for any help, it is greatly appreciated!

        Nick

--- CODE BLOCK ---
HRESULT GetScriptCount(WCHAR * pwszInFile) {
    if(pwszInFile == NULL) {
                return(E_INVALIDARG);
    }

    HRESULT hr = S_OK;

    IWMMetadataEditor   * pEditor       = NULL;
    IWMHeaderInfo       * pHeaderInfo   = NULL;
    IWMHeaderInfo3      * pHeaderInfo3  = NULL;

        WORD *wScriptCount = 0;

        hr = EditorOpenFile(pwszInFile, &pEditor, &pHeaderInfo,
&pHeaderInfo3);

        pHeaderInfo->GetScriptCount(wScriptCount);
        printf("count: %hu\n", &wScriptCount);

        pHeaderInfo->AddScript(L"URL", L"http://www.microsoft.com",
100000);
        pHeaderInfo->AddScript(L"URL", L"http://www.msdn.com", 200000);

        hr = pEditor->Flush();
    if(FAILED(hr)) {
                printf("Could not flush editor ( hr=0x%08x ).\n", hr);
    }

        hr = pEditor->Close();
    if(FAILED(hr)) {
                printf("Could not close editor ( hr=0x%08x ).\n", hr);
    }

        SAFE_RELEASE(pHeaderInfo);
        SAFE_RELEASE(pHeaderInfo3);
        SAFE_RELEASE(pEditor);

        return hr;

Quote:}

 
 
 

Adding Script to WM9 in Post Processing - Please Help

Post by Stuart Wyatt [MS » Thu, 03 Apr 2003 03:56:34


The only way I can see that this would be a problem is if the file was
changed between opening the editor and calling Flush().  The way the editor
works, this is possible since the editor does not hold a reference to the
file while the editor is being used.

--
-Stuart

This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:> Hello all, again.  I have run into another little problem with
> this application (or DLL actually) I am trying to write.
> If I have an ASF file ("test.asf"), I can run the program and the
> new script events are added -- no troubles!  But, if I then try to run the
> program on a different file, the program fails!  Specifically, it fails
> when it calls 'pEditor->Flush()'.
> I can run the program 100 times on the *same* file, but as soon as
> I alter that file in any way (change the name, move a new file to the same
> name, etc...) the program begins to fail.
> I figure I am not closing a reference somewhere, but I can't see
> where!

> Can anyone help me out in figuring out why this is the case?  The
> problem only comes up if I delete run the program on the file, delete and
> move a new file to that name, and try and run the program again.
> I've included the main function of my program below.  Any non-SDK
> functions that are called in this function are straight out of the
> MetadataEdit sample program.

> Thanks again for any help, it is greatly appreciated!

> Nick

> --- CODE BLOCK ---
> HRESULT GetScriptCount(WCHAR * pwszInFile) {
>     if(pwszInFile == NULL) {
> return(E_INVALIDARG);
>     }

>     HRESULT hr = S_OK;

>     IWMMetadataEditor   * pEditor       = NULL;
>     IWMHeaderInfo       * pHeaderInfo   = NULL;
>     IWMHeaderInfo3      * pHeaderInfo3  = NULL;

> WORD *wScriptCount = 0;

> hr = EditorOpenFile(pwszInFile, &pEditor, &pHeaderInfo,
> &pHeaderInfo3);

> pHeaderInfo->GetScriptCount(wScriptCount);
> printf("count: %hu\n", &wScriptCount);

> pHeaderInfo->AddScript(L"URL", L"http://www.microsoft.com",
> 100000);
> pHeaderInfo->AddScript(L"URL", L"http://www.msdn.com", 200000);

> hr = pEditor->Flush();
>     if(FAILED(hr)) {
> printf("Could not flush editor ( hr=0x%08x ).\n", hr);
>     }

> hr = pEditor->Close();
>     if(FAILED(hr)) {
> printf("Could not close editor ( hr=0x%08x ).\n", hr);
>     }

> SAFE_RELEASE(pHeaderInfo);
> SAFE_RELEASE(pHeaderInfo3);
> SAFE_RELEASE(pEditor);

> return hr;
> }