KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > internal > ole > win32 > ITypeInfo


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.swt.internal.ole.win32;
12
13  
14 import org.eclipse.swt.internal.win32.OS;
15
16 public class ITypeInfo extends IUnknown
17 {
18     
19 public ITypeInfo(int /*long*/ address) {
20     super(address);
21 }
22 public int GetDocumentation(int index, String JavaDoc[] name, String JavaDoc[] docString, int[] pdwHelpContext, String JavaDoc[] helpFile ) {
23     int /*long*/[] pBstrName = null;
24     if (name != null) pBstrName = new int /*long*/[1];
25     int /*long*/[] pBstrDocString = null;
26     if (docString != null) pBstrDocString = new int /*long*/[1];
27     int /*long*/[] pBstrHelpFile = null;
28     if (helpFile != null) pBstrHelpFile = new int /*long*/[1];
29     int rc = COM.VtblCall(12, address, index, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
30     if (name != null && pBstrName[0] != 0) {
31         int size = COM.SysStringByteLen(pBstrName[0]);
32         if (size > 0){
33             // get the unicode character array from the global memory and create a String
34
char[] buffer = new char[(size + 1) /2]; // add one to avoid rounding errors
35
COM.MoveMemory(buffer, pBstrName[0], size);
36             name[0] = new String JavaDoc(buffer);
37             int subindex = name[0].indexOf("\0");
38             if (subindex > 0)
39                 name[0] = name[0].substring(0, subindex);
40         }
41         COM.SysFreeString(pBstrName[0]);
42     }
43     if (docString != null && pBstrDocString[0] != 0) {
44         int size = COM.SysStringByteLen(pBstrDocString[0]);
45         if (size > 0){
46             // get the unicode character array from the global memory and create a String
47
char[] buffer = new char[(size + 1) /2]; // add one to avoid rounding errors
48
COM.MoveMemory(buffer, pBstrDocString[0], size);
49             docString[0] = new String JavaDoc(buffer);
50             int subindex = docString[0].indexOf("\0");
51             if (subindex > 0)
52                 docString[0] = docString[0].substring(0, subindex);
53         }
54         COM.SysFreeString(pBstrDocString[0]);
55     }
56     if (helpFile != null && pBstrHelpFile[0] != 0) {
57         int size = COM.SysStringByteLen(pBstrHelpFile[0]);
58         if (size > 0){
59             // get the unicode character array from the global memory and create a String
60
char[] buffer = new char[(size + 1) /2]; // add one to avoid rounding errors
61
COM.MoveMemory(buffer, pBstrHelpFile[0], size);
62             helpFile[0] = new String JavaDoc(buffer);
63             int subindex = helpFile[0].indexOf("\0");
64             if (subindex > 0)
65                 helpFile[0] = helpFile[0].substring(0, subindex);
66         }
67         COM.SysFreeString(pBstrHelpFile[0]);
68     }
69     return rc;
70 }
71 public int GetFuncDesc(int index, int /*long*/[] ppFuncDesc) {
72     return COM.VtblCall(5, address, index, ppFuncDesc);
73 }
74 public int GetIDsOfNames(String JavaDoc[] rgszNames, int cNames, int[] pMemId) {
75
76     char[] buffer;
77     int size = rgszNames.length;
78
79     // create an array to hold the addresses
80
int /*long*/ hHeap = OS.GetProcessHeap();
81     int /*long*/ ppNames = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, size * OS.PTR_SIZEOF);
82     int /*long*/[] memTracker = new int /*long*/[size];
83     
84     try {
85         // add the address of each string to the array
86

87         for (int i=0; i<size; i++){
88             // create a null terminated array of char for each String
89
int nameSize = rgszNames[i].length();
90             buffer = new char[nameSize +1];
91             rgszNames[i].getChars(0, nameSize, buffer, 0);
92             // get the address of the start of the array of char
93
int /*long*/ pName = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, buffer.length * 2);
94             OS.MoveMemory(pName, buffer, buffer.length * 2);
95             // copy the address to the array of addresses
96
COM.MoveMemory(ppNames + OS.PTR_SIZEOF * i, new int /*long*/[]{pName}, OS.PTR_SIZEOF);
97             // keep track of the Global Memory so we can free it
98
memTracker[i] = pName;
99         }
100     
101         return COM.VtblCall(10, address, ppNames, cNames, pMemId);
102         
103     } finally {
104         // free the memory
105
for (int i=0; i<memTracker.length; i++){
106             OS.HeapFree(hHeap, 0, memTracker[i]);
107         }
108         OS.HeapFree(hHeap, 0, ppNames);
109     }
110 }
111
112 public int GetImplTypeFlags(int index, int[] pImplTypeFlags) {
113     return COM.VtblCall(9, address, index, pImplTypeFlags);
114 }
115 public int GetNames(int memid, String JavaDoc[] names, int cMaxNames, int[] pcNames){
116     
117     int nameSize = names.length;
118     int /*long*/[] rgBstrNames = new int /*long*/[nameSize];
119     int rc = COM.VtblCall(7, address, memid, rgBstrNames, nameSize, pcNames);
120     
121     if (rc == COM.S_OK) {
122         for (int i = 0; i < pcNames[0]; i++) {
123             int size = COM.SysStringByteLen(rgBstrNames[i]);
124             if (size > 0){
125                 // get the unicode character array from the global memory and create a String
126
char[] buffer = new char[(size + 1) /2]; // add one to avoid rounding errors
127
COM.MoveMemory(buffer, rgBstrNames[i], size);
128                 names[i] = new String JavaDoc(buffer);
129                 int subindex = names[i].indexOf("\0");
130                 if (subindex > 0)
131                     names[i] = names[i].substring(0, subindex);
132             }
133             COM.SysFreeString(rgBstrNames[i]);
134         }
135     }
136     
137     return rc;
138 }
139 public int GetRefTypeInfo(int hRefType, int /*long*/[] ppTInfo) {
140     return COM.VtblCall(14, address, hRefType, ppTInfo);
141 }
142 public int GetRefTypeOfImplType(int index, int[] pRefType) {
143     return COM.VtblCall(8, address, index, pRefType);
144 }
145 public int GetTypeAttr(int /*long*/[] ppTypeAttr) {
146     return COM.VtblCall(3, address, ppTypeAttr);
147 }
148 public int GetVarDesc(int index, int /*long*/[] ppVarDesc ) {
149     return COM.VtblCall(6, address, index, ppVarDesc);
150 }
151 public int ReleaseFuncDesc(int /*long*/ pFuncDesc ) {
152     return COM.VtblCall(20, address, pFuncDesc);
153 }
154 public int ReleaseTypeAttr(int /*long*/ pTypeAttr) {
155     return COM.VtblCall(19, address, pTypeAttr);
156 }
157 public int ReleaseVarDesc(int /*long*/ pVarDesc ) {
158     return COM.VtblCall(21, address, pVarDesc);
159 }
160 }
161
Popular Tags