 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
SmartDude Guest
|
Posted: Mon Jan 29, 2007 9:10 am Post subject: Writing to CD/DVD using COM |
|
|
I'm working with example code from MSDN thats supposed to wrapper all the
COM stuff but it was originaly written for vc.NET so i converted it the best
i could to BCB6. It looks like it should work but the CoCreateInstance()
always fails. If it worked, this code would tell you if you have a writable
CD drive and What the drive letter is. Also where the temp folder is where
files to be written to CD go.
check out: http://msdn.microsoft.com/msdnmag/issues/04/04/CQA/ and
http://msdn2.microsoft.com/en-us/library/ms646705.aspx
#define NO_WIN32_LEAN_AND_MEAN
#include <vcl.h>
#include <windows.h>
#include <shellapi.h>
#include <ShlObj.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include "atl\atlvcl.h" //ALREADY SEEMS TO INCLUDE THE ATL HEADERS
//#include "atl\atlbase.h" // for CComQIPtr etc.
//#include <atlstr.h> // ..for CString
#include <imapi.h> // IMAPI interfaces..
#include <imapierror.h> // ..and error codes
#pragma hdrstop
#include "Unit1.h"
#ifndef TRACE
#define TRACE ATLTRACE
#endif
#ifndef ASSERT
#define ASSERT ATLASSERT
#endif
#define TRACEHR(funcname,hr) \
if (!SUCCEEDED(m_hr)) { Application->MessageBox("failed", "ERROR", MB_OK);}
//The IID and CLSID are not in the standard uuid.lib, so have been defined
here.
const IID IID_ICDBurn =
{0x3d73a659,0xe5d0,0x4d42,{0xaf,0xc0,0x51,0x21,0xba,0x42,0x5c,0x8d}};
const CLSID CLSID_CDBurn =
{0xfbeb8a05,0xbeee,0x4442,{0x80,0x4e,0x40,0x9d,0x6c,0x45,0x15,0xe9}};
class CCDBurn : public CComQIPtr<ICDBurn>
{
public:
HRESULT m_hr; // last error code
CCDBurn() {
// HRESULT hr = CoCreateInstance(CLSID_CDBurn,
NULL,CLSCTX_INPROC_SERVER,IID_ICDBurn,(LPVOID*)&pICDBurn);
// m_hr = ::CoCreateInstance(CLSID_CDBurn,NULL,CLSCTX_INPROC_SERVER,
IID_ICDBurn,(LPVOID*)this);
// m_hr = CoCreateInstance(CLSID_CDBurn,NULL,CLSCTX_INPROC_SERVER);
// CCDBurn burn;
m_hr = ::CoCreateInstance((CLSID)CLSID_CDBurn,
NULL,CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER,(IID)
IID_ICDBurn,(LPVOID*)&burn);
///////THIS IS THE PROBLEM AREA!!////
if (!SUCCEEDED(m_hr)) { Application->MessageBox("failed", "message",
MB_OK);}
else { Application->MessageBox("it worked", "message", MB_OK);}
}
~CCDBurn() { }
// Burn the data in staging area to CD
//
BOOL Burn(HWND hwnd) {
m_hr = (*this)->Burn(hwnd);
TRACEHR(_T("CCDBurn::Burn"),m_hr);
return SUCCEEDED(m_hr);
}
// Does this machine have a recordable drive?
//
BOOL HasRecordableDrive() {
BOOL bHasIt=FALSE;
m_hr = (*this)->HasRecordableDrive(&bHasIt);
TRACEHR(_T("CCDBurn::HasRecordableDrive"),m_hr);
return (SUCCEEDED(m_hr) && bHasIt);
}
// Get drive letter for recordable CD drive, return as STL string.
//
String GetRecorderDriveLetter() {
WCHAR d[32]={0};
m_hr = (*this)->GetRecorderDriveLetter(d, sizeof(d)/sizeof(d[0]));
TRACEHR(_T("CCDBurn::GetRecorderDriveLetter"),m_hr);
return d;
}
// Get location of burn (staging) area. You can change this by setting a
// registry entry or using TWEAKUI in PowerToys for XP.
// This is not an ICDBurn method, but useful anyway.
//
String GetBurnFolderPath() {
TCHAR path[MAX_PATH]={0};
m_hr = SHGetSpecialFolderPath(NULL, path, CSIDL_CDBURN_AREA, FALSE);
TRACEHR(_T("CCDBurn::GetBurnFolderPath"),m_hr);
return path;
}
};
....
TForm *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
// burn path
String str;
CCDBurn cdb;
if (!cdb.HasRecordableDrive())
str = "No recordable drive.";
else
str = "recordable drive detected.";
Application->MessageBox(str.c_str(), "Look", MB_OK);
str = cdb.GetRecorderDriveLetter();
Application->MessageBox(str.c_str(), "Look", MB_OK);
str = cdb.GetBurnFolderPath();
Application->MessageBox(str.c_str(), "Look", MB_OK);
} |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Jan 30, 2007 12:04 am Post subject: Re: Writing to CD/DVD using COM |
|
|
"SmartDude" <smartdude81 (AT) comcast (DOT) net> wrote in message
news:45bdabd6$1 (AT) newsgroups (DOT) borland.com...
| Quote: | It looks like it should work but the CoCreateInstance() always
fails. |
I do not see you calling CoInitialize/Ex() anywhere. If you look at
the HRESULT that CoCreateInstance() is returning, it is likely
returning CO_E_NOTINITIALIZED.
| Quote: | If it worked, this code would tell you if you have a writable
CD drive and What the drive letter is. Also where the temp
folder is where files to be written to CD go.
|
Only on XP and higher. For any other system, you will have to use
third-party libraries, or else use ASPI/SPTI to send SCSI comands to
the hardware directly (I just wrote my own code to do exactly that, it
is not too difficult).
Gambit |
|
| Back to top |
|
 |
