Changeset 153:8907b6374258

Show
Ignore:
Timestamp:
08/21/08 11:49:33 (3 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Tangofied the OLE snippet 81

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • snippets/ole/Snippet81.d

    r151 r153  
    2222 */ 
    2323 
    24 bug 
    25 { 
    26     pragma(lib, "DD-dwt-dbg.lib"); 
    27 } 
    28 else 
    29 { 
    30     pragma(lib, "DD-dwt.lib"); 
    31 } 
    32 pragma(lib, "advapi32.lib"); 
    33 pragma(lib, "comctl32.lib"); 
    34 pragma(lib, "comdlg32.lib"); 
    35 pragma(lib, "gdi32.lib"); 
    36 pragma(lib, "gdiplus.lib"); 
    37 pragma(lib, "glu32.lib"); 
    38 pragma(lib, "imm32.lib"); 
    39 pragma(lib, "kernel32.lib"); 
    40 pragma(lib, "msimg32.lib"); 
    41 pragma(lib, "ole32.lib"); 
    42 pragma(lib, "oleacc.lib"); 
    43 pragma(lib, "oleaut32.lib"); 
    44 pragma(lib, "olepro32.lib"); 
    45 pragma(lib, "opengl32.lib"); 
    46 pragma(lib, "shlwapi.lib"); 
    47 pragma(lib, "user32.lib"); 
    48 pragma(lib, "usp10.lib"); 
    49 pragma(lib, "uxtheme.lib"); 
    50  
    5124import dwt.DWT; 
    5225import dwt.widgets.Display; 
     
    6235import dwt.ole.win32.OlePropertyDescription; 
    6336 
    64 import std.cstream
    65 import std.path
    66 import std.stream
     37import tango.io.Stdout
     38import tango.io.Print
     39import tango.text.convert.Format
    6740 
    68 alias char[] string; 
    69  
    70 int main(string[] asArg) 
    71 
     41int main() { 
    7242    int iRes = 0; 
    7343 
    74     try 
    75     { 
    76     //  String progID = "Shell.Explorer"; 
    77         String progID = "Excel.Application"; 
    78          
    79         Display oDisplay = new Display(); 
    80         Shell oShell = new Shell(oDisplay); 
    81      
    82         OleFrame frame = new OleFrame(oShell, DWT.NONE); 
    83         OleControlSite oOleSite = null; 
    84         OleAutomation oOleAutoObj = null; 
    85         try 
    86         { 
    87             oOleSite = new OleControlSite(frame, DWT.NONE, progID);  
    88         } catch (Exception oExc) 
    89         { 
    90             dout.writefln("Exception %s creating OleControlSite on type library for %s", oExc.toString(), progID); 
    91             return 1; 
    92         } 
    93         try 
    94         { 
    95             oOleAutoObj = new OleAutomation(oOleSite); 
    96         } catch (Exception oExc) 
    97         { 
    98             dout.writefln("Exception %s  OleAutomation on type library for %s", oExc.toString(), progID); 
    99             return 1; 
    100         } 
    101          
    102         dout.writefln("TypeLibrary for: '%s'", progID); 
    103         printTypeInfo(oOleAutoObj, dout); 
    104          
    105         oShell.dispose(); 
    106         oDisplay.dispose(); 
    107     } catch (Exception oExc) 
    108     { 
    109         dout.writefln("Exception %s in main()", oExc.toString()); 
    110         iRes = 1; 
     44    String progID = "Shell.Explorer"; 
     45    //String progID = "Excel.Application"; 
     46 
     47    Display oDisplay = new Display(); 
     48    Shell oShell = new Shell(oDisplay); 
     49 
     50    OleFrame frame = new OleFrame(oShell, DWT.NONE); 
     51    OleControlSite oOleSite = null; 
     52    OleAutomation oOleAutoObj = null; 
     53    try { 
     54        oOleSite = new OleControlSite(frame, DWT.NONE, progID);  
    11155    } 
    112      
     56    catch (Exception oExc) { 
     57        Stdout.formatln("Exception {} creating OleControlSite on type library for {}", oExc.toString(), progID); 
     58        return 1; 
     59    } 
     60    try { 
     61        oOleAutoObj = new OleAutomation(oOleSite); 
     62    } 
     63    catch (Exception oExc) { 
     64        Stdout.formatln("Exception {}  OleAutomation on type library for {}", oExc.toString(), progID); 
     65        return 1; 
     66    } 
     67 
     68    Stdout.formatln("TypeLibrary for: '{}'", progID); 
     69    printTypeInfo(oOleAutoObj, Stdout); 
     70 
     71Stdout.formatln("trace {} ", __LINE__); 
     72// Unhandled Exception: EXCEPTION_PRIV_INSTRUCTION(0xc0000096) 
     73    oShell.dispose(); 
     74Stdout.formatln("trace {} ", __LINE__); 
     75    oDisplay.dispose(); 
     76Stdout.formatln("trace {} ", __LINE__); 
    11377    return iRes; 
    11478} 
    11579 
    116 private static void printTypeInfo(OleAutomation oOleAutoObj, OutputStream oOut) 
     80private static void printTypeInfo(OleAutomation oOleAutoObj, Print!(char) oOut) 
    11781{ 
    11882    dwt.internal.ole.win32.OAIDL.TYPEATTR * pTypeAttr = oOleAutoObj.getTypeInfoAttributes(); 
    119     if (pTypeAttr !is null) 
    120     {        
    121         if (pTypeAttr.cFuncs > 0) 
    122         { 
    123             oOut.writefln("Functions :"); 
    124             for (int iIdx = 0; iIdx < pTypeAttr.cFuncs; ++iIdx) 
    125             {            
     83    if (pTypeAttr !is null) { 
     84        if (pTypeAttr.cFuncs > 0) { 
     85            oOut.formatln("Functions :"); 
     86            for (int iIdx = 0; iIdx < pTypeAttr.cFuncs; ++iIdx) { 
    12687                OleFunctionDescription oData = oOleAutoObj.getFunctionDescription(iIdx); 
    127                 string sArgList = ""; 
     88                char[] sArgList = ""; 
    12889                int iFirstOptionalArgIndex = oData.args.length - oData.optionalArgCount; 
    129                 for (int iArg = 0; iArg < oData.args.length; ++iArg) 
    130                 { 
     90                for (int iArg = 0; iArg < oData.args.length; ++iArg) { 
    13191                    sArgList ~= "["; 
    132                     if (iArg >= iFirstOptionalArgIndex) 
     92                    if (iArg >= iFirstOptionalArgIndex){ 
    13393                        sArgList ~= "optional, "; 
     94                    } 
    13495                    sArgList ~= getDirection(oData.args[iArg].flags) ~ "] " ~ 
    13596                        getTypeName(oData.args[iArg].type) ~ " " ~ 
    13697                        oData.args[iArg].name 
    13798                        ; 
    138                     if (iArg < oData.args.length - 1) 
     99                    if (iArg < oData.args.length - 1){ 
    139100                        sArgList ~= ", "; 
     101                    } 
    140102                } 
    141                 oOut.writefln("%s (id = %d (0x%08X))", getInvokeKind(oData.invokeKind), oData.id, oData.id); 
    142                 oOut.writefln("\tSignature  : %s %s(%s)", getTypeName(oData.returnType), oData.name, sArgList); 
    143                 oOut.writefln("\tDescription: %s", oData.documentation); 
    144                 oOut.writefln("\tHelp File  : %s", oData.helpFile); 
    145                 oOut.writefln(); 
     103                oOut.formatln("{} (id = {} (0x{:X8}))", getInvokeKind(oData.invokeKind), oData.id, oData.id); 
     104                oOut.formatln("\tSignature  : {} {}({})", getTypeName(oData.returnType), oData.name, sArgList); 
     105                oOut.formatln("\tDescription: {}", oData.documentation); 
     106                oOut.formatln("\tHelp File  : {}", oData.helpFile); 
     107                oOut.formatln(""); 
    146108            } 
    147109        } 
    148          
    149         if (pTypeAttr.cVars > 0) 
    150         { 
    151             oOut.writefln("\n\nVariables :"); 
    152             for (int iIdx = 0; iIdx < pTypeAttr.cVars; ++iIdx) 
    153             { 
     110 
     111        if (pTypeAttr.cVars > 0) { 
     112            oOut.formatln("\n\nVariables :"); 
     113            for (int iIdx = 0; iIdx < pTypeAttr.cVars; ++iIdx) { 
    154114                OlePropertyDescription oData = oOleAutoObj.getPropertyDescription(iIdx); 
    155                 oOut.writefln("PROPERTY (id = %d (0x%08X)", oData.id, oData.id); 
    156                 oOut.writefln("\tName : %s", oData.name); 
    157                 oOut.writefln("\tType : %s", getTypeName(oData.type)); 
    158                 oOut.writefln(); 
     115                oOut.formatln("PROPERTY (id = {} (0x{:X8})", oData.id, oData.id); 
     116                oOut.formatln("\tName : {}", oData.name); 
     117                oOut.formatln("\tType : {}", getTypeName(oData.type)); 
     118                oOut.formatln(""); 
    159119            } 
    160120        } 
    161121    } 
    162122} 
    163 private static string getTypeName(int iType) 
    164 
     123private static char[] getTypeName(int iType) { 
    165124    int iBase = iType & ~OLE.VT_BYREF; 
    166     String sDsc = null; 
    167     switch (iBase) 
    168     { 
     125    char[] sDsc = null; 
     126    switch (iBase) { 
    169127        case OLE.VT_BOOL :          sDsc = "boolean"; break; 
    170128        case OLE.VT_R4 :            sDsc = "float"; break; 
     
    183141        case OLE.VT_HRESULT :       sDsc = "HRESULT"; break; 
    184142        case OLE.VT_VOID :          sDsc = "void"; break; 
    185          
    186143        case OLE.VT_UI2 :           sDsc = "unsigned short"; break; 
    187144        case OLE.VT_UINT :          sDsc = "unsigned int"; break; 
     
    189146        default: break; 
    190147    } 
    191     if (sDsc !is null) 
    192     { 
    193         if ((iType & OLE.VT_BYREF) == OLE.VT_BYREF) 
     148    if (sDsc !is null) { 
     149        if ((iType & OLE.VT_BYREF) == OLE.VT_BYREF){ 
    194150            return sDsc ~ " *"; 
     151        } 
    195152        return sDsc; 
    196153    } 
    197     return std.string.format("unknown %d (0x%04X)", iType, iType); 
     154    return Format("unknown {} (0x{:X4})", iType, iType); 
    198155} 
    199 private static string getDirection(int bDirection) 
    200 
    201     string sDirString = ""; 
     156 
     157char[] getDirection(int bDirection)
     158    char[] sDirString = ""; 
    202159    bool bComma = false; 
    203     if ((bDirection & OLE.IDLFLAG_FIN) != 0) 
    204     { 
     160    if ((bDirection & OLE.IDLFLAG_FIN) != 0) { 
    205161        sDirString ~= "in"; 
    206162        bComma = true; 
    207163    } 
    208     if ((bDirection & OLE.IDLFLAG_FOUT) != 0) 
    209     { 
     164    if ((bDirection & OLE.IDLFLAG_FOUT) != 0) { 
    210165        if (bComma) sDirString ~= ", "; 
    211166        sDirString ~= "out"; 
    212167        bComma = true; 
    213168    } 
    214     if ((bDirection & OLE.IDLFLAG_FLCID) != 0) 
    215     { 
     169    if ((bDirection & OLE.IDLFLAG_FLCID) != 0) { 
    216170        if (bComma) sDirString ~= ", "; 
    217171        sDirString ~= "lcid"; 
    218172        bComma = true; 
    219173    } 
    220     if ((bDirection & OLE.IDLFLAG_FRETVAL) != 0) 
    221     { 
     174    if ((bDirection & OLE.IDLFLAG_FRETVAL) != 0) { 
    222175        if (bComma) sDirString ~= ", ";  
    223176        sDirString ~= "retval"; 
     
    225178    return sDirString; 
    226179} 
    227 private static string getInvokeKind(int iInvKind) { 
    228     switch (iInvKind) 
    229     { 
     180private static char[] getInvokeKind(int iInvKind) { 
     181    switch (iInvKind) { 
    230182        case OLE.INVOKE_FUNC : return "METHOD"; 
    231183        case OLE.INVOKE_PROPERTYGET : return "PROPERTY GET"; 
     
    234186        default: break; 
    235187    } 
    236     return std.string.format("unknown %d", iInvKind); 
     188    return Format("unknown {}", iInvKind); 
    237189} 
     190 
     191