KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.eclipse.swt.internal.win32.*;
14
15 public class IDispatch extends IUnknown
16 {
17 public IDispatch(int /*long*/ address) {
18     super(address);
19 }
20 public int GetIDsOfNames(GUID riid, String JavaDoc[] rgszNames, int cNames, int lcid, int[] rgDispId) {
21
22     char[] buffer;
23     int size = rgszNames.length;
24
25     // create an array to hold the addresses
26
int /*long*/ hHeap = OS.GetProcessHeap();
27     int /*long*/ ppNames = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, size * OS.PTR_SIZEOF);
28     int /*long*/[] memTracker = new int /*long*/[size];
29     
30     try {
31         // add the address of each string to the array
32

33         for (int i=0; i<size; i++){
34             // create a null terminated array of char for each String
35
int nameSize = rgszNames[i].length();
36             buffer = new char[nameSize +1];
37             rgszNames[i].getChars(0, nameSize, buffer, 0);
38             // get the address of the start of the array of char
39
int /*long*/ pName = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, buffer.length * 2);
40             OS.MoveMemory(pName, buffer, buffer.length * 2);
41             // copy the address to the array of addresses
42
COM.MoveMemory(ppNames + OS.PTR_SIZEOF * i, new int /*long*/[]{pName}, OS.PTR_SIZEOF);
43             // keep track of the Global Memory so we can free it
44
memTracker[i] = pName;
45         }
46     
47         return COM.VtblCall(5, address, new GUID(), ppNames, cNames, lcid, rgDispId);
48         
49     } finally {
50         // free the memory
51
for (int i=0; i<memTracker.length; i++){
52             OS.HeapFree(hHeap, 0, memTracker[i]);
53         }
54         OS.HeapFree(hHeap, 0, ppNames);
55     }
56 }
57 public int GetTypeInfo(int iTInfo, int lcid, int /*long*/[] ppTInfo ){
58     return COM.VtblCall(4, address, iTInfo, lcid, ppTInfo);
59 }
60 public int GetTypeInfoCount(int[] pctinfo ){
61     return COM.VtblCall(3, address, pctinfo);
62 }
63 public int Invoke(int dispIdMember, GUID riid, int lcid, int dwFlags, DISPPARAMS pDispParams, int /*long*/ pVarResult, EXCEPINFO pExcepInfo, int[] pArgErr) {
64     return COM.VtblCall(6, address, dispIdMember, riid, lcid, dwFlags, pDispParams, pVarResult, pExcepInfo, pArgErr);
65 }
66 }
67
Popular Tags