1 | /* |
2 | * $Id: IDispatch.java,v 1.17 2006/03/04 06:04:15 hastings Exp $ |
3 | * |
4 | * Copyright (c) 2004, Moebius Solutions, Inc. |
5 | * All rights reserved. |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions |
9 | * are met: |
10 | * |
11 | * Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. |
13 | * |
14 | * Redistributions in binary form must reproduce the above |
15 | * copyright notice, this list of conditions and the following |
16 | * disclaimer in the documentation and/or other materials provided |
17 | * with the distribution. |
18 | * |
19 | * Neither the name of Moebius Solutions, Inc. nor the names of |
20 | * its contributors may be used to endorse or promote products |
21 | * derived from this software without specific prior written |
22 | * permission. |
23 | * |
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
30 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
33 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
35 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
36 | */ |
37 | |
38 | package com.moesol.bindings.platform_sdk.component_services; |
39 | |
40 | import com.moesol.bindings.NativeStructure; |
41 | |
42 | /** See IDispatch in MSDN */ |
43 | public interface IDispatch extends IUnknown { |
44 | public static final Class TYPELIB = TYPELIB_00020430_0000_0000_C000_000000000046.class; |
45 | /** IID for IDispatch {00020400-0000-0000-C000-000000000046} */ |
46 | public static final com.moesol.bindings.platform_sdk.component_services.GUID IID = new com.moesol.bindings.platform_sdk.component_services.GUID( |
47 | 0x00020400, (short) 0x0000, (short) 0x0000, new byte[]{ |
48 | (byte) 0xC0, (byte) 0x00, (byte) 0x00, (byte) 0x00, |
49 | (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x46}); |
50 | |
51 | /** Java to COM implementation. */ |
52 | public static class Jni extends IUnknown.Jni implements IDispatch { |
53 | /** |
54 | * Help prevent method/property name collisions. |
55 | */ |
56 | protected static class MoeSolInternal extends IUnknown.Jni.MoeSolInternal { |
57 | /** |
58 | * Help convert out VARIANTs into the expected Java interface wrapper. |
59 | * |
60 | * @param iface_class |
61 | * class of QI |
62 | * @param iface |
63 | * interface to QI and Release. |
64 | * @return interface castable to iface_class. |
65 | */ |
66 | public static IUnknown queryInterfaceAndRelease(Class iface_class, Object iface) { |
67 | if (iface == null) { |
68 | return null; |
69 | } |
70 | |
71 | IUnknown unk = (IUnknown)iface; |
72 | try { |
73 | return unk.QueryInterface(iface_class); |
74 | } finally { |
75 | unk.Release(); |
76 | } |
77 | } |
78 | /** |
79 | * Help convert out VARIANTs into the expected Java structure wrapper. |
80 | */ |
81 | public static NativeStructure recoverRecord(Class ns_class, Object obj) { |
82 | if (obj == null) { |
83 | return null; |
84 | } |
85 | |
86 | NativeStructure ns = (NativeStructure)obj; |
87 | try { |
88 | NativeStructure dst = (NativeStructure)ns_class.newInstance(); |
89 | dst.getByteBuffer().put(ns.getByteBuffer()); |
90 | return dst; |
91 | } catch (InstantiationException e) { |
92 | throw new RuntimeException(e); |
93 | } catch (IllegalAccessException e) { |
94 | throw new RuntimeException(e); |
95 | } |
96 | } |
97 | } |
98 | |
99 | /** protect constructor */ |
100 | protected Jni() { |
101 | // Empty |
102 | } |
103 | |
104 | /** |
105 | * Call native IDipatch::Invoke. Native exceptions are mapped |
106 | * to Java exceptions. |
107 | * |
108 | * @param dispIdMember |
109 | * @param riid |
110 | * @param lcid |
111 | * @param wFlags |
112 | * @param dispParams |
113 | * @param varResult |
114 | */ |
115 | public void Invoke(int dispIdMember, GUID riid, int lcid, short wFlags, |
116 | Object[] dispParams, Object[] varResult) { |
117 | String[] errDescription = { null }; |
118 | int hr; |
119 | hr = jni_Invoke(dispIdMember, riid, lcid, wFlags, dispParams, varResult, errDescription); |
120 | HRESULT.throwOnFailed(hr, errDescription[0]); |
121 | } |
122 | |
123 | private native int jni_Invoke(int dispIdMember, GUID riid, int lcid, short wFlags, |
124 | Object[] dispParams, Object[] varResult, String[] errDescription); |
125 | } |
126 | |
127 | /** COM to Java implementation. */ |
128 | public static class Disp extends IUnknown.Disp { |
129 | private static Disp s_instance = new Disp(); |
130 | public static IUnknown.Disp instance() { |
131 | return s_instance; |
132 | } |
133 | |
134 | protected Disp() { |
135 | addEntry(Integer.MIN_VALUE, (short)0, "_thunk_IDispatch_GetTypeInfo@16", "com_moesol_bindings.dll"); |
136 | addEntry(Integer.MIN_VALUE, (short)0, "_thunk_IDispatch_GetTypeInfoCount@8", "com_moesol_bindings.dll"); |
137 | addEntry(Integer.MIN_VALUE, (short)0, "_thunk_IDispatch_GetIDsOfNames@24", "com_moesol_bindings.dll"); |
138 | addEntry(Integer.MIN_VALUE, (short)0, "_thunk_IDispatch_Invoke@36", "com_moesol_bindings.dll"); |
139 | } |
140 | } |
141 | |
142 | /** See MSDN */ |
143 | public static final short DISPATCH_METHOD = (short)0x1; |
144 | /** See MSDN */ |
145 | public static final short DISPATCH_PROPERTYGET = (short)0x2; |
146 | /** See MSDN */ |
147 | public static final short DISPATCH_PROPERTYPUT = (short)0x4; |
148 | /** See MSDN */ |
149 | public static final short DISPATCH_PROPERTYPUTREF = (short)0x8; |
150 | } |