我試圖將一個簡單的.mp3文件添加到iTunes庫,但當我調用AddFile()時,程序不斷崩潰。但是,當我調用get_Tracks()時,它返回一個有效的指針,所以我認爲指向IITLibraryPlaylist的指針是有效的。我究竟做錯了什麼?iTunes COM接口 - 無法將歌曲添加到庫
IiTunes* p_iTunes;
IITLibraryPlaylist* p_Library;
IITOperationStatus* status;
IITTrackCollection* iTrackCollection;
CoInitialize(0);
if (FAILED(CoCreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER, IID_IiTunes, (PVOID *)&p_iTunes))){
p_iTunes->Release();
CoUninitialize();
}
else{
p_iTunes->get_LibraryPlaylist(&p_Library);
p_Library->get_Tracks(&iTrackCollection); // This works, so I suppose p_Library is valid..
long trackCount = 0;
iTrackCollection->get_Count(&trackCount);
p_Library->AddFile(L"C:\\asd\asd.mp3",&status); // crashes here
}
順便說一句,你有錯誤處理做錯了。如果'CoCreateInstance()'失敗'p_iTunes'將會爲空,因此調用'Release()'會導致程序崩潰。 – sharptooth 2011-05-16 12:51:10