D支持COM

Han*_*ger 10 windows com d

维基百科说:"在Microsoft Windows上,D可以访问COM(组件对象模型)代码."

D中存在什么样的COM支持?它是否比在C++中使用COM更容易.我在D页面上找到了这个链接,但它并没有告诉我太多.

小智 3

Juno 有一个新版本 .5.1,它有很多连接到 Word、Excel、FrameMaker、Trados 等的好方法。因此,这是可能的且简单的。像这样的东西:

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");
Run Code Online (Sandbox Code Playgroud)