Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / April 2004

Tip: Looking for answers? Try searching our database.

CreateInstance(t) when t is interface (for Mattias)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lars Olsson - 31 Mar 2004 16:54 GMT
I'm trying to use the IGroupPolicyObject interface
suggested by Mattias S. :
http://www.dotnet247.com/247reference/msgs/39/197771.aspx

I'm wrapping this interface in another class sort of like this:

namespace MyNamespace
{
      class WrappedIGroupPolicyObjectClass
       {
              IGroupPolicyObject wrappedIGPO;
              ...

               //Constructor
               public WrappedIGroupPolicyObjectClass()
               {
                   //Tried both of these
                   t = Type.GetTypeFromCLSID(new
Guid("EA502723-A23D-11d1-A7D3-0000F87571E3"));
                   t = typeof(MyNamespace.IGroupPolicyObject);

                   wrappedIGPO = (IGroupPolicyObject)
Activator.CreateInstance(t);//Blows up here
                   ...
               }

               ...

               ...
       }

       [ComImport, Guid("EA502723-A23D-11d1-A7D3-0000F87571E3"),
       InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
       interface IGroupPolicyObject
       {
           ...
           all of Mattias's declarations here
       }
}

Note that I have the interface declaration in the same file and resulting
dll.

As I wrote
wrappedIGPO = (IGroupPolicyObject) Activator.CreateInstance(t);
fails. CreateInstance does not like to create an instance when t is refering
to an interface.

I saw this:
http://www.yoda.arachsys.com/csharp/plugin.html
which looks similar to my situation. He suggests to put the interface
declaration
in a separate dll. I'll try that as soon as possible.
Any other suggestions??

TIA
Lars
Lars Olsson - 01 Apr 2004 09:54 GMT
I think I've solved it.
>-----Original Message-----
>I'm trying to use the IGroupPolicyObject interface
[quoted text clipped - 56 lines]
>
>.
Andreas H?kansson - 01 Apr 2004 16:23 GMT
Lars,

   Why not share the solution with the rest of us? Being new to interop at
this level I personally like to read peoples posts and learn from the
answers =)

//Andreas

> I think I've solved it.
> >-----Original Message-----
[quoted text clipped - 65 lines]
> >
> >.
Lars Olsson - 01 Apr 2004 17:26 GMT
Ok, here goes:

It was just plain incompetence. I needed to define a coclass that
pointed to the MS 'Group Policy Object'.
I created an instance of this coclass and casted it to IGroupPolicyObject.
The example that helped me was this msdn example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwl
kCOMInteropPart1CClientTutorial.asp

Scroll down to the 'Example 2: The C# Code Approach' section.
One way to find the guid id:s for the interfaces and classes that one wishes
to define
is to look in the appropriate *.h-files.

> Lars,
>
[quoted text clipped - 73 lines]
> > >
> > >.
Andreas H?kansson - 01 Apr 2004 23:33 GMT
Lars,

   Cheers =)

//Andreas

> Ok, here goes:
>
> It was just plain incompetence. I needed to define a coclass that
> pointed to the MS 'Group Policy Object'.
> I created an instance of this coclass and casted it to IGroupPolicyObject.
> The example that helped me was this msdn example:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwl
kCOMInteropPart1CClientTutorial.asp

> Scroll down to the 'Example 2: The C# Code Approach' section.
> One way to find the guid id:s for the interfaces and classes that one wishes
[quoted text clipped - 79 lines]
> > > >
> > > >.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.