To Index an ASF File

The process of indexing an ASF file is very simple. Make a call to IWMIndexer::StartIndexing and pass the file name. The indexer does the rest. The call to StartIndexing is asynchronous, so status must be monitored using the OnStatus callback.

The following code shows how to index an ASF file. If you want to configure the indexer prior to indexing the file, you will need to include code from the example included in To Configure the Indexer.

For this example, the handle that points to the event must be created as a global variable so it will be accessible by the callback. The following declaration should appear in a global scope.

HANDLE g_hEvent = NULL;

In a more realistic scenario, the event handle should be a data member of the class that contains both the callback and the logic for starting the indexer.

The indexer sends several events to the OnStatus callback after the call to IWMIndexer::StartIndexing. You can trap them as needed for your application. At a minimum, you need to trap WMT_CLOSED, which is sent when indexing is complete. Use the following logic within the message switch in your implementation of the OnStatus callback.

// Inside the status switch statement.
case WMT_CLOSED:
   // You may want to deal with the HRESULT value passed with the status.
   // If you do, you should do it here.

   // Signal the event.
   SetEvent(g_hEvent);
   break;

For this example it is assumed that your implementation of the OnStatus callback is accessed through an object called MyCallback. For more information about using events and callbacks with this SDK, see Using the Callback Methods.

IWMIndexer* pMyIndexer     = NULL;
HRESULT     hr             = S_OK;
WCHAR       pwszFileName[] = L"C:\SomeFile.wmv";

// Initialize COM.
hr = CoInitialize(NULL);

// Create an event for asynchronous calls.
g_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

// Create an indexer.
hr = WMCreateIndexer(&pMyIndexer);

// TODO: Configure the indexer if needed. See To Configure the Indexer.

// Start the indexer.
hr = pMyIndexer->StartIndexing(pwszFileName, &MyCallback, NULL);

// Wait for the indexer to finish.
WaitForSingleObject(g_hEvent, INFINITE);

// Clean up.
pMyIndexer->Release();
pMyIndexer = NULL

CloseHandle(g_hEvent);
g_hEvent = NULL;

IWMIndexer Interface

To Configure the Indexer

WMCreateIndexer

Working with Indexes