0

I am working with a vendor's API. It is supplied as various COM object DLL's. I am trying to gain access to method "CreateDisconnectedADORecordset" contained within the interface IBBUtilityCode.

A code sample from the vendor is as follows:

Dim oReservices As New REServices
Dim oUtilCode As IBBUtilityCode
Dim rs As Recordset
Dim sSQL As String

sSQL = "SELECT * FROM CONSTITUENT_BANK"

oReservices.Init SessionContext
Set oUtilCode = oReservices

Set rs = oUtilCode.CreateDisconnectedADORecordset(sSQL)

They seem to be using the interface "IBBUtilityCode" by first declaring a pointer to one, then casting "oReservices" as a pointer to the interface???

I am not a VB programmer, so I really haven't a clue.

How can this be done with C#? Any help and/or pointers you can give me would be greatly appreciated.

Thanks, Jimmy

2 Answers 2

1

They seem to be using the interface "IBBUtilityCode" by first declaring a pointer to one, then casting "oReservices" as a pointer to the interface???

The concept of a class implementing an interface is not special to COM or Visual Basic, you should be familiar with it in C# as well. Just as in this VB6 code, you don't need a cast to obtain the interface reference. The translation is entirely mechanical:

var oReservices = new REServices();
oReservices.Init(SessionContext);
IBBUtilityCode oUtilCode = oReservices
var sSQL = "SELECT * FROM CONSTITUENT_BANK"
var rs = oUtilCode.CreateDisconnectedADORecordset(sSQL)

No lack of traps with this kind of component, ADO has not aged well. A minor install or configuration problem can turn into a pretty unsolvable headache. Be sure to contact the vendor or author of this component when you have trouble.

Sign up to request clarification or add additional context in comments.

1 Comment

Hans: Your solution is correct and I had tried something like that earlier. What I discovered that prevented me from using it was that I needed to set "Embed Interop Types" in the properties of the DLL to "false". Once I made that change, everything began to work. Thanks for your help.
0

I would suggest using cominvoke. Here is a link from Microsoft explaining it: http://msdn.microsoft.com/en-us/library/aa645736(v=vs.71).aspx

Here is an example of it from that page:

// Create an instance of a COM coclass:
FilgraphManager graphManager = new FilgraphManager();

// See if it supports the IMediaControl COM interface. 
// Note that this will throw a System.InvalidCastException if 
// the cast fails. This is equivalent to QueryInterface for 
// COM objects:
IMediaControl mc = (IMediaControl) graphManager;

// Now you call a method on a COM interface: 
mc.Run();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.