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 / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

ActiveX and Late binding in C++/CLI

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
none - 31 May 2005 21:39 GMT
Hello All

My app requires runtime creation of an ActiveX control on demand. I
attempted to fullfil this requirment with the following code snippet:

.
.
.
System::Type ^t =
System::Type::GetTypeFromProgID("CONTINUUMX.TRecordSetCtrl.1");

AxCONTINUUMXLib::AxTRecordSet ^rs =
(AxCONTINUUMXLib::AxTRecordSet^)System::Activator::CreateInstance(t);

rs->DataChange += gcnew
AxCONTINUUMXLib::_DTRecordSetEvents_DataChangeEventHandler(this,&Form1::OnDataChange);

rs->Open(textBox1->Text + "," + "Daily");
rs->Init(100, 0);
rs->GetRecDouble(0,0, val);

Unfortunately the above results in the following runtime error:

Unable to cast COM object of type 'AxCONTINUUMXLib.AxTRecordSet' to
class type ''. Instances of types that represent COM components cannot
be cast to types that do not represent COM components; however they can
be cast to interfaces as long as the underlying COM component supports
QueryInterface calls for the IID of the interface.

Is reflection and the use of System::Type::GetMethod the only (and
tedious) way of doing this?

Any hint or help is greatly appreciated.

Regards
Willy Denoyette [MVP] - 31 May 2005 23:59 GMT
> Hello All
>
[quoted text clipped - 27 lines]
> Is reflection and the use of System::Type::GetMethod the only (and
> tedious) way of doing this?

Yes, reflection only. If you want late binding support for COM at the
language level you should use VB.NET, C++/CLI and C# aren't well suited for
this.

Willy.
None - 01 Jun 2005 00:43 GMT
> Yes, reflection only. If you want late binding support for COM at the
> language level you should use VB.NET, C++/CLI and C# aren't well
> suited for this.
>
> Willy.

Thank you, Willy. I appreciate your expedient response.

Regards
Marcus Heege - 02 Jun 2005 21:47 GMT
> System::Type ^t =
> System::Type::GetTypeFromProgID("CONTINUUMX.TRecordSetCtrl.1");
>
> AxCONTINUUMXLib::AxTRecordSet ^rs =
> (AxCONTINUUMXLib::AxTRecordSet^)System::Activator::CreateInstance(t);

What you get from Activator create instance is a Runtime Callable Wrapper
(RCW). If you cast an RCW to a .NET interface with the Guid attribute, it
calls QueryInterface under the hood.

Often, the easiest way to get an interface with the correct attribute
settings etc., is the TLBIMP.EXE tool.

Marcus Heege

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.