473,320 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ActiveX and Late binding in C++/CLI

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.TRecor dSetCtrl.1");

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

rs->DataChange += gcnew
AxCONTINUUMXLib::_DTRecordSetEvents_DataChangeEven tHandler(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
Nov 17 '05 #1
3 2048

"none" <no**@nowhere.inv> wrote in message
news:RX*******************@fe04.news.easynews.com. ..
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.TRecor dSetCtrl.1");

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

rs->DataChange += gcnew
AxCONTINUUMXLib::_DTRecordSetEvents_DataChangeEven tHandler(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?


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.
Nov 17 '05 #2
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in
news:OO**************@TK2MSFTNGP12.phx.gbl:
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
Nov 17 '05 #3
> System::Type ^t =
System::Type::GetTypeFromProgID("CONTINUUMX.TRecor dSetCtrl.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
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gary | last post by:
sorry for not cross-posting originally (originally posted in the components subgroup) I seem to have run into two documented bugs whose workarounds are incompatible. What I have is an OCX...
2
by: Blake | last post by:
I'm using late binding to create Outlook email from an Access2K database. I am not referencing the Microsoft Office 9.0 Object Library nor the Microsoft Outlook 9.0 Object Library. Instead, I have...
1
by: Blake | last post by:
I'm using late binding to create Outlook email from an Access2K database. I am not referencing the Microsoft Office 9.0 Object Library nor the Microsoft Outlook 9.0 Object Library. Instead, I have...
9
by: Zlatko Matiæ | last post by:
I was reading about late binding, but I'm not completely sure what is to be done in order to adjust code to late binding... For example, I'm not sure if this is correct: early binding: Dim ws...
0
by: JL_327 | last post by:
No one on any of the other boards seem to know In VB.Net this late binding works fine Dim Version As Integer Dim Revision As Integer Dim Wnum As Integer Dim o As System.Array =...
1
by: Rocio | last post by:
I have a windows app. written in VB6, now we need to expose some of its classes through a web service. I am only able to expose the classes using late binding becasue that's the way the original...
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
2
by: jdanoz | last post by:
Hello, i have a vb.net project with a reference to an ActiveX object (ocx). If i try to use the ocx from vb6 project (adding the reference) it works ok (using CreateObject). In vb.net, the...
5
by: Michael Maes | last post by:
Hi, We have an ERP-Application that needs to interact with an "external accountancy program". This is acchieved through a "Connector" (ActiveX-dll) so kindly provided by the Accountancy-Program....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.