473,395 Members | 1,571 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,395 software developers and data experts.

Late binding in C+ with COM+

Hi, I have a small problem I solve easily in VB.NET but now I need to
implement it in C#. The problem is:

I have a COM component written in C++ and the methods are like this:

STDMETHOD(get_OpeningBalance)(double *pVal);
In VB.NET I do the following:

MyLoanCalculator = CreateObject("LoanLib.Loan.1")

And then I use MyLoanCalculator normally and since VB allows latebinding I
can access all methods and properties easily. However when I use C# I use
Activator.CreateInstance but then I haven't been able to invoke properties
or methods that receive parameters by reference.

An important detail is that the COM library needs to be registered as a
server application in COM+.

Any ideas?
Nov 16 '05 #1
3 1345
Xavier,

What I would do is I would get the type library that is associated with
the COM+ object, and get the interface defined in .NET. Once you have that,
you can just cast the instance that you create to the interface, and access
it normally (and it's faster as well).

If you can't do that, then you will have to use reflection, as you are
trying to do now.

In order to handle parameters passed by reference in COM, you need to
call the InvokeMember method on the Type, passing in the instance, as well
as a number of other parameters. The one that you have to pay attention to
here is the modifiers parameter. It will be an array of ParameterModifier
structures, which indicate which Parameters (indexed starting from zero)
have reference parameters which need to be marshaled back.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Xavier MT" <xm*****@hotmail.com> wrote in message
news:ut*************@TK2MSFTNGP10.phx.gbl...
Hi, I have a small problem I solve easily in VB.NET but now I need to
implement it in C#. The problem is:

I have a COM component written in C++ and the methods are like this:

STDMETHOD(get_OpeningBalance)(double *pVal);
In VB.NET I do the following:

MyLoanCalculator = CreateObject("LoanLib.Loan.1")

And then I use MyLoanCalculator normally and since VB allows latebinding I
can access all methods and properties easily. However when I use C# I use
Activator.CreateInstance but then I haven't been able to invoke properties
or methods that receive parameters by reference.

An important detail is that the COM library needs to be registered as a
server application in COM+.

Any ideas?

Nov 16 '05 #2
Thanks. I will look how ParameterModifier works since I cannot get the type
library. It has to be totally late bound.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eM**************@TK2MSFTNGP10.phx.gbl...
Xavier,

What I would do is I would get the type library that is associated with the COM+ object, and get the interface defined in .NET. Once you have that, you can just cast the instance that you create to the interface, and access it normally (and it's faster as well).

If you can't do that, then you will have to use reflection, as you are
trying to do now.

In order to handle parameters passed by reference in COM, you need to
call the InvokeMember method on the Type, passing in the instance, as well
as a number of other parameters. The one that you have to pay attention to here is the modifiers parameter. It will be an array of ParameterModifier
structures, which indicate which Parameters (indexed starting from zero)
have reference parameters which need to be marshaled back.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Xavier MT" <xm*****@hotmail.com> wrote in message
news:ut*************@TK2MSFTNGP10.phx.gbl...
Hi, I have a small problem I solve easily in VB.NET but now I need to
implement it in C#. The problem is:

I have a COM component written in C++ and the methods are like this:

STDMETHOD(get_OpeningBalance)(double *pVal);
In VB.NET I do the following:

MyLoanCalculator = CreateObject("LoanLib.Loan.1")

And then I use MyLoanCalculator normally and since VB allows latebinding I can access all methods and properties easily. However when I use C# I use Activator.CreateInstance but then I haven't been able to invoke properties or methods that receive parameters by reference.

An important detail is that the COM library needs to be registered as a
server application in COM+.

Any ideas?


Nov 16 '05 #3
Thanks. I will look how ParameterModifier works since I cannot get the type
library. It has to be totally late bound.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eM**************@TK2MSFTNGP10.phx.gbl...
Xavier,

What I would do is I would get the type library that is associated with the COM+ object, and get the interface defined in .NET. Once you have that, you can just cast the instance that you create to the interface, and access it normally (and it's faster as well).

If you can't do that, then you will have to use reflection, as you are
trying to do now.

In order to handle parameters passed by reference in COM, you need to
call the InvokeMember method on the Type, passing in the instance, as well
as a number of other parameters. The one that you have to pay attention to here is the modifiers parameter. It will be an array of ParameterModifier
structures, which indicate which Parameters (indexed starting from zero)
have reference parameters which need to be marshaled back.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Xavier MT" <xm*****@hotmail.com> wrote in message
news:ut*************@TK2MSFTNGP10.phx.gbl...
Hi, I have a small problem I solve easily in VB.NET but now I need to
implement it in C#. The problem is:

I have a COM component written in C++ and the methods are like this:

STDMETHOD(get_OpeningBalance)(double *pVal);
In VB.NET I do the following:

MyLoanCalculator = CreateObject("LoanLib.Loan.1")

And then I use MyLoanCalculator normally and since VB allows latebinding I can access all methods and properties easily. However when I use C# I use Activator.CreateInstance but then I haven't been able to invoke properties or methods that receive parameters by reference.

An important detail is that the COM library needs to be registered as a
server application in COM+.

Any ideas?


Nov 16 '05 #4

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

Similar topics

21
by: Mike MacSween | last post by:
Had some trouble with Word automation. Sorted it, in the process thought I would try late binding. Some people reccomend it. So this: *********************************************************...
1
by: JD Kronicz | last post by:
Hi .. I have an issue I have been beating my head against the wall on for some time. I am trying to use late binding for MS graph so that my end users don't have to worry about having the right...
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...
5
by: eBob.com | last post by:
In another thread VJ made me aware of Tag. Fantastic! I've been wanting this capability for a long time. But it seems that I cannot use it with Option Strict On. In an event handler I have ......
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...
6
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document...
2
by: GS | last post by:
I have installed the ms PIA for ofc XP, and followed the article http://support.microsoft.com/kb/247412/ trying to paste into a worksheet However I got late binding not allowed errors .......
3
ADezii
by: ADezii | last post by:
The process of verifying that an Object exists and that a specified Property or Method is valid is called Binding. There are two times when this verification process can take place: during compile...
14
by: Siv | last post by:
hi, I am converting an application that writes to an Excel spreadsheet and the code trips the "option Strict" that I would like on because the parser says "option Strict On disallows late...
4
by: =?Utf-8?B?Y2xhcmE=?= | last post by:
Hi all, what is the difference between the late binding and reflection? clara -- thank you so much for your help
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.