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 / September 2005

Tip: Looking for answers? Try searching our database.

Simply Call a method from a OCX?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
News-mail.SW@gmx.net - 12 Sep 2005 15:34 GMT
Hello alltogether.
I hope anyone of you can help me.
I have a OCX-file (arsole.ocx) which contains one class. I need to call
some methods of this class. They have BSTR parameters and return SHORTs
(The return codes are not required to catch).

When I am trying to include the OCX through the automatic generated
wrapper (Interop.ARSOLELib) then all calls fail ("catastrophic
failure")...

I do not need a instance of the class itself. I just need to call some
simple methods.

Thanks in advance.
Robert Jordan - 12 Sep 2005 16:11 GMT
Hi!

> I have a OCX-file (arsole.ocx) which contains one class. I need to call
> some methods of this class. They have BSTR parameters and return SHORTs
[quoted text clipped - 6 lines]
> I do not need a instance of the class itself. I just need to call some
> simple methods.

You definitely need an instance.

Rob
News-mail.SW@gmx.net - 13 Sep 2005 08:31 GMT
Hi Robert.

How can I easily get an instance to call those methods. Is there any
way to instance a OCX classwithout using a wrapper?
In old VB you could create an object through late binding. Isnt it
possible to do this in .NET?

Are there any tutorials on that matter?

Thanks in advance.
Sebastian
Robert Jordan - 13 Sep 2005 10:22 GMT
> Hi Robert.
>
> How can I easily get an instance to call those methods. Is there any
> way to instance a OCX classwithout using a wrapper?
> In old VB you could create an object through late binding. Isnt it
> possible to do this in .NET?

You can use reflection:

object comObject = Activator.CreateInstance (
  Type.GetTypeFromProgID("ProgId"));

object result = comObject.GetType().InvokeMember (
  "MethodName",
  BindingFlags.InvokeMethod,
  null,
  comObject,
  new object[] {arg1, arg2 , ...}
  );

Rob
News-mail.SW@gmx.net - 13 Sep 2005 12:04 GMT
Hi Robert.
Thanks for the answer. It worked so far that I can get a instance of my
class (I used the GetTypeFromCLSID function).

But my problem is that I cannot invoke any methods. When I am listing
all methods of the type (using type.GetMethods) it seems that the
object is represented as a MarshalByRefObject class.
The List of available methods consists of:
- CreateObjRef
- GetLifetimeService
- InitializeLifetimeService

What shall I do to get a real method of the class invoked?

Tanks in advance
Sebastian
Robert Jordan - 13 Sep 2005 12:12 GMT
Hi!

> Thanks for the answer. It worked so far that I can get a instance of my
> class (I used the GetTypeFromCLSID function).
[quoted text clipped - 8 lines]
>
> What shall I do to get a real method of the class invoked?

Please post some parts of the IDL of the OCX, especially
the coclass and its interfaces.

Rob
Sebastian W - 13 Sep 2005 12:29 GMT
Where do I get the IDL from?
ILDASM of the Interop-class?

Sebastian
Robert Jordan - 13 Sep 2005 12:36 GMT
> Where do I get the IDL from?
> ILDASM of the Interop-class?
>
> Sebastian

OleView on the ocx.

Rob
Sebastian W - 13 Sep 2005 13:35 GMT
library ARSOLELib
{
   // TLib :     // TLib : OLE Automation :
{00020430-0000-0000-C000-000000000046}
   importlib("stdole2.tlb");

   // Forward declare all types defined in this typelib
   dispinterface _DArsOle;
   dispinterface _DArsOleEvents;

   [
     uuid(B374D541-4DA7-11D0-B540-0004AC94759C),
     version(1.0),
     helpstring("Dispatch interface for OnDemand Control"),
     hidden
   ]
   dispinterface _DArsOle {
       properties:
       methods:
           [id(0x00000001)]
           short GetControlId(VARIANT* pControlId);
           [id(0x00000002)]
           short GetNumServers(VARIANT* pNumServers);
           [id(0x00000003)]
           short GetServerNames(
                           IUnknown* pNames,
                           short MaxNames);
           [id(0x00000004)]
           short Logon(
                           BSTR pServer,
                           BSTR pUserId,
                           BSTR pPassword);
...
           [id(0xfffffdd8)]
           void AboutBox();
   };

   [
     uuid(B374D542-4DA7-11D0-B540-0004AC94759C),
     version(1.0),
     helpstring("Event interface for OnDemand Control")
   ]
   dispinterface _DArsOleEvents {
       properties:
       methods:
...
    };
  [
     uuid(B374D543-4DA7-11D0-B540-0004AC94759C),
     version(1.0),
     helpstring("OnDemand Control"),
     control
   ]
   coclass ArsOle {
       [default] dispinterface _DArsOle;
       [default, source] dispinterface _DArsOleEvents;
   };
};

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.