changeset 153:8907b6374258

Tangofied the OLE snippet 81
author Frank Benoit <benoit@tionex.de>
date Thu, 21 Aug 2008 17:49:33 +0200
parents dd312a353df6
children 57cb6d948bf7
files snippets/ole/Snippet81.d
diffstat 1 files changed, 79 insertions(+), 125 deletions(-) [+]
line wrap: on
line diff
--- a/snippets/ole/Snippet81.d	Thu Aug 21 17:49:17 2008 +0200
+++ b/snippets/ole/Snippet81.d	Thu Aug 21 17:49:33 2008 +0200
@@ -21,33 +21,6 @@
  * http://www.eclipse.org/swt/snippets/
  */
 
-bug
-{
-    pragma(lib, "DD-dwt-dbg.lib");
-}
-else
-{
-    pragma(lib, "DD-dwt.lib");
-}
-pragma(lib, "advapi32.lib");
-pragma(lib, "comctl32.lib");
-pragma(lib, "comdlg32.lib");
-pragma(lib, "gdi32.lib");
-pragma(lib, "gdiplus.lib");
-pragma(lib, "glu32.lib");
-pragma(lib, "imm32.lib");
-pragma(lib, "kernel32.lib");
-pragma(lib, "msimg32.lib");
-pragma(lib, "ole32.lib");
-pragma(lib, "oleacc.lib");
-pragma(lib, "oleaut32.lib");
-pragma(lib, "olepro32.lib");
-pragma(lib, "opengl32.lib");
-pragma(lib, "shlwapi.lib");
-pragma(lib, "user32.lib");
-pragma(lib, "usp10.lib");
-pragma(lib, "uxtheme.lib");
-
 import dwt.DWT;
 import dwt.widgets.Display;
 import dwt.widgets.Shell;
@@ -61,111 +34,96 @@
 import dwt.ole.win32.OleFunctionDescription;
 import dwt.ole.win32.OlePropertyDescription;
 
-import std.cstream;
-import std.path;
-import std.stream;
+import tango.io.Stdout;
+import tango.io.Print;
+import tango.text.convert.Format;
 
