Hi Matthew,

It's pretty lame, but I was thinking something like this:

    public class ComWrapper<T> : IDisposable where T: new()
    {
        private T mComObject;

        public ComWrapper()
        {
            mComObject = new T();
        }

        #region IDisposable Members

        public void Dispose()
        {
            Marshal.ReleaseComObject(mComObject);
            mComObject = default(T);
        }

        public T ComObject
        {
            get
            {
                return mComObject;
            }
        }

        #endregion
    }

This could then be used in this kind of manner:

            using(ComWrapper<Word.DocumentClass> doc = new 
ComWrapper<Word.DocumentClass>())
            {
                doc.ComObject.PrintPreview();
            }

You have a little more typing (ie the doc.ComObject) but it's type safe and I 
guess would get the job done. Perhaps there's a better way of doing this....

Cheers,

mal
---- Matthew Wills <[EMAIL PROTECTED]> wrote: 
> 
> 

> 

> 

> 
Mal,
> 

> 
I am not on 2.0 (but we are considering its use for the next release of our
> 
software). How would generics help? Do you have a link to something I can
> 
read about its applicability to my problem?
> 

> 
Thanks
> 
Matthew Wills @ MLC
> 
Senior Analyst Programmer
> 

> 

> 

> 
|---------+---------------------------->
> 
|         |           Malcolm Young    |
> 
|         |           <[EMAIL PROTECTED]|
> 
|         |           .COM>            |
> 
|         |                            |
> 
|---------+---------------------------->
> 
  
>--------------------------------------------------------------------------------------------------------------|
> 
  |                                                                             
                                 |
> 
  |       To:       [email protected]                         
                                 |
> 
  |       cc:                                                                   
                                 |
> 
  |       Subject:  Re: [ADVANCED-DOTNET] RCW generation with automatic 
ReleaseCOMObject                         |
> 
  
>--------------------------------------------------------------------------------------------------------------|
> 

> 

> 

> 

> 
 Hi Matthew,
> 

> 
I assume you're not using 2.0 and can't make use of generics?
> 

> 
Regards,
> 

> 
mal
> 

> 
<snip>
> 

> 

> 

> 
______________________________________________________________________
> 
This email has been scanned by the MessageLabs Email Security System.
> 
For more information please visit http://www.messagelabs.com/email
> 
______________________________________________________________________
> 

> 
===================================
> 
This list is hosted by DevelopMentor  http://www.develop.com
> 

> 
View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to