]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.eclipse.swt.win32.win32.x86_64/src/org/eclipse/swt/internal/ole/win32/IDispatch.java
a93811e97dfbf53ffba79ba76774dc5794fc0fe6
[simantics/platform.git] / bundles / org.eclipse.swt.win32.win32.x86_64 / src / org / eclipse / swt / internal / ole / win32 / IDispatch.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2017 IBM Corporation and others.
3  *
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/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.swt.internal.ole.win32;
15
16 import org.eclipse.swt.internal.*;
17 import org.eclipse.swt.internal.win32.*;
18
19 public class IDispatch extends IUnknown {
20
21 public IDispatch(long address) {
22         super(address);
23 }
24 public int GetIDsOfNames(GUID riid, String[] rgszNames, int cNames, int lcid, int[] rgDispId) {
25
26         char[] buffer;
27         int size = rgszNames.length;
28
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];
33
34         try {
35                 // add the address of each string to the array
36
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;
49                 }
50
51                 return COM.VtblCall(5, address, new GUID(), ppNames, cNames, lcid, rgDispId);
52
53         } finally {
54                 // free the memory
55                 for (int i=0; i<memTracker.length; i++){
56                         OS.HeapFree(hHeap, 0, memTracker[i]);
57                 }
58                 OS.HeapFree(hHeap, 0, ppNames);
59         }
60 }
61 public int GetTypeInfo(int iTInfo, int lcid, long[] ppTInfo ){
62         return COM.VtblCall(4, address, iTInfo, lcid, ppTInfo);
63 }
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);
66 }
67 }