LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing COM(Component Object Model) components having custom interface from a CVI project

I have some COM(Component Object Model) components using custom interface
i.e they have been derived from IUnknown and not IDispatch. These have been
created using VC++.
I want to use these components in my LabWindows project. The ActiveX Automation
Controller Wizard allows only the Automation objects to be created. If we
try creating a custom interface component it gives error "Server contains
no objects (dispatch interfaces). Check type library."
I want to do a CoCreateInstance of my component and call the methods in it
using the interface pointer returned.
Please tell me how I can do this and what are the files I need to include.
0 Kudos
Message 1 of 4
(3,801 Views)
You can call CoCreateInstance in CVI by including the SDK ole2.lib. However, programming custom interfaces in C (instead of C++) can be very difficult, but you can do it in CVI. I would recommend the book Inside OLE 2nd Edition, by Kraig Brockschmidt. It has information on programming custom interfaces from C. Also, attached is a source file that can get you started on the how to communicate with custom interfaces.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 4
(3,801 Views)
Chris,
your comment doesn't address the issue of using COM objects with IUnknowns created with VC++, inside CVI.

Sincerely,
Keita
0 Kudos
Message 3 of 4
(3,801 Views)
The ability to create Automation controllers for interfaces that derive from IUnknown has been added to CVI (I believe in version 6.0).

You must, however, restrict the set of datatypes that you use inside your interfaces. The datatypes must be ActiveX Automation compatible. All of the typical data types are supported, including BSTRs, integers, doubles, and interfaces derived from IUnknown. If your server has additional custom data types such as structs, you can create a wrapper interface that encloses each struct or custom data type in another interface that exposes the members of the structs as Automation compatible types.

To clarify Chris's response, the Brockshmidt book does describe in detail how to call COM interfaces (of all types) from
C code. Also, although it is a little obfuscated, the example code that Chris referenced in his response does show how to call, from CVI, COM objects with interfaces derived from IUnknown. There are two key points to note when doing this.

1. You must explicitly dereference the vtbl pointer when you call an interface method.

2. You must pass the interface pointer as the first parameter to each method call (even though this does not show up in the interface definition in C++ or in OleView).

A C++ compiler does these two things for you automatically while a C compiler does not. Following is a line from the code that Chris referenced that shows how to do this.

pMyObjClassFactory->lpVtbl->Release ((IClassFactory *)pMyObjClassFactory);

In this example, pMyObjClassFactory is the interface pointer, pMyObjClassFactory->lpVtbl shows the first point I outlined above, and Release ((IClassFactory *)pMyObjClassFactory) shows the second point I outlined above.

I hope this helps.


David Rohacek
National Instruments
0 Kudos
Message 4 of 4
(3,801 Views)