PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → Use COM objects
Use COM objects
Iniciado por gezas, 12,feb. 2016 09:36 - 5 respuestas
Miembro registrado
5 mensajes
Publicado el 12,febrero 2016 - 09:36
Hi,

I would need to use COM classes provided by another company. I have seen COMCreateInstance and COMCallMethod but is there another way? I was expecting that I would be able to import the type library of the COM classes and then be able to declare the imported types and work with them directly. But I can not find any relevant information in the manuals.

For example

// Declare a variable (assuming RX is the type library and CutOptimizer is the name of the imported COM class)
vCutOptimizer is RX.CutOptimizer

// Retrieve the interface. I would use "new" in VB
vCutOptimizer = new RX.CutOptimizer
vCutOptimizer.DoSomething
vCutOptimizer.DoSomethingElse
etc.

Is this possible?

Kind regards
Mr G.
Publicado el 12,febrero 2016 - 12:57
Hi

I'm not sure what you call COM classes. If you are talking about an
activeX and OLE automation, look at OLE in the help for all that. If you
are talking about a .net component, then look at .net.

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Ready for you: WXShowroom.com, WXReplication (open source) and now WXEDM
(open source)

More information on http://www.fabriceharari.com


On 2/12/2016 3:36 AM, Mr G. wrote:
Hi,

I would need to use COM classes provided by another company. I have seen
COMCreateInstance and COMCallMethod but is there another way? I was
expecting that I would be able to import the type library of the COM
classes and then be able to declare the imported types and work with
them directly. But I can not find any relevant information in the manuals.

For example
// Declare a variable (assuming RX is the type library and CutOptimizer
is the name of the imported COM class)
vCutOptimizer is RX.CutOptimizer

// Retrieve the interface. I would use "new" in VB
vCutOptimizer = new RX.CutOptimizer
vCutOptimizer.DoSomething
vCutOptimizer.DoSomethingElse
etc.

Is this possible?

Kind regards
Mr G.
Miembro registrado
5 mensajes
Publicado el 14,febrero 2016 - 02:29
Hi Fabrice,

thank you for your reply. I meant OLE automation. I have found and read the help for this. I understand that OLE classes can be created using their class name for example:

MyAutomationObject is automation object MyServer

Does the type library of MyServer has to be imported for this to work? My real question behind this is that does WinDev uses "MyServer" name to create the COM class or it uses the GUID of "MyServer" based on the type library? (For later to work obviously the type library has to be imported first).

Kind regards
Mr G.
Miembro registrado
5 mensajes
Publicado el 14,febrero 2016 - 07:54
Hi,

I have investigated further and as far as I found importing the type library is not possible.

Background info:
The Windev application must be run in an environment where the COM classes are not registered in the registry, but can be instantiated by Windows if created using their GUIDs.

I have found that it is possible to create a COM class using it's GUID by using the COMObject type and the COMCreateInstance function.
But then the only way to call methods of the COM class is COMCallMethod which is quite awkward.

I presume that internally both the Automation object type and the COMObject type keep an IDispatch interface to the COM class.

So theoretically it would be possible to first create a COMObject using COMCreateInstance and then assign it to an Automation type variable. I tried this but it fails with "incompatible types during assignment" error message.

Would there be a way to assign the internal IDispatch interface from a COMObject type to an Automation type? If that would work then I could create the COM class using COMCreateInstance then use the >> operator to access the COM object's members.

Kind regards

Mr G.
Publicado el 16,febrero 2016 - 15:30
Hi

once again, I'm not sure what you are asking.

However, to use OLE automation is quite simple:
- the OLE automation system/object/tool is installed on a computer and
registered in the system
- at this point, it has a name that can be found in its documentation,
of course, but also with a number of tools able to list all OLE installed
- you use THIS name to declare your ole automation object

when that is done, EVERYTHING ELSE depends on the object, its
documentation, and how the developers of that object want you to use it.

There are several examples available with windev (for word, excel, open
office, etc), so you can have a look and draw parallels with YOUR case

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Ready for you: WXShowroom.com, WXReplication (open source) and now WXEDM
(open source)

More information on http://www.fabriceharari.com


On 2/14/2016 1:54 AM, Mr G. wrote:
Hi,

I have investigated further and as far as I found importing the type
library is not possible.

Background info:
The Windev application must be run in an environment where the COM
classes are not registered in the registry, but can be instantiated by
Windows if created using their GUIDs.

I have found that it is possible to create a COM class using it's GUID
by using the COMObject type and the COMCreateInstance function.
But then the only way to call methods of the COM class is COMCallMethod
which is quite awkward.

I presume that internally both the Automation object type and the
COMObject type keep an IDispatch interface to the COM class.
So theoretically it would be possible to first create a COMObject using
COMCreateInstance and then assign it to an Automation type variable. I
tried this but it fails with "incompatible types during assignment"
error message.

Would there be a way to assign the internal IDispatch interface from a
COMObject type to an Automation type? If that would work then I could
create the COM class using COMCreateInstance then use the >> operator to
access the COM object's members.

Kind regards

Mr G.
Miembro registrado
5 mensajes
Publicado el 16,febrero 2016 - 22:33
Hi Fabrice,

thanks for the reply.

>the OLE automation system/object/tool is installed on a computer and
registered in the system
As I wrote this application must run on a system where the OLE automation object is not installed. Yes, it is possible to use a non installed OLE automation object.

I think this is simply not possible with Windev.

Kind regards

Mr. G.