Skip to content

Instantly share code, notes, and snippets.

@kenpb
Last active April 30, 2016 07:10
Show Gist options
  • Save kenpb/576191fec76edbda155a6c45ef223653 to your computer and use it in GitHub Desktop.
Save kenpb/576191fec76edbda155a6c45ef223653 to your computer and use it in GitHub Desktop.
#include <imapi2.h>
#include <imapi2error.h>
#include <imapi2fs.h>
#include <imapi2fserror.h>
void iampi2_cpp::convert2iso() {
HRESULT hres = 0;
CoInitialize(NULL);
IFileSystemImage* image = NULL;
IFileSystemImageResult* result = NULL;
IFsiDirectoryItem* root = NULL;
IStream* file = NULL;
IStream* r_i = NULL;
hres = CoCreateInstance(CLSID_MsftFileSystemImage, NULL, CLSCTX_ALL, __uuidof(IFileSystemImage), (void**)&image);
printf("CoCreateInstance %08X\n", hres);
hres = image->put_FileSystemsToCreate((FsiFileSystems)(FsiFileSystemJoliet | FsiFileSystemISO9660));
printf("put_FileSystemsToCreate %08X\n", hres);
hres = image->put_VolumeName(L"Pictures");
printf("put_VolumeName %08X\n", hres);
hres = image->ChooseImageDefaultsForMediaType(IMAPI_MEDIA_TYPE_CDRW);
printf("ChooseImageDefaultsForMediaType %08X\n", hres);
hres = image->get_Root(&root);
printf("get_Root %08X\n", hres);
hres = root->AddTree(L"C:\\isome", VARIANT_TRUE);
printf("AddTree %08X\n", hres);
hres = image->CreateResultImage(&result);
printf("CreateResultImage %08X\n", hres);
hres = result->get_ImageStream(&r_i);
printf("get_ImageStream %08X\n", hres);
STATSTG stg;
r_i->Stat(&stg, 1);
char* data = new char[stg.cbSize.QuadPart];
ULONG size;
r_i->Read(data, stg.cbSize.QuadPart, &size);
FILE* f = fopen("C:\\image.iso", "wb");
fwrite(data, stg.cbSize.QuadPart, 1, f);
fclose(f);
delete data;
r_i->Release();
root->Release();
result->Release();
image->Release();
CoUninitialize();
}
using system;
namespace csharp_console
{
using iampi2_cpp;
class Program
{
static iampi2_class cpp = new iampi2_class();
static void Main(string[] args)
{
cpp.convert2iso();
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment