I think I have found the solution. The confusion is about what IDatasetEdit::isBeingEdited( VARIANT_BOOL* pIsBeingEdited) actually means. If pIsBeingEdited is VARIANT_TRUE, then it means the current application is editing the dataset (or standalone feature class). If pIsBeingEdited is VARIANT_FALSE, then it means some OTHER application has a write lock on the dataset (or standalone feature class). Here is how I used this information to return the information I needed about which datasets are read-only to my application. Please note that in the C++ snippets below, the code is extracted from a class that has class members starting with m_.
void
MyClass::updateReadOnlyForDataset(BSTR dataset_name)
{
if(m_ipWorkspace == NULL)
return;
try
{
IFeatureDatasetPtr ipFeatureDataset = NULL;
IFeatureWorkspacePtr ipFeatureWorkspace( m_ipWorkspace );
HRESULT hr = ipFeatureWorkspace->OpenFeatureDataset(dataset_name, &ipFeatureDataset );
if(ipFeatureDataset)
{
IDatasetEditPtr datasetEdit = NULL;
datasetEdit = ipFeatureDataset;
if(datasetEdit)
{
VARIANT_BOOL pIsBeingEdited = VARIANT_FALSE;
//are we editing this dataset or does another app have it locked?
hr = datasetEdit->IsBeingEdited(&pIsBeingEdited);
if(pIsBeingEdited == VARIANT_FALSE)
{
//since we are not editing it, then it is locked by another app
m_read_only = true;
}
}
}
}
catch(...)
{
//report error
}
}
void
MyClass::updateReadOnlyForFeatureClass(BSTR layer_name)
{
if(m_ipWorkspace == NULL)
return;
try
{
IFeatureClassPtr ipFeatureClass = NULL;
IFeatureWorkspacePtr ipFeatureWorkspace( m_ipWorkspace );
HRESULT hr = ipFeatureWorkspace->OpenFeatureClass(layer_name, &ipFeatureClass );
if(ipFeatureClass)
{
IDatasetEditPtr datasetEdit = NULL;
datasetEdit = ipFeatureClass;
//are we editing this standalone fc or does another app have it locked?
if(datasetEdit)
{
VARIANT_BOOL pIsBeingEdited = VARIANT_FALSE;
hr = datasetEdit->IsBeingEdited(&pIsBeingEdited);
if(pIsBeingEdited == VARIANT_FALSE)
{
//since we are not editing it, then it is locked by another app
m_read_only = true;
}
}
}
}
catch(...)
{
//report error
}
}
// main
HRESULT hr = _ipWorkspaceEdit->StartEditing( VARIANT_FALSE );
...
BSTR layer_name = ::AoAllocBSTR( L"None" );
...
ipDataset->get_Name( &layer_name );
//if testing a dataset ...
updateReadOnlyForDataset(layer_name );
//if testing a standalone feature class ...
updateReadOnlyForFeatureClass(layer_name);