This repository was archived by the owner on Nov 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitemcollection.cs
executable file
·233 lines (197 loc) · 8.05 KB
/
itemcollection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*---------------------------------------------------------------------
Copyright (C) Microsoft Corporation. All rights reserved.
This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation. See these other
materials for detailed information regarding Microsoft code samples.
THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
-----------------------------------------------------------------------
* File: ItemCollection.class
*
* Purpose: Managed reperesentation of the IPOutlookItemCollection
*
*
* Notes:
*
*/
namespace PocketOutlook
{
using System;
using System.Runtime.InteropServices;
public class ItemCollection
{
private Application m_application;
private IntPtr m_pIPOutlookItemCollection;
private int m_tItemType;
internal ItemCollection(Application application, int tItemType, ref IntPtr pIPOutlookItemCollection)
{
m_pIPOutlookItemCollection = pIPOutlookItemCollection;
m_tItemType = tItemType;
m_application = application;
}
public int Count
{
get
{
int nCount = 0;
PocketOutlook.CheckHRESULT(do_get_Count(m_pIPOutlookItemCollection, ref nCount));
return nCount;
}
}
public bool IncludeRecurrences
{
get
{
int bIncludeRecurrences = 0;
PocketOutlook.CheckHRESULT(do_get_IncludeRecurrences(m_pIPOutlookItemCollection, ref bIncludeRecurrences));
return bIncludeRecurrences == 0 ? false : true;
}
set
{
PocketOutlook.CheckHRESULT(do_put_IncludeRecurrences(m_pIPOutlookItemCollection, value ? 1 : 0));
}
}
public Application Application
{
get
{
return m_application;
}
}
public OutlookItem Add()
{
IntPtr pItem = new IntPtr(0);
int hResult = do_Add(m_pIPOutlookItemCollection, ref pItem);
try
{
PocketOutlook.CheckHRESULT(hResult);
}
catch (Exception)
{
PocketOutlook.ReleaseCOMPtr(pItem);
throw;
}
return this.CreateItem(pItem);
}
public OutlookItem Item(int iIndex)
{
IntPtr pItem = new IntPtr(0);
int hResult = do_Item(m_pIPOutlookItemCollection, iIndex, ref pItem);
try
{
PocketOutlook.CheckHRESULT(hResult);
}
catch (Exception)
{
PocketOutlook.ReleaseCOMPtr(pItem);
throw;
}
return this.CreateItem(pItem);
}
public void Remove(int iIndex)
{
PocketOutlook.CheckHRESULT(do_Remove(m_pIPOutlookItemCollection, iIndex));
}
public void Sort(string zProperty, bool bDescending)
{
PocketOutlook.CheckHRESULT(do_Sort(m_pIPOutlookItemCollection, zProperty, bDescending ? 1 : 0));
}
public OutlookItem Find(string zRestriction)
{
IntPtr pItem = new IntPtr(0);
int hResult = do_Find(m_pIPOutlookItemCollection, zRestriction, ref pItem);
try
{
PocketOutlook.CheckHRESULT(hResult);
}
catch (Exception)
{
PocketOutlook.ReleaseCOMPtr(pItem);
throw;
}
return this.CreateItem(pItem);
}
public OutlookItem FindNext()
{
IntPtr pItem = new IntPtr(0);
int hResult = do_FindNext(m_pIPOutlookItemCollection, ref pItem);
try
{
PocketOutlook.CheckHRESULT(hResult);
}
catch (Exception)
{
PocketOutlook.ReleaseCOMPtr(pItem);
throw;
}
return this.CreateItem(pItem);
}
public ItemCollection Restrict(String zRestriction)
{
IntPtr pItemCollection = new IntPtr(0);
int hResult = do_Restrict(m_pIPOutlookItemCollection, zRestriction,
ref pItemCollection);
try
{
PocketOutlook.CheckHRESULT(hResult);
}
catch
{
PocketOutlook.ReleaseCOMPtr(pItemCollection);
}
return new ItemCollection(m_application, m_tItemType, ref pItemCollection);
}
/*
* A private function for creating an item of the proper type.
*/
private OutlookItem CreateItem(IntPtr pItem)
{
OutlookItem item = null;
OutlookItem.ItemType itemType = (OutlookItem.ItemType) m_tItemType;
switch (itemType)
{
case OutlookItem.ItemType.AppointmentItem:
item = new Appointment(m_application, ref pItem);
break;
case OutlookItem.ItemType.ContactItem:
item = new Contact(m_application, ref pItem);
break;
case OutlookItem.ItemType.TaskItem:
item = new Task(m_application, ref pItem);
break;
case OutlookItem.ItemType.CityItem:
item = new City(m_application, ref pItem);
break;
default:
throw new InvalidProgramException();
}
return item;
} // CreateItem
[ DllImport("PocketOutlook.dll", EntryPoint="IPOutlookItemCollection_get_Count") ]
private static extern int do_get_Count(IntPtr self,
ref int rnCount);
[ DllImport("PocketOutlook.dll", EntryPoint="IPOutlookItemCollection_get_IncludeRecurrences") ]
private static extern int do_get_IncludeRecurrences(IntPtr self,
ref int rbIncludeRecurrences);
[ DllImport("PocketOutlook.dll", EntryPoint="IPOutlookItemCollection_put_IncludeRecurrences") ]
private static extern int do_put_IncludeRecurrences(IntPtr self,
int bIncludeRecurrences);
[ DllImport("PocketOutlook.dll", EntryPoint="IPOutlookItemCollection_Add") ]
private static extern int do_Add(IntPtr self, ref IntPtr rpItem);
[ DllImport("PocketOutlook.dll", EntryPoint="IPOutlookItemCollection_Item") ]
private static extern int do_Item(IntPtr self, int iIndex,
ref IntPtr rpItem);
[ DllImport("PocketOutlook.dll", EntryPoint="IPOutlookItemCollection_Remove") ]
private static extern int do_Remove(IntPtr self, int iIndex);
[ DllImport("PocketOutlook.dll", EntryPoint="IPOutlookItemCollection_Sort") ]
private static extern int do_Sort(IntPtr self, String zProperty, int bDescending);
[ DllImport("PocketOutlook.dll", EntryPoint="IPOutlookItemCollection_Find") ]
private static extern int do_Find(IntPtr self, String zRestriction, ref IntPtr rpItem);
[ DllImport("PocketOutlook.dll", EntryPoint="IPOutlookItemCollection_FindNext") ]
private static extern int do_FindNext(IntPtr self, ref IntPtr rpItem);
[ DllImport("PocketOutlook.dll", EntryPoint="IPOutlookItemCollection_Restrict") ]
private static extern int do_Restrict(IntPtr self, String zRestriction, ref IntPtr rpItemCollection);
}
}