001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.swt.internal.ole.win32;
011:
012: import org.eclipse.swt.internal.win32.OS;
013:
014: public class ITypeInfo extends IUnknown {
015:
016: public ITypeInfo(int /*long*/address) {
017: super (address);
018: }
019:
020: public int GetDocumentation(int index, String[] name,
021: String[] docString, int[] pdwHelpContext, String[] helpFile) {
022: int /*long*/[] pBstrName = null;
023: if (name != null)
024: pBstrName = new int /*long*/[1];
025: int /*long*/[] pBstrDocString = null;
026: if (docString != null)
027: pBstrDocString = new int /*long*/[1];
028: int /*long*/[] pBstrHelpFile = null;
029: if (helpFile != null)
030: pBstrHelpFile = new int /*long*/[1];
031: int rc = COM.VtblCall(12, address, index, pBstrName,
032: pBstrDocString, pdwHelpContext, pBstrHelpFile);
033: if (name != null && pBstrName[0] != 0) {
034: int size = COM.SysStringByteLen(pBstrName[0]);
035: if (size > 0) {
036: // get the unicode character array from the global memory and create a String
037: char[] buffer = new char[(size + 1) / 2]; // add one to avoid rounding errors
038: COM.MoveMemory(buffer, pBstrName[0], size);
039: name[0] = new String(buffer);
040: int subindex = name[0].indexOf("\0");
041: if (subindex > 0)
042: name[0] = name[0].substring(0, subindex);
043: }
044: COM.SysFreeString(pBstrName[0]);
045: }
046: if (docString != null && pBstrDocString[0] != 0) {
047: int size = COM.SysStringByteLen(pBstrDocString[0]);
048: if (size > 0) {
049: // get the unicode character array from the global memory and create a String
050: char[] buffer = new char[(size + 1) / 2]; // add one to avoid rounding errors
051: COM.MoveMemory(buffer, pBstrDocString[0], size);
052: docString[0] = new String(buffer);
053: int subindex = docString[0].indexOf("\0");
054: if (subindex > 0)
055: docString[0] = docString[0].substring(0, subindex);
056: }
057: COM.SysFreeString(pBstrDocString[0]);
058: }
059: if (helpFile != null && pBstrHelpFile[0] != 0) {
060: int size = COM.SysStringByteLen(pBstrHelpFile[0]);
061: if (size > 0) {
062: // get the unicode character array from the global memory and create a String
063: char[] buffer = new char[(size + 1) / 2]; // add one to avoid rounding errors
064: COM.MoveMemory(buffer, pBstrHelpFile[0], size);
065: helpFile[0] = new String(buffer);
066: int subindex = helpFile[0].indexOf("\0");
067: if (subindex > 0)
068: helpFile[0] = helpFile[0].substring(0, subindex);
069: }
070: COM.SysFreeString(pBstrHelpFile[0]);
071: }
072: return rc;
073: }
074:
075: public int GetFuncDesc(int index, int /*long*/[] ppFuncDesc) {
076: return COM.VtblCall(5, address, index, ppFuncDesc);
077: }
078:
079: public int GetIDsOfNames(String[] rgszNames, int cNames,
080: int[] pMemId) {
081:
082: char[] buffer;
083: int size = rgszNames.length;
084:
085: // create an array to hold the addresses
086: int /*long*/hHeap = OS.GetProcessHeap();
087: int /*long*/ppNames = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY,
088: size * OS.PTR_SIZEOF);
089: int /*long*/[] memTracker = new int /*long*/[size];
090:
091: try {
092: // add the address of each string to the array
093:
094: for (int i = 0; i < size; i++) {
095: // create a null terminated array of char for each String
096: int nameSize = rgszNames[i].length();
097: buffer = new char[nameSize + 1];
098: rgszNames[i].getChars(0, nameSize, buffer, 0);
099: // get the address of the start of the array of char
100: int /*long*/pName = OS.HeapAlloc(hHeap,
101: OS.HEAP_ZERO_MEMORY, buffer.length * 2);
102: OS.MoveMemory(pName, buffer, buffer.length * 2);
103: // copy the address to the array of addresses
104: COM.MoveMemory(ppNames + OS.PTR_SIZEOF * i,
105: new int /*long*/[] { pName }, OS.PTR_SIZEOF);
106: // keep track of the Global Memory so we can free it
107: memTracker[i] = pName;
108: }
109:
110: return COM.VtblCall(10, address, ppNames, cNames, pMemId);
111:
112: } finally {
113: // free the memory
114: for (int i = 0; i < memTracker.length; i++) {
115: OS.HeapFree(hHeap, 0, memTracker[i]);
116: }
117: OS.HeapFree(hHeap, 0, ppNames);
118: }
119: }
120:
121: public int GetImplTypeFlags(int index, int[] pImplTypeFlags) {
122: return COM.VtblCall(9, address, index, pImplTypeFlags);
123: }
124:
125: public int GetNames(int memid, String[] names, int cMaxNames,
126: int[] pcNames) {
127:
128: int nameSize = names.length;
129: int /*long*/[] rgBstrNames = new int /*long*/[nameSize];
130: int rc = COM.VtblCall(7, address, memid, rgBstrNames, nameSize,
131: pcNames);
132:
133: if (rc == COM.S_OK) {
134: for (int i = 0; i < pcNames[0]; i++) {
135: int size = COM.SysStringByteLen(rgBstrNames[i]);
136: if (size > 0) {
137: // get the unicode character array from the global memory and create a String
138: char[] buffer = new char[(size + 1) / 2]; // add one to avoid rounding errors
139: COM.MoveMemory(buffer, rgBstrNames[i], size);
140: names[i] = new String(buffer);
141: int subindex = names[i].indexOf("\0");
142: if (subindex > 0)
143: names[i] = names[i].substring(0, subindex);
144: }
145: COM.SysFreeString(rgBstrNames[i]);
146: }
147: }
148:
149: return rc;
150: }
151:
152: public int GetRefTypeInfo(int hRefType, int /*long*/[] ppTInfo) {
153: return COM.VtblCall(14, address, hRefType, ppTInfo);
154: }
155:
156: public int GetRefTypeOfImplType(int index, int[] pRefType) {
157: return COM.VtblCall(8, address, index, pRefType);
158: }
159:
160: public int GetTypeAttr(int /*long*/[] ppTypeAttr) {
161: return COM.VtblCall(3, address, ppTypeAttr);
162: }
163:
164: public int GetVarDesc(int index, int /*long*/[] ppVarDesc) {
165: return COM.VtblCall(6, address, index, ppVarDesc);
166: }
167:
168: public int ReleaseFuncDesc(int /*long*/pFuncDesc) {
169: return COM.VtblCall(20, address, pFuncDesc);
170: }
171:
172: public int ReleaseTypeAttr(int /*long*/pTypeAttr) {
173: return COM.VtblCall(19, address, pTypeAttr);
174: }
175:
176: public int ReleaseVarDesc(int /*long*/pVarDesc) {
177: return COM.VtblCall(21, address, pVarDesc);
178: }
179: }
|