1 package org.jinterop.dcom.test; 2 3 import java.net.UnknownHostException ; 4 5 import org.jinterop.dcom.common.JIException; 6 import org.jinterop.dcom.core.IJIComObject; 7 import org.jinterop.dcom.core.JIArray; 8 import org.jinterop.dcom.core.JIComServer; 9 import org.jinterop.dcom.core.JIProgId; 10 import org.jinterop.dcom.core.JISession; 11 import org.jinterop.dcom.core.JIString; 12 import org.jinterop.dcom.win32.ComFactory; 13 import org.jinterop.dcom.win32.ElemDesc; 14 import org.jinterop.dcom.win32.FuncDesc; 15 import org.jinterop.dcom.win32.IJIDispatch; 16 import org.jinterop.dcom.win32.IJITypeInfo; 17 import org.jinterop.dcom.win32.IJITypeLib; 18 import org.jinterop.dcom.win32.IMPLETYPEFLAGS; 19 import org.jinterop.dcom.win32.TYPEKIND; 20 import org.jinterop.dcom.win32.TypeAttr; 21 import org.jinterop.dcom.win32.TypeDesc; 22 import org.jinterop.dcom.win32.VarDesc; 23 24 public class MSTypeLibraryBrowser2 { 25 26 private JIComServer comServer = null; 27 private IJIDispatch dispatch = null; 28 private IJIComObject unknown = null; 29 30 public MSTypeLibraryBrowser2(String address, String args[]) throws JIException, UnknownHostException  31 { 32 JISession session = JISession.createSession(args[1],args[2],args[3]); 33 comServer = new JIComServer(JIProgId.valueOf(session,args[4]),address,session); 34 } 35 36 public void start() throws JIException 37 { 38 unknown = comServer.createInstance(); 39 dispatch = (IJIDispatch)ComFactory.createCOMInstance(ComFactory.IID_IDispatch,unknown); 40 IJITypeLib typeLib = (IJITypeLib)((Object [])dispatch.getTypeInfo(0).getContainingTypeLib())[0]; 41 Object [] result = typeLib.getDocumentation(-1); 42 System.out.println("Name: " + ((JIString)result[0]).getString()); 43 System.out.println("Library Name: " + ((JIString)result[1]).getString()); 44 System.out.println("Full path to help file: " + ((JIString)result[3]).getString()); 45 System.out.println("\n------------------------Library Members---------------------"); 46 int typeInfoCount = typeLib.getTypeInfoCount(); 47 String g_arrClassification[] = { "Enum","Struct","Module","Interface", 48 "Dispinterface","Coclass","Typedef","Union"}; 49 for(int l = 0; l < typeInfoCount;l++) 50 { 51 System.out.println("\n\n-----------------------Member Description--------------------------"); 52 result = typeLib.getDocumentation(l); 53 int k = typeLib.getTypeInfoType(l); 54 55 56 System.out.println("Name: " + ((JIString)result[0]).getString()); 57 System.out.println("Type: " + g_arrClassification[k]); 58 59 60 IJITypeInfo typeInfo = typeLib.getTypeInfo(l); 61 TypeAttr typeAttr = typeInfo.getTypeAttr(); 62 IJITypeInfo ptempInfo = null; 63 TypeAttr pTempAttr = null; 64 if(typeAttr.typekind != TYPEKIND.TKIND_DISPATCH.intValue() && typeAttr.typekind != TYPEKIND.TKIND_COCLASS.intValue()) 65 { 66 int p = 0; 67 p++; 68 } 69 70 if(typeAttr.typekind == TYPEKIND.TKIND_COCLASS.intValue()) 71 { 72 73 for (int i = 0;i<typeAttr.cImplTypes;i++) 74 { 75 int nFlags = -1; 76 try{ 77 nFlags = typeInfo.getImplTypeFlags(i); 78 }catch (JIException e) { 79 continue; 80 } 81 82 if((nFlags & IMPLETYPEFLAGS.IMPLTYPEFLAG_FDEFAULT) == IMPLETYPEFLAGS.IMPLTYPEFLAG_FDEFAULT) 83 { 84 int hRefType = -1; 85 try{ 86 hRefType = typeInfo.getRefTypeOfImplType(i); 87 }catch(JIException e) 88 { 89 break; 90 } 91 92 93 try{ 94 ptempInfo = typeInfo.getRefTypeInfo(hRefType); 95 }catch(JIException e) 96 { 97 break; 98 } 99 100 try{ 101 pTempAttr = ptempInfo.getTypeAttr(); 102 }catch(JIException e) 103 { 104 System.out.println("Failed to get reference type info."); 105 return; 106 } 107 } 108 } 109 110 } 111 112 if (pTempAttr != null) 113 { 114 typeInfo = ptempInfo; 115 typeAttr = pTempAttr; 116 } 117 118 int m_nMethodCount = typeAttr.cFuncs; 119 int m_nVarCount = typeAttr.cVars; 120 int m_nDispInfoCount = m_nMethodCount+2*m_nVarCount; 121 System.out.println("Method and variable count = " + m_nMethodCount + m_nVarCount + "\n\n"); 122 123 124 for(int i = 0;i < m_nMethodCount; i++) 125 { 126 System.out.println("************Method Seperator*****************"); 127 FuncDesc pFuncDesc ; 128 129 try{ 130 pFuncDesc = typeInfo.getFuncDesc(i); 131 }catch(JIException e) 132 { 133 System.out.println("GetFuncDesc failed."); 134 return; 135 } 136 137 System.out.println(i + ": DispID = " + pFuncDesc.memberId); 138 139 int nCount; 140 try{ 141 Object [] ret = typeInfo.getNames(pFuncDesc.memberId ,1); 142 System.out.println("MethodName = " + ((JIString)((Object [])((JIArray)ret[0]).getArrayInstance())[0]).getString()); 143 nCount = ((Integer )ret[1]).intValue(); 144 }catch(JIException e) 145 { 146 System.out.println("GetNames failed."); 147 return; 148 } 149 150 switch(pFuncDesc.invokeKind) 151 { 152 153 case 2: System.out.println("PropertyGet"); 155 break; 156 case 4: System.out.println("PropertyPut"); 158 break; 159 case 8: System.out.println("PropertyPutRef"); 161 break; 162 case 1: System.out.println("DispatchMethod"); 164 break; 165 default: 166 break; 167 } 168 169 System.out.println("VTable offset: " + pFuncDesc.oVft); 170 System.out.println("Calling convention: " + pFuncDesc.callConv); 171 System.out.println("Return type = " + pFuncDesc.elemdescFunc.typeDesc.vt); 173 System.out.println("ParamCount = " + pFuncDesc.cParams); 174 JIArray array = (JIArray)pFuncDesc.lprgelemdescParam.getReferent(); 175 Object [] types = null; 176 if (array != null) 177 { 178 types = (Object [])array.getArrayInstance(); 179 } 180 181 for(int j = 0;j < pFuncDesc.cParams; j++) 182 { 183 184 if(((ElemDesc)types[j]).typeDesc.vt == TypeDesc.VT_SAFEARRAY.shortValue()) 185 { 186 System.out.println("Param(" + j + ") type = SafeArray" ); 187 } 188 else if(((ElemDesc)types[j]).typeDesc.vt == TypeDesc.VT_PTR.shortValue()) 189 { 190 System.out.println("Param(" + j + ") type = Pointer" ); 191 } 192 else 193 { 194 System.out.println("Param(" + j + ") type = UserDefined" ); 195 } 196 } 197 } 198 199 200 for(int i = m_nMethodCount; i < m_nMethodCount + m_nVarCount; i++) 201 { 202 System.out.println("************Variable Seperator*****************"); 203 VarDesc pVarDesc; 204 try{ 205 pVarDesc = typeInfo.getVarDesc(i - m_nMethodCount); 206 }catch(JIException e) 207 { 208 System.out.println("GetVarDesc failed."); 209 return; 210 } 211 212 System.out.println(i + ": DispID = " + pVarDesc.memberId); 213 214 int nCount; 215 try{ 216 Object [] ret = typeInfo.getNames(pVarDesc.memberId ,1); 217 System.out.println("VarName = " + ((JIString)((Object [])((JIArray)ret[0]).getArrayInstance())[0]).getString()); 218 nCount = ((Integer )ret[1]).intValue(); 219 }catch(JIException e) 220 { 221 System.out.println("GetNames failed."); 222 return; 223 } 224 225 switch(pVarDesc.varkind) 226 { 227 case VarDesc.VAR_DISPATCH: 228 System.out.println("VarKind = VAR_DISPATCH"); 229 System.out.println("VarType = " + pVarDesc.elemdescVar.typeDesc.vt); 230 break; 231 default: 232 System.out.println("VarKind = " + pVarDesc.varkind); 234 break; 235 } 236 } 237 } 238 239 System.out.println("########################Execution complete#########################"); 240 JISession.destroySession(dispatch.getAssociatedSession()); 241 } 242 243 public static void main(String [] args) { 244 try { 245 if (args.length < 5) 246 { 247 System.out.println("Please provide address domain username password progIdOfApplication"); 248 return; 249 } 250 MSTypeLibraryBrowser2 typeLibraryBrowser = new MSTypeLibraryBrowser2(args[0],args); 251 typeLibraryBrowser.start(); 252 } catch (Exception e) { 253 e.printStackTrace(); 255 } 256 257 } 258 259 } 260 | Popular Tags |