SmartDude Guest
|
Posted: Tue Jan 30, 2007 6:36 am Post subject: Re: Writing to CD/DVD using COM |
|
|
| Quote: | Only on XP and higher. For any other system, you will have to use
third-party libraries, or else use ASPI/SPTI to send SCSI comands to
the hardware directly (I just wrote my own code to do exactly that, it
is not too difficult).
Gambit
|
I have to disagree. writing a CD driver seems extremely difficult but thats
great if it works. Does it work on most CD RW drives? Please show me some
of it.
| Quote: | I do not see you calling CoInitialize/Ex() anywhere. If you look at
the HRESULT that CoCreateInstance() is returning, it is likely
returning CO_E_NOTINITIALIZED.
|
Thats funny because then the example was wrong but i'll try that. |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Jan 30, 2007 8:20 am Post subject: Re: Writing to CD/DVD using COM |
|
|
"SmartDude" <smartdude81 (AT) comcast (DOT) net> wrote in message
news:45be92b8$1 (AT) newsgroups (DOT) borland.com...
| Quote: | I have to disagree. writing a CD driver seems extremely difficult
but
thats great if it works.
|
I did not say to write a CD driver. You don't need to write a custom
driver for what I suggested. ASPI (Advanced SCSI Programming
Interface) and SPTI (SCSI Pass Through Interface) are
application-layer APIs that allow you to send standard SCSI MMC
commands to hardware.
ASPI is natively installed on Win9x/Me. It has a ASPI function, named
SendASPI32Command(), that is exported from wnaspi32.dll in the
%SYSDIR% directory.
SPTI is natively available on NT4+. It has two I/O controls, named
IOCTL_SCSI_PASS_THROUGH and IOCTL_SCSI_PASS_THROUGH_DIRECT, that can
be used with DeviceIoControl().
| Quote: | Does it work on most CD RW drives?
|
The MMC spec is freely available from http://www.t10.org. Most modern
CD/DVD drives (read/write and read-only) support at least MMC-3,
though the specs go up to MMC-6 currently. There are flags and
commands that deal specifically with CD writing and DVD writing
separately. I wrote fully working application code in a few days that
was able to query CD and DVD drives for their capabilities, whether
media was present and what type it was, etc.
| Quote: | Please show me some of it.
|
I have posted an example application to the .attachments newsgroup.
It locates all CD/DVD drives and reports some of their information. I
wrapped ASPI and SPTI in their own classes that derive from an
abstract base class to help hide the platform-specific details. The
code was written with another specific application in mind, so some of
its functions are not generalized and others are not implemented, but
you can expand on it as needed. I've included the relavant specs from
http://www.t10.org.
| Quote: | Thats funny because then the example was wrong but i'll try that.
|
The example is not wrong. It just does not show everything. Most
Microsoft examples of COM assume that you already have a basic
understanding of the requirements (calling CoInitialize/Ex() and
CoUninitialize(), reference counting, etc) so they leave those details
out.
Gambit |
|
| Back to top |
|
 |
