Thread: IMAPI2: cannot finish the burn process

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Latvia
    Posts
    102

    IMAPI2: cannot finish the burn process

    Hi, I'm trying to use IWriteEngine2 of IMAPI2 to write a single sector to a disc at LBA 0. Everything goes fine until the very end - when it's supposed to stop burning, the disc keeps spinning and the device is locked. I can't open the tray without doing a restart. In fact, WriteSection() returns S_OK, indicating that data must've been written, although the medium (CD-RW) remains blank afterwards (checked with hex editor).

    Every call to the COM methods returns S_OK (this is what Assert() checks for), see excerpt below.
    Code:
    	CoInitialize(NULL);
    
    	IWriteEngine2* writeEngine;
    	Assert(CoCreateInstance(__uuidof(MsftWriteEngine2), NULL, CLSCTX_ALL,
    		__uuidof(IWriteEngine2), (void**)&writeEngine));
    	
    	IDiscRecorder2* discRecorder;
    	Assert(CoCreateInstance(__uuidof(MsftDiscRecorder2), NULL, CLSCTX_ALL,
    		__uuidof(IDiscRecorder2), (void**)&discRecorder));
    
    	IDiscMaster2* discMaster;
    	Assert(CoCreateInstance(__uuidof(MsftDiscMaster2), NULL, CLSCTX_ALL,
    		__uuidof(IDiscMaster2), (void**)&discMaster));
    
    	BSTR uniqueID;
    	long numDevices = 0;
    	Assert(discMaster->get_Count(&numDevices));
    	for(int i = 0; i < 100; i++)
    		if(discMaster->get_Item(i, &uniqueID) == S_OK) break;
    	Assert(discRecorder->InitializeDiscRecorder(uniqueID));
    	Assert(discRecorder->AcquireExclusiveAccess(VARIANT_TRUE, SysAllocString(L"abcd")));
    	Assert(writeEngine->put_Recorder((IDiscRecorder2Ex*)discRecorder));
    	Assert(writeEngine->put_BytesPerSector(2048));
    	Assert(writeEngine->put_StartingSectorsPerSecond(-1));
    	Assert(writeEngine->put_EndingSectorsPerSecond(-1));
    
    	IStream* patternStream;
    	patternStream = SHCreateMemStream(pattern, 2048); //pattern is a valid pointer to 2048 bytes of memory
    
    	Assert(writeEngine->WriteSection(patternStream, 0, 1)); //after burning this returns S_OK
    
    	Assert(discRecorder->ReleaseExclusiveAccess());
    I've tried reading the stream, which works fine, so it shouldn't be a problem with IStream. The reason I'm using IWriteEngine2 is that data will be generated "on the fly" and should not be written in the conventional data CD format, but raw.

    Let me know of any ideas to fix this. Thanks!
    Last edited by Overlord; 06-11-2011 at 04:19 AM.

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Quote Originally Posted by Overlord View Post
    Code:
    	Assert(writeEngine->put_Recorder((IDiscRecorder2Ex*)discRecorder));
    discRecorder is an IDiscRecorder2* not an IDiscRecorder2Ex*. These are about the same as a HWND and a HBITMAP.
    To get an instance of this interface (IDiscRecorder2Ex), create an instance of the IDiscRecorder2 interface and then call the IDiscRecorder2::QueryInterface method to retrieve the IDiscRecorder2Ex interface.
    This isn't optional.

    Also:
    Code:
    Assert(discRecorder->AcquireExclusiveAccess(VARIANT_TRUE, SysAllocString(L"abcd")/* mem leak */));

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Latvia
    Posts
    102
    Thanks for replying, adeyblue, but it still doesn't work - the diode on the drive keeps blinking and it won't open. In addition to preventing the mem leak, this is how I acquired the new interface:
    Code:
    	IDiscRecorder2Ex* discRecorder;
    	discRecorderNoEx->QueryInterface(IID_IDiscRecorder2Ex, (void**)&discRecorder);
    	Assert(writeEngine->put_Recorder(discRecorder));
    Have you worked with these interfaces? Maybe you've got some examples I could verify my code against?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vector of Objects = crash and burn
    By Vandrian in forum C++ Programming
    Replies: 5
    Last Post: 04-14-2008, 10:14 PM
  2. Burn large nero image to multiple cd's?
    By Waldo2k2 in forum Tech Board
    Replies: 3
    Last Post: 05-20-2004, 08:14 AM
  3. How do I burn this onto a CD?
    By Leeman_s in forum Tech Board
    Replies: 4
    Last Post: 08-04-2003, 10:36 AM
  4. Nero Burn
    By jinx in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-09-2002, 09:37 PM