-alias char[] string;
-
-int main(string[] asArg)
-{
+int main() {
     int iRes = 0;
 
-    try
-    {
-    //  String progID = "Shell.Explorer";
-        String progID = "Excel.Application";
-        
-        Display oDisplay = new Display();
-        Shell oShell = new Shell(oDisplay);
-    
-        OleFrame frame = new OleFrame(oShell, DWT.NONE);
-        OleControlSite oOleSite = null;
-        OleAutomation oOleAutoObj = null;
-        try
-        {
-            oOleSite = new OleControlSite(frame, DWT.NONE, progID); 
-        } catch (Exception oExc)
-        {
-            dout.writefln("Exception %s creating OleControlSite on type library for %s", oExc.toString(), progID);
-            return 1;
-        }
-        try
-        {
-            oOleAutoObj = new OleAutomation(oOleSite);
-        } catch (Exception oExc)
-        {
-            dout.writefln("Exception %s  OleAutomation on type library for %s", oExc.toString(), progID);
-            return 1;
-        }
-        
-        dout.writefln("TypeLibrary for: '%s'", progID);
-        printTypeInfo(oOleAutoObj, dout);
-        
-        oShell.dispose();
-        oDisplay.dispose();
-    } catch (Exception oExc)
-    {
-        dout.writefln("Exception %s in main()", oExc.toString());
-        iRes = 1;
+    String progID = "Shell.Explorer";
+    //String progID = "Excel.Application";
+
+    Display oDisplay = new Display();
+    Shell oShell = new Shell(oDisplay);
+
+    OleFrame frame = new OleFrame(oShell, DWT.NONE);
+    OleControlSite oOleSite = null;
+    OleAutomation oOleAutoObj = null;
+    try {
+        oOleSite = new OleControlSite(frame, DWT.NONE, progID); 
+    }
+    catch (Exception oExc) {
+        Stdout.formatln("Exception {} creating OleControlSite on type library for {}", oExc.toString(), progID);
+        return 1;
     }
-    
+    try {
+        oOleAutoObj = new OleAutomation(oOleSite);
+    }
+    catch (Exception oExc) {
+        Stdout.formatln("Exception {}  OleAutomation on type library for {}", oExc.toString(), progID);
+        return 1;
+    }
+
+    Stdout.formatln("TypeLibrary for: '{}'", progID);
+    printTypeInfo(oOleAutoObj, Stdout);
+
+Stdout.formatln("trace {} ", __LINE__);
+// Unhandled Exception: EXCEPTION_PRIV_INSTRUCTION(0xc0000096)
+    oShell.dispose();
+Stdout.formatln("trace {} ", __LINE__);
+    oDisplay.dispose();
+Stdout.formatln("trace {} ", __LINE__);
     return iRes;
 }
 
-private static void printTypeInfo(OleAutomation oOleAutoObj, OutputStream oOut)
+private static void printTypeInfo(OleAutomation oOleAutoObj, Print!(char) oOut)
 {
     dwt.internal.ole.win32.OAIDL.TYPEATTR * pTypeAttr = oOleAutoObj.getTypeInfoAttributes();
-    if (pTypeAttr !is null)
-    {       
-        if (pTypeAttr.cFuncs > 0)
-        {
-            oOut.writefln("Functions :");
-            for (int iIdx = 0; iIdx < pTypeAttr.cFuncs; ++iIdx)
-            {           
+    if (pTypeAttr !is null) {
+        if (pTypeAttr.cFuncs > 0) {
+            oOut.formatln("Functions :");
+            for (int iIdx = 0; iIdx < pTypeAttr.cFuncs; ++iIdx) {
                 OleFunctionDescription oData = oOleAutoObj.getFunctionDescription(iIdx);
-                string sArgList = "";
+                char[] sArgList = "";
                 int iFirstOptionalArgIndex = oData.args.length - oData.optionalArgCount;
-                for (int iArg = 0; iArg < oData.args.length; ++iArg)
-                {
+                for (int iArg = 0; iArg < oData.args.length; ++iArg) {
                     sArgList ~= "[";
-                    if (iArg >= iFirstOptionalArgIndex)
+                    if (iArg >= iFirstOptionalArgIndex){
                         sArgList ~= "optional, ";
+                    }
                     sArgList ~= getDirection(oData.args[iArg].flags) ~ "] " ~
                         getTypeName(oData.args[iArg].type) ~ " " ~
                         oData.args[iArg].name
                         ;
-                    if (iArg < oData.args.length - 1)
+                    if (iArg < oData.args.length - 1){
                         sArgList ~= ", ";
+                    }
                 }
-                oOut.writefln("%s (id = %d (0x%08X))", getInvokeKind(oData.invokeKind), oData.id, oData.id);
-                oOut.writefln("\tSignature  : %s %s(%s)", getTypeName(oData.returnType), oData.name, sArgList);
-                oOut.writefln("\tDescription: %s", oData.documentation);
-                oOut.writefln("\tHelp File  : %s", oData.helpFile);
-                oOut.writefln();
+                oOut.formatln("{} (id = {} (0x{:X8}))", getInvokeKind(oData.invokeKind), oData.id, oData.id);
+                oOut.formatln("\tSignature  : {} {}({})", getTypeName(oData.returnType), oData.name, sArgList);
+                oOut.formatln("\tDescription: {}", oData.documentation);
+                oOut.formatln("\tHelp File  : {}", oData.helpFile);
+                oOut.formatln("");
             }
         }
-        
-        if (pTypeAttr.cVars > 0)
-        {
-            oOut.writefln("\n\nVariables :");
-            for (int iIdx = 0; iIdx < pTypeAttr.cVars; ++iIdx)
-            {
+
+        if (pTypeAttr.cVars > 0) {
+            oOut.formatln("\n\nVariables :");
+            for (int iIdx = 0; iIdx < pTypeAttr.cVars; ++iIdx) {
                 OlePropertyDescription oData = oOleAutoObj.getPropertyDescription(iIdx);
-                oOut.writefln("PROPERTY (id = %d (0x%08X)", oData.id, oData.id);
-                oOut.writefln("\tName : %s", oData.name);
-                oOut.writefln("\tType : %s", getTypeName(oData.type));
-                oOut.writefln();
+                oOut.formatln("PROPERTY (id = {} (0x{:X8})", oData.id, oData.id);
+                oOut.formatln("\tName : {}", oData.name);
+                oOut.formatln("\tType : {}", getTypeName(oData.type));
+                oOut.formatln("");
             }
         }
     }
 }
-private static string getTypeName(int iType)
-{
+private static char[] getTypeName(int iType) {
     int iBase = iType & ~OLE.VT_BYREF;
-    String sDsc = null;
-    switch (iBase)
-    {
+    char[] sDsc = null;
+    switch (iBase) {
         case OLE.VT_BOOL :          sDsc = "boolean"; break;
         case OLE.VT_R4 :            sDsc = "float"; break;
         case OLE.VT_R8 :            sDsc = "double"; break;
@@ -182,56 +140,52 @@
         case OLE.VT_USERDEFINED :   sDsc = "UserDefined"; break;
         case OLE.VT_HRESULT :       sDsc = "HRESULT"; break;
         case OLE.VT_VOID :          sDsc = "void"; break;
-        
         case OLE.VT_UI2 :           sDsc = "unsigned short"; break;
         case OLE.VT_UINT :          sDsc = "unsigned int"; break;
         case OLE.VT_PTR :           sDsc = "void *"; break;
         default: break;
     }
-    if (sDsc !is null)
-    {
-        if ((iType & OLE.VT_BYREF) == OLE.VT_BYREF)
+    if (sDsc !is null) {
+        if ((iType & OLE.VT_BYREF) == OLE.VT_BYREF){
             return sDsc ~ " *";
+        }
         return sDsc;
     }
-    return std.string.format("unknown %d (0x%04X)", iType, iType);
+    return Format("unknown {} (0x{:X4})", iType, iType);
 }
-private static string getDirection(int bDirection)
-{
-    string sDirString = "";
+
+char[] getDirection(int bDirection) {
+    char[] sDirString = "";
     bool bComma = false;
-    if ((bDirection & OLE.IDLFLAG_FIN) != 0)
-    {
+    if ((bDirection & OLE.IDLFLAG_FIN) != 0) {
         sDirString ~= "in";
         bComma = true;
     }
-    if ((bDirection & OLE.IDLFLAG_FOUT) != 0)
-    {
+    if ((bDirection & OLE.IDLFLAG_FOUT) != 0) {
         if (bComma) sDirString ~= ", ";
         sDirString ~= "out";
         bComma = true;
     }
-    if ((bDirection & OLE.IDLFLAG_FLCID) != 0)
-    {
+    if ((bDirection & OLE.IDLFLAG_FLCID) != 0) {
         if (bComma) sDirString ~= ", ";
         sDirString ~= "lcid";
         bComma = true;
     }
-    if ((bDirection & OLE.IDLFLAG_FRETVAL) != 0)
-    {
+    if ((bDirection & OLE.IDLFLAG_FRETVAL) != 0) {
         if (bComma) sDirString ~= ", "; 
         sDirString ~= "retval";
     }
     return sDirString;
 }
-private static string getInvokeKind(int iInvKind) {
-    switch (iInvKind)
-    {
+private static char[] getInvokeKind(int iInvKind) {
+    switch (iInvKind) {
         case OLE.INVOKE_FUNC : return "METHOD";
         case OLE.INVOKE_PROPERTYGET : return "PROPERTY GET";
         case OLE.INVOKE_PROPERTYPUT : return "PROPERTY PUT";
         case OLE.INVOKE_PROPERTYPUTREF : return "PROPERTY PUT BY REF";
         default: break;
     }
-    return std.string.format("unknown %d", iInvKind);
+    return Format("unknown {}", iInvKind);
 }
+
+