Changeset 153:8907b6374258
- Timestamp:
- 08/21/08 11:49:33 (3 months ago)
- Files:
-
- snippets/ole/Snippet81.d (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
snippets/ole/Snippet81.d
r151 r153 22 22 */ 23 23 24 bug25 {26 pragma(lib, "DD-dwt-dbg.lib");27 }28 else29 {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 51 24 import dwt.DWT; 52 25 import dwt.widgets.Display; … … 62 35 import dwt.ole.win32.OlePropertyDescription; 63 36 64 import std.cstream;65 import std.path;66 import std.stream;37 import tango.io.Stdout; 38 import tango.io.Print; 39 import tango.text.convert.Format; 67 40 68 alias char[] string; 69 70 int main(string[] asArg) 71 { 41 int main() { 72 42 int iRes = 0; 73 43 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); 111 55 } 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 71 Stdout.formatln("trace {} ", __LINE__); 72 // Unhandled Exception: EXCEPTION_PRIV_INSTRUCTION(0xc0000096) 73 oShell.dispose(); 74 Stdout.formatln("trace {} ", __LINE__); 75 oDisplay.dispose(); 76 Stdout.formatln("trace {} ", __LINE__); 113 77 return iRes; 114 78 } 115 79 116 private static void printTypeInfo(OleAutomation oOleAutoObj, OutputStreamoOut)80 private static void printTypeInfo(OleAutomation oOleAutoObj, Print!(char) oOut) 117 81 { 118 82 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) { 126 87 OleFunctionDescription oData = oOleAutoObj.getFunctionDescription(iIdx); 127 stringsArgList = "";88 char[] sArgList = ""; 128 89 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) { 131 91 sArgList ~= "["; 132 if (iArg >= iFirstOptionalArgIndex) 92 if (iArg >= iFirstOptionalArgIndex){ 133 93 sArgList ~= "optional, "; 94 } 134 95 sArgList ~= getDirection(oData.args[iArg].flags) ~ "] " ~ 135 96 getTypeName(oData.args[iArg].type) ~ " " ~ 136 97 oData.args[iArg].name 137 98 ; 138 if (iArg < oData.args.length - 1) 99 if (iArg < oData.args.length - 1){ 139 100 sArgList ~= ", "; 101 } 140 102 } 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(""); 146 108 } 147 109 } 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) { 154 114 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(""); 159 119 } 160 120 } 161 121 } 162 122 } 163 private static string getTypeName(int iType) 164 { 123 private static char[] getTypeName(int iType) { 165 124 int iBase = iType & ~OLE.VT_BYREF; 166 String sDsc = null; 167 switch (iBase) 168 { 125 char[] sDsc = null; 126 switch (iBase) { 169 127 case OLE.VT_BOOL : sDsc = "boolean"; break; 170 128 case OLE.VT_R4 : sDsc = "float"; break; … … 183 141 case OLE.VT_HRESULT : sDsc = "HRESULT"; break; 184 142 case OLE.VT_VOID : sDsc = "void"; break; 185 186 143 case OLE.VT_UI2 : sDsc = "unsigned short"; break; 187 144 case OLE.VT_UINT : sDsc = "unsigned int"; break; … … 189 146 default: break; 190 147 } 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){ 194 150 return sDsc ~ " *"; 151 } 195 152 return sDsc; 196 153 } 197 return std.string.format("unknown %d (0x%04X)", iType, iType);154 return Format("unknown {} (0x{:X4})", iType, iType); 198 155 } 199 private static string getDirection(int bDirection) 200 {201 stringsDirString = "";156 157 char[] getDirection(int bDirection) { 158 char[] sDirString = ""; 202 159 bool bComma = false; 203 if ((bDirection & OLE.IDLFLAG_FIN) != 0) 204 { 160 if ((bDirection & OLE.IDLFLAG_FIN) != 0) { 205 161 sDirString ~= "in"; 206 162 bComma = true; 207 163 } 208 if ((bDirection & OLE.IDLFLAG_FOUT) != 0) 209 { 164 if ((bDirection & OLE.IDLFLAG_FOUT) != 0) { 210 165 if (bComma) sDirString ~= ", "; 211 166 sDirString ~= "out"; 212 167 bComma = true; 213 168 } 214 if ((bDirection & OLE.IDLFLAG_FLCID) != 0) 215 { 169 if ((bDirection & OLE.IDLFLAG_FLCID) != 0) { 216 170 if (bComma) sDirString ~= ", "; 217 171 sDirString ~= "lcid"; 218 172 bComma = true; 219 173 } 220 if ((bDirection & OLE.IDLFLAG_FRETVAL) != 0) 221 { 174 if ((bDirection & OLE.IDLFLAG_FRETVAL) != 0) { 222 175 if (bComma) sDirString ~= ", "; 223 176 sDirString ~= "retval"; … … 225 178 return sDirString; 226 179 } 227 private static string getInvokeKind(int iInvKind) { 228 switch (iInvKind) 229 { 180 private static char[] getInvokeKind(int iInvKind) { 181 switch (iInvKind) { 230 182 case OLE.INVOKE_FUNC : return "METHOD"; 231 183 case OLE.INVOKE_PROPERTYGET : return "PROPERTY GET"; … … 234 186 default: break; 235 187 } 236 return std.string.format("unknown %d", iInvKind);188 return Format("unknown {}", iInvKind); 237 189 } 190 191
