61
61
62
62
< h1 > DispHelper</ h1 >
63
63
64
- < p > DispHelper Version 0.80 - June 2004.</ p >
64
+ < p > DispHelper Version 0.81 - July 2004.</ p >
65
65
66
66
< h2 > Introduction</ h2 >
67
67
< p > The aim of the DispHelper library is to allow C/C++ programmers to use COM objects
@@ -132,77 +132,78 @@ <h2>Directory Layout</h2>
132
132
< strong > single_file_source: </ strong > Contains a compacted single file version of the source
133
133
for easy inclusion in your projects.< br />
134
134
< strong > samples_c: </ strong > Contains several DispHelper samples in C.< br />
135
- < strong > samples_cpp: </ strong > Currently empty. Will contain samples optimized for C++.< br />
135
+ < strong > samples_cpp: </ strong > Contains several DispHelper samples in C++.< br />
136
136
< strong > samples_applications: </ strong > Currently empty. Will contain small sample applications that
137
137
make use of DispHelper.</ p >
138
138
139
139
< h2 > Samples</ h2 >
140
- < p > Several samples are available in the < strong > samples_c</ strong > directory. Batch files to compile these
140
+ < p > Several samples are available in the < strong > samples_c</ strong > and < strong > samples_cpp</ strong > directories.
141
+ Batch files to compile these
141
142
samples are provided for Dev-C++, Visual C++ and LCC-WIN32. Drag the sample file you wish to
142
143
compile onto the appropriate batch file. You may have to edit the batch file for your environment.</ p >
143
- < p > While each of these samples will compile as either C or C++, many are not C++ friendly. Included in
144
- a future release will be C++ friendly versions of the samples which will make use of smart pointers,
145
- exceptions and the C++ standard libraries .</ p >
144
+ < p > While each of the samples in samples_c will compile as either C or C++, more C++ friendly versions, which
145
+ make use of smart pointers, C++ exceptions and the C++ standard libraries are
146
+ available in the samples_cpp directory .</ p >
146
147
147
148
< h2 > Sample List</ h2 >
148
149
< table cellspacing ="0 ">
149
150
< tr > < th > File</ th > < th > Description</ th > </ tr >
150
151
151
152
< tr >
152
- < td > word.c </ td >
153
+ < td > word</ td >
153
154
< td > Demonstrates outputting formatted text to a Word document and getting user feed
154
155
back with the help of the office assistant. Demonstrates using Word as a spell
155
156
checker.</ td >
156
157
</ tr >
157
158
158
159
< tr >
159
- < td > excel.c </ td >
160
+ < td > excel</ td >
160
161
< td > Demonstrates outputting formatted data to Excel and using it to create a
161
162
chart. Demonstrates using a safe array to efficiently insert data into Excel.</ td >
162
163
</ tr >
163
164
164
165
< tr >
165
- < td > email.c </ td >
166
+ < td > email</ td >
166
167
< td > Demonstrates sending an email with CDO, Outlook and Eudora.</ td >
167
168
</ tr >
168
169
169
170
< tr >
170
- < td > ado.c </ td >
171
+ < td > ado</ td >
171
172
< td > Demonstrates reading and manipulating data from a data source using ActiveX Data Objects.</ td >
172
173
</ tr >
173
174
174
175
< tr >
175
- < td > corel.c </ td >
176
+ < td > corel</ td >
176
177
< td > Demonstrates outputting formatted text to a WordPerfect document.</ td >
177
178
</ tr >
178
179
179
180
< tr >
180
- < td > speech.c </ td >
181
+ < td > speech</ td >
181
182
< td > Demonstrates using Microsoft Agent and SAPI to provide text-to-speech.</ td >
182
183
</ tr >
183
184
184
185
< tr >
185
- < td > MSHTML.c </ td >
186
+ < td > MSHTML</ td >
186
187
< td > Demonstrates ui-less html parsing and manipulation of the html document object
187
188
model(DOM) using MSHTML.
188
189
Provides functions to parse html from a string, a website or a file.</ td >
189
190
</ tr >
190
191
191
192
< tr >
192
- < td > regexp.c </ td >
193
+ < td > regexp</ td >
193
194
< td > Demonstrates using the VBScript.RegExp object to provide support for regular
194
195
expressions. Provides a function to extract hrefs from a web page using a
195
196
regular expression.</ td >
196
197
</ tr >
197
198
198
199
< tr >
199
- < td > xml.c </ td >
200
+ < td > xml</ td >
200
201
< td > Demonstrates using MSMXL to download a web page, read an RSS feed and read and
201
202
manipulate XML with the XML document object model(DOM).</ td >
202
203
</ tr >
203
204
204
205
< tr >
205
- < td > wmi.c </ td >
206
+ < td > wmi</ td >
206
207
< td > Demonstrates using Windows Management Instrumentation(WMI).
207
208
208
209
Samples include enumerating installed hot fixes, purging print queues, starting
@@ -211,40 +212,40 @@ <h2>Sample List</h2>
211
212
</ tr >
212
213
213
214
< tr >
214
- < td > pocketsoap.c </ td >
215
+ < td > pocketsoap</ td >
215
216
< td > Demonstrates using the PocketSoap toolkit to utilise several web services.
216
217
Play the 'Who wants to be a millionaire' quiz with the help of a web service.</ td >
217
218
</ tr >
218
219
219
220
< tr >
220
- < td > soap.c </ td >
221
+ < td > soap</ td >
221
222
< td > Demonstrates using the MSSoap toolkit to utilise several web services.
222
223
Web services demonstrated include Google search, spell checker and cache viewer.</ td >
223
224
</ tr >
224
225
225
226
< tr >
226
- < td > iexplore.c </ td >
227
+ < td > iexplore</ td >
227
228
< td > Demonstrates controlling Internet Explorer via COM. Demonstrates using an Internet
228
229
Explorer window to display or retrieve information from the user.</ td >
229
230
</ tr >
230
231
231
232
< tr >
232
- < td > scriptctl.c </ td >
233
+ < td > scriptctl</ td >
233
234
< td > Demonstrates using the MSScriptControl to run a VBScript or JScript.</ td >
234
235
</ tr >
235
236
236
237
< tr >
237
- < td > dexplore.c </ td >
238
+ < td > dexplore</ td >
238
239
< td > Demonstrates controlling Microsoft's new help system for developers, dexplore.</ td >
239
240
</ tr >
240
241
241
242
< tr >
242
- < td > dcom_alt_creds.c </ td >
243
+ < td > dcom_alt_creds</ td >
243
244
< td > Demonstrates one way of accessing a remote COM object using alternate credentials.</ td >
244
245
</ tr >
245
246
246
247
< tr >
247
- < td > wia.c </ td >
248
+ < td > wia</ td >
248
249
< td > Demonstrates using Windows Image Acquisition(WIA) to manipulate
249
250
images. Demonstrates taking a snapshot from a video device.</ td >
250
251
</ tr >
@@ -384,6 +385,9 @@ <h3>Initializing DispHelper</h3>
384
385
// Initializes DispHelper only. COM must be initialized seperately
385
386
// using CoInitialize(), CoInitializeEx() or OleInitialize().
386
387
dhInitialize(FALSE);
388
+
389
+ // Using the C++ initialization class
390
+ CDhInitialize init;
387
391
</ pre >
388
392
389
393
< h3 > Declaring a DispHelper COM object</ h3 >
@@ -393,6 +397,9 @@ <h3>Declaring a DispHelper COM object</h3>
393
397
394
398
// Without the macro
395
399
IDispatch * wdDoc = NULL;
400
+
401
+ // Using the C++ smart pointer
402
+ CDispPtr wdDoc;
396
403
</ pre >
397
404
398
405
< h3 > Toggling Exceptions</ h3 >
@@ -526,19 +533,9 @@ <h3>Retrieving the last error text</h3>
526
533
// Dump the details of the last error to a log file
527
534
void LogDhError(void)
528
535
{
529
- PDH_EXCEPTION pException = NULL;
530
- dhGetLastException(&pException);
531
-
532
- if (pException)
533
- {
534
- WCHAR szMessage[512];
535
- dhFormatException(pException, szMessage, 512, TRUE);
536
- fprintf(g_hLogFile, "%S", szMessage);
537
- }
538
- else
539
- {
540
- fprintf(g_hLogFile, "No error information available.");
541
- }
536
+ char szMessage[512];
537
+ dhFormatExceptionA(NULL, szMessage, sizeof(szMessage)/sizeof(szMessage[0]), TRUE);
538
+ fprintf(g_hLogFile, "%s", szMessage);
542
539
}
543
540
544
541
// Sample usage
@@ -549,16 +546,30 @@ <h3>Retrieving the last error text</h3>
549
546
}
550
547
</ pre >
551
548
549
+ < h3 > Throw a C++ exception on error</ h3 >
550
+ < pre >
551
+ // Use the dhCheck macro which will throw a std::string on error
552
+
553
+ try
554
+ {
555
+ dhCheck( dhCallMethod(wdApp, L".Selection.TypeText(%s)", "Hello World") );
556
+ dhCheck( dhPutValue(wdApp, L".Selection.Font.Bold = %b", TRUE) );
557
+ }
558
+ catch (string errstr)
559
+ {
560
+ cerr << "Fatal error details:" << endl << errstr << endl;
561
+ }
562
+ </ pre >
563
+
564
+
552
565
< h3 > Releasing a COM object</ h3 >
553
566
< pre >
554
- // Make use of the SAFE_RELEASE macro
567
+ // Make use of the SAFE_RELEASE macro - do not use with smart pointer
555
568
SAFE_RELEASE(wdApp);
556
569
</ pre >
557
570
558
571
< h2 > Future Directions</ h2 >
559
- < p > In the near future DispHelper will become more C++ friendly, with samples
560
- that use exceptions, smart pointers and the C++ standard libraries.</ p >
561
- < p > DispHelper may also expand to allow easy hosting of ActiveX controls, if demand exists.</ p >
572
+ < p > DispHelper may expand to allow easy hosting of ActiveX controls, if demand exists.</ p >
562
573
563
574
< p style ="text-align:center; "> < a href ="http://sourceforge.net " title ="Go to SourceForge.net - The open source development site ">
564
575
< img src ="http://sourceforge.net/sflogo.php?group_id=111558&type=3 " width ="125 " height ="37 " style ="border:none; " alt ="Go to SourceForge.net - The open source development site " />
0 commit comments