Opening a Shapefile (C++)

1629
4
09-27-2010 12:56 PM
MattMoyles
New Contributor III
I've been trying to open a shapefile as a workspace in ArcObjects C++ 10.  I've been trying to use this sample as a guide to go by but I can't seem to open my file. (http://help.arcgis.com/en/sdk/10.0/arcobjects_cpp/conceptualhelp/index.html#/Simplify_feature_geomet...)

int _tmain(int argc, _TCHAR* argv[])
{
    CoInitialize(0);

    ESRI_SET_VERSION(esriArcGISDesktop);

    CComBSTR srcPath;
    char path[] = "C:/points/Points_10000.shp";
    HRESULT hr = GetParentDirFromFullPath(path, &srcPath);
    CComBSTR targetWorkspacePath = L"C:\\Users\\matt.moyles\\Documents\\Visual Studio 2008\\Projects\\PointBenchmarksStandalone\\Debug";

    IWorkspaceFactoryPtr sourceWorkspaceFactory(CLSID_ShapefileWorkspaceFactory);

    IWorkspacePtr sourceWorkspace;
    hr = sourceWorkspaceFactory->OpenFromFile(srcPath, NULL, &sourceWorkspace);
    if( FAILED(hr) || sourceWorkspace == 0 )
    {
        std::wcerr << L"Couldn't open workspace " << (BSTR) srcPath << std::endl;
        return 1;
    }    

    ShutdownApp();
    CoUninitialize();
    
    return 0;
}


This line sourceWorkspaceFactory->OpenFromFile(srcPath, NULL, &sourceWorkspace); is not returning the IWorkspace.  Any help would be appreciated, I've been stuck for a few hours now.
0 Kudos
4 Replies
HeribertoMantilla_Santamaría
New Contributor
Hi

Is possible the var srcPath is empty or invalid, or try to change the NULL parameter in OpenFromFile
0 Kudos
MattMoyles
New Contributor III
Thanks, I can verify that the srcPath variable is set to the correct path because I get "Couldn't open workspace c:/points"  I tried to put in a value for the 2nd HWND parameter but it didn't seem to change anything.
0 Kudos
HeribertoMantilla_Santamaría
New Contributor
Hi again.

Try change slash for backslash in the path.
0 Kudos
MattMoyles
New Contributor III
I've tried a bunch of different little tweaks like that.  I've even tried just changing the function call to:

hr = sourceWorkspaceFactory->OpenFromFile((BSTR)"c:\\points", 0, &sourceWorkspace);

with no luck... I can run similar code in .NET/C# just fine which baffles me...
0 Kudos