2011-04-04 94 views
1

我想通过使用IMAPI2.dll来添加设备以将CD/DVD刻录到我的应用程序中。我正在使用Microsoft Visual FoxPro 9 SP 2来发掘。当我使用作为IMAPI2.MsftDiscFormat2Data类(示例代码的最后一行)成员的Write()方法时,Visual FoxPro会提供以下错误消息。错误消息:“OLE错误代码0x80004002:不支持此类接口。”使用IMAPI2.dll刻录CD/DVD

操作系统:Windows 7

请帮助。

**--Creating MsftDiscMaster2 object to connect to optical drives. 
loDiscMaster = CREATEOBJECT("IMAPI2.MsftDiscMaster2") 

**--Creating MsftDiscRecorder2 object for the specified burning device. 
loRecorder = CREATEOBJECT("IMAPI2.MsftDiscRecorder2") 
lcUniqueId = loDiscMaster.ITEM(0) 
loRecorder.InitializeDiscRecorder(lcUniqueId) 

**--Create an image stream for the specified directory. 
loFileSystem = CREATEOBJECT("IMAPI2FS.MsftFileSystemImage") 
loRootDir = loFileSystem.Root 

**--Create the new disc format and set the recorder. 
loDataWriter = CREATEOBJECT("IMAPI2.MsftDiscFormat2Data") 
loDataWriter.Recorder = loRecorder 
loDataWriter.ClientName = "IMAPIv2 TEST" 

loFileSystem.ChooseImageDefaults(loRecorder) 

**--Add the directory and its contents to the file system. 
loRootDir.AddTree("F:\VSS",.F.) 

**--Create an image from the file system 
loResultImage = loFileSystem.CreateResultImage() 
loStream = loResultImage.ImageStream 

**--Write stream to disc using the specified recorder. 
loDataWriter.Write(loStream) 

回答

1

恐怕你运气不好。 FoxPro以相当高的级别与COM对象交互。实际上,它的工作方式与VBScript与COM交互的方式非常相似。通常,如果你的代码在VBScript中工作,它也可以在FoxPro中工作。

这实际上是一些ActiveX/COM库的常见问题。尽管在imapi2.dll和imapi2fs.dll中实现的对象全都使用IDispatch-- COM接口的最高级别和最可互操作的形式 - 这些对象的某些方法参数,方法返回和属性不是IDispatch。

具体而言,ImageStream属性返回的内容为IStream,它继承自IUnknown而不是IDispatch。因此,ImageStream属性返回FoxPro不知道如何处理的内容。 FoxPro知道它是一个COM接口,但它不知道如何查找或调用该对象上的方法。