Click here to Skip to main content
15,895,011 members
Home / Discussions / C#
   

C#

 
GeneralRe: SourceSafe and References to COM Objects Pin
Heath Stewart16-Apr-04 4:05
protectorHeath Stewart16-Apr-04 4:05 
Questionowner draw trackbar? Pin
misterbear16-Apr-04 1:10
misterbear16-Apr-04 1:10 
AnswerRe: owner draw trackbar? Pin
Ernst Kuschke16-Apr-04 3:05
Ernst Kuschke16-Apr-04 3:05 
AnswerRe: owner draw trackbar? Pin
Heath Stewart16-Apr-04 4:14
protectorHeath Stewart16-Apr-04 4:14 
GeneralWord Automation Pin
Dominic Godin16-Apr-04 1:06
Dominic Godin16-Apr-04 1:06 
GeneralRe: Word Automation Pin
Ernst Kuschke16-Apr-04 2:59
Ernst Kuschke16-Apr-04 2:59 
GeneralRe: Word Automation Pin
Dominic Godin16-Apr-04 5:31
Dominic Godin16-Apr-04 5:31 
GeneralRe: Word Automation Pin
Heath Stewart16-Apr-04 5:49
protectorHeath Stewart16-Apr-04 5:49 
The thing about OLE automation (and COM in general) is that it works practically the same in whatever language you use as a client (though the syntax may be slightly different).

Unfortunately, ApplicationClass.WordBasic returns an object and because of the Common Type System - a component of the .NET Framework - you can't simply call the method like you could in Delphi or VB (which internally uses the DISPID to invoke the dispatch function with any DISPARAMs you might specify).

There is a way, though, and it's not too easy. You need to declare the IDispatch interface in COM (merging the IUnknown methods in the same interface - do not inherit from a declared IUknown). Then you call IDispatch.GetIDsOfNames to get the DISPID for DisableAutoMacros, and then use that in the call to IDispatch.Invoke.

The last line is easy and there are many eamples here on CodeProject that show examples, though it's pretty easy. The following is, of course, the method signature for Documents.Open:
public Document Open(
  ref object FileName,
  ref object ConfirmConversions,
  ref object ReadOnly,
  ref object AddToRecentFiles,
  ref object PasswordDocument,
  ref object PasswordTemplate,
  ref object Revert,
  ref object WritePasswordDocument,
  ref object WritePasswordTemplate,
  ref object Format,
  ref object Encoding,
  ref object Visible,
  ref object OpenAndRepair,
  ref object DocumentDirection,
  ref object NoEncodingDialog);
So, if you wanted to open a document and don't want/need to provide all those parameters, you can simply using Missing.Value (or null):
object fileName = "C:\Example.doc";
object missing = Missing.Value;
Document doc = app.Documents.Open(ref fileName, ref missing, ref missing,
  ref missing, ref missing, ref missing, ref missing, ref missing,
  ref missing, ref missing, ref missing, ref missing, ref missing,
  ref missing, ref missing);
If you wanted to open the document as read-only, add the following line before calling Open and change the third parameter to ref readOnly:
object readOnly = true;


 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Word Automation Pin
Dominic Godin19-Apr-04 22:06
Dominic Godin19-Apr-04 22:06 
GeneralRe: Word Automation Pin
Heath Stewart20-Apr-04 3:52
protectorHeath Stewart20-Apr-04 3:52 
GeneralRe: Word Automation Pin
Dominic Godin20-Apr-04 6:55
Dominic Godin20-Apr-04 6:55 
GeneralRe: Word Automation Pin
Heath Stewart20-Apr-04 8:31
protectorHeath Stewart20-Apr-04 8:31 
GeneralRe: Word Automation Pin
Dominic Godin21-Apr-04 1:37
Dominic Godin21-Apr-04 1:37 
GeneralRe: Word Automation Pin
Heath Stewart21-Apr-04 3:18
protectorHeath Stewart21-Apr-04 3:18 
GeneralRe: Word Automation Pin
Dominic Godin21-Apr-04 4:14
Dominic Godin21-Apr-04 4:14 
GeneralRe: Word Automation Pin
Heath Stewart21-Apr-04 6:22
protectorHeath Stewart21-Apr-04 6:22 
GeneralRe: Word Automation Pin
Dominic Godin21-Apr-04 7:14
Dominic Godin21-Apr-04 7:14 
GeneralRe: Word Automation Pin
Dominic Godin22-Apr-04 0:54
Dominic Godin22-Apr-04 0:54 
GeneralRe: Word Automation Pin
Heath Stewart22-Apr-04 2:37
protectorHeath Stewart22-Apr-04 2:37 
Questionhow to get a list of computers on Local area network Pin
vutrunghieu16-Apr-04 0:55
vutrunghieu16-Apr-04 0:55 
AnswerRe: how to get a list of computers on Local area network Pin
Heath Stewart16-Apr-04 6:12
protectorHeath Stewart16-Apr-04 6:12 
GeneralRe: how to get a list of computers on Local area network Pin
vutrunghieu18-Apr-04 7:17
vutrunghieu18-Apr-04 7:17 
GeneralRe: how to get a list of computers on Local area network Pin
Heath Stewart19-Apr-04 2:13
protectorHeath Stewart19-Apr-04 2:13 
Generalweek numbers Pin
robmays16-Apr-04 0:02
robmays16-Apr-04 0:02 
GeneralRe: week numbers Pin
Stefan Troschuetz16-Apr-04 0:22
Stefan Troschuetz16-Apr-04 0:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.