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....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...roperatingwith
unmanagedcode.a sp?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(LPWS TR pszDir, IStorage **ppstg)
{
IShellFolder *psfDesktop;
HRESULT hr = SHGetDesktopFol der(&psfDesktop );
if (SUCCEEDED(hr))
{
IMalloc *pm;
hr = SHGetMalloc(&pm );
if (SUCCEEDED(hr))
{
LPITEMIDLIST pidl;
hr = psfDesktop->ParseDisplayNa me(NULL, NULL, pszDir, NULL,
&pidl,
NULL);
if (SUCCEEDED(hr))
{
hr = psfDesktop->BindToObject(p idl, NULL, IID_IStorage,
(void**)ppstg);
pm->Free(pidl);
}
pm->Release();
}
psfDesktop->Release();
}
return hr;
}
HRESULT SetUpRecorder(I DiscMaster *pdm, IJolietDiscMast er *pjdm, LPWSTR
pszDir) {
wprintf(L"Getti ng recorder enumerator object.\n");
IEnumDiscRecord ers *pedr;
HRESULT hr = pdm->EnumDiscRecord ers(&pedr);
if (SUCCEEDED(hr))
{
wprintf(L"Findi ng 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"Setti ng active disc recorder.\n");
hr = pdm->SetActiveDiscR ecorder(pdr);
if (SUCCEEDED(hr))
{
IStorage *pstg;
hr = GetStorage(pszD ir, &pstg);
if (SUCCEEDED(hr))
{
wprintf(L"Addin g data to stash file.\n");
hr = pjdm->AddData(pstg , 1);
pstg->Release();
}
else
{
wprintf(L"Could n'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"Burni ng directory %s.\n", pszDir);
wprintf(L"CoCre ating object.\n");
IDiscMaster *pdm;
HRESULT hr = CoCreateInstanc e(CLSID_MSDiscM asterObj, NULL, CLSCTX_ALL,
IID_IDiscMaster , (void**)&pdm);
if (SUCCEEDED(hr))
{
wprintf(L"Initi alizing.\n");
hr = pdm->Open();
if (SUCCEEDED(hr))
{
wprintf(L"Setti ng active disc master format to Joliet.\n");
IJolietDiscMast er *pjdm;
hr = pdm->SetActiveDiscM asterFormat(IID _IJolietDiscMas ter,
(void**)&pjdm);
if (SUCCEEDED(hr))
{
hr = SetUpRecorder(p dm, pjdm, pszDir);
if (SUCCEEDED(hr))
{
wprintf(L"Burni ng disc.\n");
// first param FALSE for non-simulated burn.
// second param TRUE to eject on completion.
hr = pdm->RecordDisc(FAL SE, TRUE);
}
// Get IDiscRecorder and close;
IDiscRecorder* piDR;
pdm->GetActiveDiscR ecorder(&piDR);
piDR->Close();
pjdm->Release();
}
}
pdm->Release();
}
if (SUCCEEDED(hr))
{
wprintf(L"Burni ng succeeded.\n");
}
else
{
wprintf(L"Failu re, 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(CoIn itializeEx(NULL , COINIT_APARTMEN TTHREADED)))
{
DoBurn(argv[1]);
//=============== =============== =============== =============== =======
//detect if the burn operation worked:
WIN32_FIND_DATA data;
HRESULT hr;
HANDLE hFind = FindFirstFile(( LPCTSTR)"e:\\CD Burn.exe", &data);
if (hFind == INVALID_HANDLE_ VALUE)
{
printf("RecordD isc did not return error but no files were burned");
hr = HRESULT_FROM_WI N32(ERROR_FILE_ NOT_FOUND); //<====it always
comes
here
}
else
{
FindClose(hFind );
hr = S_OK;
} //=============== =============== =============== =============== =======
CoUninitialize( );
}
}
return 0;
}