Big news! The community will be moving to a new platform April 21. Read more.
Big news! The community will be moving to a new platform April 21. Read more.
Absent Member.
Absent Member.
1626 views

sharing data in a COM server

Jump to solution

[Migrated content. Thread originally posted on 08 April 2011]

After struggling for several days and combing the documentation (it really needs better search) I find that Micro Focus Net Express 5.1 does not support Factory in COM components. You are not allowed to write factory methods and if you do they are ignored. Neither are you allowed to use Class Object (Factory) data. You ARE allowed to write ONE Factory method which must be called "new" and it cannot return or accept anything.

So here's the scenario:

I have a Class that will be implemented as a COM server (IN Process .DLL). Every time it is instanced I need to update a count and build an instance stamp for that particular instance of the Class, as there can be multiple instances running in multiple threads and I need to be able to identify them. I wrote an override successfully for the "new" class and tried the following:

in the Class Methods (Factory methods):


method-id. "new".

*>---USER-CODE. Add any local storage items needed below.
working-storage section.
01 instanceStamp pic x(24).
01 isStamp pic x(20) value "AnyCo3MT".
01 isCount pic 9999 value zero.

*>---------------------------------------------------------------

procedure division.
P1.

add 1 to isCount
move isStamp to instancestamp
string
instancestamp
delimited by space
isCount
delimited by size
into instancestamp
end-string
invoke SELF "LocalinstanceStamp"
using instancestamp
end-invoke
.

end method "new".

That's what has to happen when someone instantiates the object... Because the above method runs at the Class level the count gets continually incremented as new instances are created. Obviously, there is no point in putting this count at the Object level because it will always be 1...

I need for certain Object Methods to have access to the instance stamp so that's why the Method above invokes a standard object method to set the instance stamp into object storage. Here's the object method:

... (this is OBJECT storage not CLASS storage) ...
01 local-instance-stamp pic x(24) value "Uninitialized".

*> OCWIZARD - start standard instance methods
method-id. "LocalinstanceStamp".
linkage section.
01 LIS pic x(24).
procedure division using LIS.
move LIS to local-Instance-stamp
exit method.
end method "LocalinstanceStamp".

All pretty straightforward. It compiled clean so I was optimistic, but it gives a signal error when it runs. If I comment out the invoke of "localinstanceStamp" in the Factory method ("new"), then it works fine except that I don't get the local-instance-stamp being set, of course. I thought about this and figured it might be because the Class has not yet been fully instantiated so "SELF" may not have been set. I tried setting an object reference within the "new" method and invoking "LocalinstanceStamp" on that, but nothing worked.

So HOW do you share data between Class methods and Object methods in COM servers if it doesn't support Class storage or Methods for COM? As you can see, there can be sound reasons for needing a Factory process. I have never encountered this problem before and other COBOL systems implement Factory for COM without problem.

Am I missing a directive or switch that makes storage GLOBAL or something here? (I tried +G with OOCTRL but it made no difference. Neither did +W. I also tried making local-instance-stamp GLOBAL, but the compiler spat the dummy on that.)

Please don't tell me I have to write a file from within the "new" method... 🙂

All suggestions/ideas gratefully received,

Pion.
0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert
Only class methods are not supported in COM.

Global data can be specified in the working-storage section of the class and it will be shared by all instances.

Class properties can also be specified in the object-storage section of the class and then you can use Get and Set with the name to access the data.


  class-control.                                                 
      testcomdll2 is class "testcomdll2"                         
*> OCWIZARD - start list of classes                             
      olebase is class "olebase"                                 
      oleSafeArray is class "olesafea"                           
      oleVariant is class "olevar"                               
*> OCWIZARD - end list of classes                               
*>---USER-CODE. Add any additional class names below.           
      .                                                           
*>-----------------------------------------------------------   
  working-storage section. *> Definition of global data           
  01 GlobalCount       pic s9(9) comp-5.                         
*>-----------------------------------------------------------   
  class-object.   *> Definition of class data and methods         
*>-----------------------------------------------------------   
  object-storage section.                                         
  01 PropCount       pic s9(9) comp-5   PROPERTY.                 
                                                               



View solution in original post

0 Likes
2 Replies
Micro Focus Expert
Micro Focus Expert
Only class methods are not supported in COM.

Global data can be specified in the working-storage section of the class and it will be shared by all instances.

Class properties can also be specified in the object-storage section of the class and then you can use Get and Set with the name to access the data.


  class-control.                                                 
      testcomdll2 is class "testcomdll2"                         
*> OCWIZARD - start list of classes                             
      olebase is class "olebase"                                 
      oleSafeArray is class "olesafea"                           
      oleVariant is class "olevar"                               
*> OCWIZARD - end list of classes                               
*>---USER-CODE. Add any additional class names below.           
      .                                                           
*>-----------------------------------------------------------   
  working-storage section. *> Definition of global data           
  01 GlobalCount       pic s9(9) comp-5.                         
*>-----------------------------------------------------------   
  class-object.   *> Definition of class data and methods         
*>-----------------------------------------------------------   
  object-storage section.                                         
  01 PropCount       pic s9(9) comp-5   PROPERTY.                 
                                                               



View solution in original post

0 Likes
Absent Member.
Absent Member.
Thanks Chris,

sorry for delayed reply; I have been tied up on other things.

Somehow I missed that Global use of Working-storage. Thanks for setting me straight.

Everything now works fine and that problem is well solved.

Regards,

Pion.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.