Hello Bob,
I just reviewed the whole post thread. In fact, this is a FAQ in .NET
programming. Many developers may feel confused where to find corresponding
NET framework class libraries in programming. In fact, all the framwork
class library could be found at:
http://msdn.microsoft.com/library/en-us/cpref/html/cpref_start.asp?frame=tru
e
However, .NET framework class library doesn't build in all Win32 SDK APIs
or functions. That is to say, for some Win32 functions, such as GINA,
setting default printer, burning CD, we still need to use typical Win32 API
to achieve it. In order to do so in .NET programming, we provide a method
named Platform Invoke to call typical Win32 APIs in .NET application. For
more information on PInvoke, please refer to:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconinteroperatingwith
unmanagedcode.asp?frame=true
For this question, currently we have no famework class library support for
burning CD. My suggestion for you is to write a win32 DLL to expose
funtions that you need. You could select whatever languages you like to
develop this Win32 DLL, VC++ or VB. After that, we could call this
unmanaged DLL functions from managed .NET application easily. Peter Huang
has provided an existing sample to you. I also post some useful code slice
in the end of this post. You could refer to it.
There is currently no way to do this, but keep an eye out for it in the
future. We are looking at continual improvement, and it's this kind of
feedback that let us know what things you're trying to do, that we haven't
yet exposed for you.
Keep the information coming.
Thanks very much for your understanding.
Best regards,
Yanhong Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Code Slice:
Below is a simple Imapi sample that works for me. I made a console "Hello
world" project and replaced it with the code below. IT takes a command
line path of a driectory to copy, and I added the string: "e:\\CDBurn.exe"
as a known file that would be in the result.
This works for me.
// cd.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <objbase.h>
#include <stdio.h>
#include <shlobj.h>
#include "imapi.h"
HRESULT GetStorage(LPWSTR pszDir, IStorage **ppstg)
{
IShellFolder *psfDesktop;
HRESULT hr = SHGetDesktopFolder(&psfDesktop);
if (SUCCEEDED(hr))
{
IMalloc *pm;
hr = SHGetMalloc(&pm);
if (SUCCEEDED(hr))
{
LPITEMIDLIST pidl;
hr = psfDesktop->ParseDisplayName(NULL, NULL, pszDir, NULL,
&pidl,
NULL);
if (SUCCEEDED(hr))
{
hr = psfDesktop->BindToObject(pidl, NULL, IID_IStorage,
(void**)ppstg);
pm->Free(pidl);
}
pm->Release();
}
psfDesktop->Release();
}
return hr;
}
HRESULT SetUpRecorder(IDiscMaster *pdm, IJolietDiscMaster *pjdm, LPWSTR
pszDir) {
wprintf(L"Getting recorder enumerator object.\n");
IEnumDiscRecorders *pedr;
HRESULT hr = pdm->EnumDiscRecorders(&pedr);
if (SUCCEEDED(hr))
{
wprintf(L"Finding available drive.\n");
ULONG celt;
IDiscRecorder *pdr;
// pick the first supported drive to write to.
hr = pedr->Next(1, &pdr, &celt);
if (S_OK == hr)
{
wprintf(L"Setting active disc recorder.\n");
hr = pdm->SetActiveDiscRecorder(pdr);
if (SUCCEEDED(hr))
{
IStorage *pstg;
hr = GetStorage(pszDir, &pstg);
if (SUCCEEDED(hr))
{
wprintf(L"Adding data to stash file.\n");
hr = pjdm->AddData(pstg, 1);
pstg->Release();
}
else
{
wprintf(L"Couldn't get storage, please check the
path.\n");
}
}
pdr->Release();
}
else
{
wprintf(L"No supported drives found, HRESULT = 0x%08X\n", hr);
hr = E_FAIL;
}
pedr->Release();
}
return hr;
}
void DoBurn(LPWSTR pszDir)
{
wprintf(L"Burning directory %s.\n", pszDir);
wprintf(L"CoCreating object.\n");
IDiscMaster *pdm;
HRESULT hr = CoCreateInstance(CLSID_MSDiscMasterObj, NULL, CLSCTX_ALL,
IID_IDiscMaster, (void**)&pdm);
if (SUCCEEDED(hr))
{
wprintf(L"Initializing.\n");
hr = pdm->Open();
if (SUCCEEDED(hr))
{
wprintf(L"Setting active disc master format to Joliet.\n");
IJolietDiscMaster *pjdm;
hr = pdm->SetActiveDiscMasterFormat(IID_IJolietDiscMaster,
(void**)&pjdm);
if (SUCCEEDED(hr))
{
hr = SetUpRecorder(pdm, pjdm, pszDir);
if (SUCCEEDED(hr))
{
wprintf(L"Burning disc.\n");
// first param FALSE for non-simulated burn.
// second param TRUE to eject on completion.
hr = pdm->RecordDisc(FALSE, TRUE);
}
// Get IDiscRecorder and close;
IDiscRecorder* piDR;
pdm->GetActiveDiscRecorder(&piDR);
piDR->Close();
pjdm->Release();
}
}
pdm->Release();
}
if (SUCCEEDED(hr))
{
wprintf(L"Burning succeeded.\n");
}
else
{
wprintf(L"Failure, HRESULT = 0x%08X\n", hr);
}
}
int __cdecl wmain(int argc, WCHAR *argv[])
{
if (argc != 2)
{
wprintf(L"IMAPI demo\nUsage: %s <directory to burn>\nExample: \"%s
c:\\files\"\n", argv[0], argv[0]);
}
else
{
if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
{
DoBurn(argv[1]);
//===================================================================
//detect if the burn operation worked:
WIN32_FIND_DATA data;
HRESULT hr;
HANDLE hFind = FindFirstFile((LPCTSTR)"e:\\CDBurn.exe", &data);
if (hFind == INVALID_HANDLE_VALUE)
{
printf("RecordDisc did not return error but no files were burned");
hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); //<====it always
comes
here
}
else
{
FindClose(hFind);
hr = S_OK;
} //===================================================================
CoUninitialize();
}
}
return 0;
}