为什么不能访问该元素?

时间:2016-07-15 18:05:48

标签: c++ com comtypes com-interface

这是我的代码:

#import "C:\...\.....\....tlb"

using namespace std;

int main()
{   
    HRESULT hr = CoInitialize(NULL);
    _ApplicationPtr myApp("InDesign.Application");
    DocumentPtr myDoc = myApp->ActiveDocument;
    SwatchesPtr mySwatches = myDoc->Swatches;

    cout << "Number of Swatch: " << mySwatches->Count << endl; // count = 10

    SwatchPtr first_swatch = mySwatches->Item[1L];
    SwatchPtr second_swatch = mySwatches->Item[2L]; 

    cout << first_swatch->Name; // correctly
    cout << second_swatch->Name; // crash

    cin.get();
    return 0;
}

为什么我无法访问这些元素?计数是10.任何想法?

SwatchPtr second_swatch = mySwatches->Item[2L];编译,但它是空的。

访问second_swatch->Name时出错:

error

error

0 个答案:

没有答案