SmartDude Guest
|
Posted: Tue Jan 30, 2007 9:10 am Post subject: Re: Writing to CD/DVD using COM |
|
|
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:45beabeb$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
I did not say to write a CD driver. You don't need to write a custom
driver for what I suggested. ASPI (Advanced SCSI Programming
Interface) and SPTI (SCSI Pass Through Interface) are
application-layer APIs that allow you to send standard SCSI MMC
commands to hardware.
ASPI is natively installed on Win9x/Me. It has a ASPI function, named
SendASPI32Command(), that is exported from wnaspi32.dll in the
%SYSDIR% directory.
SPTI is natively available on NT4+. It has two I/O controls, named
IOCTL_SCSI_PASS_THROUGH and IOCTL_SCSI_PASS_THROUGH_DIRECT, that can
be used with DeviceIoControl().
Does it work on most CD RW drives?
The MMC spec is freely available from http://www.t10.org. Most modern
CD/DVD drives (read/write and read-only) support at least MMC-3,
though the specs go up to MMC-6 currently. There are flags and
commands that deal specifically with CD writing and DVD writing
separately. I wrote fully working application code in a few days that
was able to query CD and DVD drives for their capabilities, whether
media was present and what type it was, etc.
Please show me some of it.
I have posted an example application to the .attachments newsgroup.
It locates all CD/DVD drives and reports some of their information. I
wrapped ASPI and SPTI in their own classes that derive from an
abstract base class to help hide the platform-specific details. The
code was written with another specific application in mind, so some of
its functions are not generalized and others are not implemented, but
you can expand on it as needed. I've included the relavant specs from
http://www.t10.org.
Thats funny because then the example was wrong but i'll try that.
The example is not wrong. It just does not show everything. Most
Microsoft examples of COM assume that you already have a basic
understanding of the requirements (calling CoInitialize/Ex() and
CoUninitialize(), reference counting, etc) so they leave those details
out.
Gambit
|
I tried your project and it works. The 'specs' file was corrupted and that
was the first post. The other number of posts after that looked like you
were sending it UUENCODE or whatever they call it now. Was that because the
file was too big to be attached to one post?
Coincidentally I made a NOT TO BAD program that splits files. Its in the
..attachments newsgroup. |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Jan 31, 2007 2:01 am Post subject: Re: Writing to CD/DVD using COM |
|
|
"SmartDude" <smartdude81 (AT) comcast (DOT) net> wrote in message
news:45bec209$1 (AT) newsgroups (DOT) borland.com...
| Quote: | The 'specs' file was corrupted and that was the first post. The
other
number of posts after that looked like you were sending it UUENCODE
or whatever they call it now. Was that because the file was too big
to
be attached to one post?
|
Yes. The specs file is 10MB. I don't remember what the max size is
that Borland's server enforces.
Did you download all 29 parts and combine them? I don't know about
other newsreaders, but Outlook (Express) has an option to auto-combine
all of the pieces. Just highlight them all, right-click, and choose
"recombine".
Otherwise, just go to http://www.t10.org and download the specs.
There is only 2 you really need - SPC-3, which is the generic commands
for all SCSI devices, and MMC-3, which is the multimedia-specific
commands.
| Quote: | Coincidentally I made a NOT TO BAD program that splits files.
|
I have several splitters available already.
Gambit |
|
| Back to top |
|
 |
SmartDude Guest
|
Posted: Wed Jan 31, 2007 6:30 am Post subject: Re: Writing to CD/DVD using COM |
|
|
| Quote: | Did you download all 29 parts and combine them? I don't know about
other newsreaders, but Outlook (Express) has an option to auto-combine
all of the pieces. Just highlight them all, right-click, and choose
"recombine".
I tried that but after it combined them into a message it wants to look for |
hyperlinks and basicly chokes. I don't know. It would just be easier to
implement cd burning with the XP COM library. I can get that to work now
thanks to your help.
| Quote: | I have several splitters available already.
|
I seen the simpler ones and mine is better. It writes the file pieces to
removable media and pauses to let you change disks or whatever it is your
using. It automaticly writes the file piece to the size of the media. Also
has a format option. It also puts files back together. I wanted to add
writable CD/DVD support for this thing so it would acually be good for
backing up files plus its free. |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Jan 31, 2007 6:47 am Post subject: Re: Writing to CD/DVD using COM |
|
|
"SmartDude" <smartdude81 (AT) comcast (DOT) net> wrote in message
news:45bfe2e7 (AT) newsgroups (DOT) borland.com...
| Quote: | I tried that but after it combined them into a message it wants to
look
for hyperlinks and basicly chokes.
|
I just tried it and it worked fine.
| Quote: | It would just be easier to implement cd burning with the XP COM
library. |
ICDBurn is XP-specific, only supports CDs and not DVDs, doesn't allow
you to pick the drive you want to use (in case a machine has multiple
writers available), and requires you to make duplicates of all files
you want to burn. ICDBurn is a *very* bare-bones approach to writing
CDs. Even if you were to use IMAPI (IDiscMaster) instead of ICDBurn,
it still only supports XP, only supports CDs but not DVDs, and still
requires a separate staging area for files, wasting hard drive space.
If that works for you, then good. But if you want something more
flexible, then using the built-in COM interfaces is not the way to go.
Gambit |
|
| Back to top |
|
 |
SmartDude Guest
|
Posted: Wed Jan 31, 2007 9:10 am Post subject: Re: Writing to CD/DVD using COM |
|
|
| Quote: | If that works for you, then good. But if you want something more
flexible, then using the built-in COM interfaces is not the way to go.
Gambit
|
So if I just wanted to get the bytes free and save a file to a CD/DVD how
hard would that be using ASPI/SPTI? |
|
| Back to top |
|
 |
SmartDude Guest
|
Posted: Thu Feb 01, 2007 5:09 am Post subject: Re: Writing to CD/DVD using COM |
|
|
| Quote: | If that works for you, then good. But if you want something more
flexible, then using the built-in COM interfaces is not the way to go.
Gambit
|
So if I just wanted to get the bytes free and save a file to a CD/DVD how
hard would that be using ASPI/SPTI?
The reason i'm asking this is because sending SCSI commands is the low level
aproach and would probably only be good for writting raw data to a CD/DVD.
It could work but i would have to change my whole program around to support
such a feature. Raw data won't show up in the file system either. But in
any case i'd be cluless. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|