Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sharing An Array In A COM DLL
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Sharing An Array In A COM DLL
Miscellaneous
Thread ID:
00665652
Message ID:
00665652
Views:
68
This is kind of lengthy, but I'm not sure how to explain it.

I have a report viewing application I created to display Crystal Reports.

All my other apps call into it, via a COM DLL, to display their reports.
This DLL is used by both the viewer application and the applications
that call into the viewer. It all works great!

I wanted to provide a function in the DLL to return information from the
report viewer about what reports are currently displayed in the viewer.

I know that public variables are shared amongst all instances of a COM DLL,
so I want to take advantage of this to pass info back to the calling
applications.

Since all the applications using the DLL are in different threads, I figured
I'd use a public array, with each element in the array holding a reference
to an object I created, called 'oReportObj'.

These objects would simply be abstract objects with properties about each
report currently open.

In the Init I have:
HIDDEN PROCEDURE Init

  WITH This

    ** When the first instance of the DLL inits, this variable
    ** array will be created. ALl other instances should be able
    ** to 'see' this variable
    IF TYPE("aReports")	= "U"
      PUBLIC aReports[1]
      aReports = NULL
    ENDIF

  ENDWITH

ENDPROC
Then I have a method called AddReport. Inside the viewer, each time a report is displayed,
I call AddReport in the DLL, which instantiates an instance of oReportObj, sets the properties to
info about the report, and store the object to an element in the public array created in
INIT:
PROCEDURE AddReport(sAppTitle, sReportTitle, sReportFile, aTables) AS Integer

  LOCAL iElement, iTemp
  iElement = 0

  WITH This

    oReportObj = CREATEOBJECT("ReportInfo")

    oReportObj.sReportId = SYS(2015)
    oReportObj.sAppTitle = sAppTitle
    oReportObj.sReportTitle = sReportTitle
    oReportObj.sReportFile = sReportFile

    =ACOPY(aTables, oReportObj.aTables)

    FOR iTemp = 1 TO ALEN(aReports, 1)
      IF VARTYPE(aReports[iTemp ]) # "O"
        iElement = iTemp
      ENDIF
    ENDFOR

    IF iElement = 0
      iElement = ALEN(aReports, 1) + 1
      DIMENSION aReports[iElement]
    ENDIF

    aReports[iElement] = oReportObj
			
    RETURN iElement

  ENDWITH

ENDPROC
Then, any application can instantiate it's own copy of the DLL and call GetReportInfo
to fill any array with objects about the reports which are open in the viewer:
DIMENSION aReports[1]
nTotReports = oDll.GetReportInfo(@aReports)
This allows the calling application to see information about reports currently
open in the report viewer. Here's GetReportinfo:
PROCEDURE GetReportInfo(aArray) AS Variant

  LOCAL iRetVal
  iRetVal = ALEN(aReports)
		
  ** aReports is public, and should be available to any application
  ** which instantiates this DLL
  =ACOPY(aReports, aArray) 
		
  RETURN iRetVal

ENDPROC
And my ReportObj is:
DEFINE CLASS ReportInfo AS Session OLEPUBLIC

  sReportId = ""    && Unique report Id
  sAppTitle = ""    && Caption to appear on the window the report is in
  sReportTitle = "" && Caption to appear on the tab
  sReportFile = ""  && Full path and name of the report file
	
  DIMENSION aTables[1] && Array of table information

ENDDEFINE
Ok now the problem. When I call the GetReportInfo function, the array I pass
has one element, which is NULL.

I have used low-level file functions in the DLL to check the values during
execution, and in the AddReport when I store the report to the array, it
IS an object.

From the other application, when I call GetReportInfo, the array has NULL.

Can anyone shed some light on this?

Thanks
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Next
Reply
Map
View

Click here to load this message in the networking platform