1 /*******************************************************************************
2 * Copyright (c) 2000, 2017 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.internal.ole.win32;
16 import org.eclipse.swt.internal.*;
17 import org.eclipse.swt.internal.win32.*;
19 public class IDispatch extends IUnknown {
21 public IDispatch(long address) {
24 public int GetIDsOfNames(GUID riid, String[] rgszNames, int cNames, int lcid, int[] rgDispId) {
27 int size = rgszNames.length;
29 // create an array to hold the addresses
30 long hHeap = OS.GetProcessHeap();
31 long ppNames = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, size * C.PTR_SIZEOF);
32 long[] memTracker = new long[size];
35 // add the address of each string to the array
37 for (int i=0; i<size; i++){
38 // create a null terminated array of char for each String
39 int nameSize = rgszNames[i].length();
40 buffer = new char[nameSize +1];
41 rgszNames[i].getChars(0, nameSize, buffer, 0);
42 // get the address of the start of the array of char
43 long pName = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, buffer.length * 2);
44 OS.MoveMemory(pName, buffer, buffer.length * 2);
45 // copy the address to the array of addresses
46 OS.MoveMemory(ppNames + C.PTR_SIZEOF * i, new long[]{pName}, C.PTR_SIZEOF);
47 // keep track of the Global Memory so we can free it
48 memTracker[i] = pName;
51 return COM.VtblCall(5, address, new GUID(), ppNames, cNames, lcid, rgDispId);
55 for (int i=0; i<memTracker.length; i++){
56 OS.HeapFree(hHeap, 0, memTracker[i]);
58 OS.HeapFree(hHeap, 0, ppNames);
61 public int GetTypeInfo(int iTInfo, int lcid, long[] ppTInfo ){
62 return COM.VtblCall(4, address, iTInfo, lcid, ppTInfo);
64 public int Invoke(int dispIdMember, GUID riid, int lcid, int dwFlags, DISPPARAMS pDispParams, long pVarResult, EXCEPINFO pExcepInfo, int[] pArgErr) {
65 return COM.VtblCall(6, address, dispIdMember, riid, lcid, dwFlags, pDispParams, pVarResult, pExcepInfo, pArgErr);