Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D support for COM

Tags:

windows

com

d

Wikipedia says the following: "On Microsoft Windows, D can access COM (Component Object Model) code."

What kind of support for COM is present in D? Does it make life easier than using COM in C++. I've found this link on the D page but it doesn't tell me too much.

like image 486
Hannes de Jager Avatar asked Sep 13 '10 08:09

Hannes de Jager


1 Answers

Juno has a new version .5.1 that has lots of great ways of connecting to Word, Excel, FrameMaker, Trados, etc. So, it is possible and easy. Something like this:

scope word = new DispatchObject("Word.Application");
scope wDocs = word.get("Documents");

char[] dd  = dir ~ r"\";

char[][] docs = GetFilesFromDir(dir ~ r"\", "*." ~ fromType, true);
if (docs.length == 0)
{
  info.text = "Did not find any " ~ std.string.toupper(fromType) ~
    " files in the directory... \n\nExiting...";
  return;
}
foreach(char[] d; docs)
{
  scope wDoc = wDocs.call("Open", d);//"Normal", false, 0);
  char[] txt = std.path.getName(d);  // original file ie. test if it was test.doc
  txt ~= ".doc";
  if (std.file.exists(txt))
    std.file.remove(txt);

  wDoc.call("SaveAs",
      txt,      // FileName
      0,        // FileFormat wdFormatDOC = 0
      false,    // LockComments
      "",       // Password
      false,    // AddToRecentFiles
      "",       // WritePassword
      false,    // ReadOnlyRecommended
      false,    // EmbedTrueTypeFonts
      false,    // SaveNativePictureFormat
      false,    // SaveFormsData
      false,    // SaveAsAOCELetter
      65001,    // Encoding 65001 is UTF8
      false,    // InsertLineBreaks
      false,    // AllowSubstitutions
      0         // LineEnding Const wdCRLF = 0
      );
  wDoc.call("Close");
}
word.call("Quit");
like image 57
jicman Avatar answered Oct 31 '22 09:10

jicman