Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

File handle locked

8 views
Skip to first unread message

Stephane Hebert

unread,
Aug 8, 2001, 7:04:23 PM8/8/01
to
Hi folks,

VO2.5
RP3.2 (no classmate)

My app generates same bitmaps to a folder and then these are used by
ReportPro in a report.

The main problem is that ReportPro doesn't release the file handles of the
bitmaps. When the user wants to print the report, I first create bitmaps
then call the report and the report uses the bitmaps. When the user tries
to print the report again, I then try to create the bitmaps again, but I
can't since the files are locked, so the user keep seeing the same bitmaps
each time the report is executed.

I did speak with Larry about this and he tells me that CAPaint.dll is the
culprit. The bitmaps are created using Fabrice Forays' functions from
FabTools and these functions use CAPaint (i think) and the handles are
released when I'm done creating them, so why is CAPaint not releaseing the
handles when it's used by ReportPro ?!

Obviously, I need a workaround.

Maybe if I wrapped the ReportPro Runtime in a DLL I could load that DLL only
when the user wants to print the report and then release it when done. That
would release the handle to the file also, right ? Wrong !

I've succeeded in the following:

1) Load the DLL with _VOLoadLibrary()
2) Use CreateInstance(#ReportProRunTime)
3) Print the report
4) _VOFreeLibrary()
5) Check if CAPAint is still loaded and if it is, free it

This all works fine the first time around but fails at #2 the second time I
print the report without quitting the app, which causes either a 5333 or an
exception error.

How can I get those bitmap files to be freed ???

Here is the code:
====================================================================
Function _PrintReport(oWin as object,nReportType as int,lPreview as logic)
as void pascal
local hRPDLL as ptr
local ptrFunc as ptr
local hModule as ptr
local oReport as object
local cTmpPath as string
local cDataPath as string

// check if the DLL is already in memory
hModule:=GetModulehandle(string2psz("ACRPRT.DLL"))
if hModule!=null_ptr
return
endif

// Load the DLL
hRPDLL:=_VOLoadLibrary(string2psz("ACRPRT.DLL"))
if hRPDLL=null_ptr
return
endif

// Call a dummy function
ptrFunc:=getProcAddress(hRPDLL,String2Psz("Dummy"))
if ptrFunc!=null_ptr
pcall(ptrFunc)
else
return
endif

cTmpPath :=AppObj():TempPath
cDataPath :=WorkDir()

if WM_CreateTmpFile("ACFTTMP1.DBF",#ACFTTMP1) .and. ;
WM_CreateTmpFile("ACFTTMP2.DBF",#ACFTTMP2) .and. ;
WM_CreateTmpFile("ACFTTMP3.DBF",#ACFTTMP3)

// Before going any further, delete the images if they exist, but of
course they won't be deleted if RP is
// still around
DelTempImages()

if oWin:_FillTemp(nReportType)
oReport:=CreateInstance(#ReportProRunTime,oWin) <<<<<----5333 or
crash second time around
if oReport!=null_object

oReport:HyperLabel:=HyperLabel{#ReportProRunTime,"ReportProRunTime",NULL_STR
ING,NULL_STRING}
if oReport:CreateEmbedding("ReportPro.Runtime")
oReport:InitAutoObject()

// load the report code...I'll skip this, not relevant

// Clean-up time
oReport:Close()
oReport:Destroy()

// The following doesn't change a thing.
oReport:=null_obejct
if !InCollect()
CollectForced()
endif

else
WarningBox{,"Audio Fit",LoadResString("Could not initialize
ReportPro RunTime component.",IDS_ERROR_RPOLEFAIL3,cLangDLL)}:show()
endif
endif
endif

// Free the DLL
if hRPDLL!=null_ptr
if _VOFreeLibrary(hRPDLL)
WarningBox{,"","DLL IS GONE"}:Show()
endif
endif

// Is CAPaint still around? If so, free it.
hModule:=GetModulehandle(string2psz("CAPAINT.DLL"))
if hModule!=null_ptr
if FreeLibrary(hModule)
WarningBox{,"","CAPAINT IS GONE"}:show()
endif
endif

=========================================================

Ok, so the above doesn't work like I stated above, but why ?.

Let's try something different.

Maybe I can figure out what the file handle of the bitmap file is and use
UnlockFile() or UnLockFileEx() to unlock it. Don't know it this would work
under Win2K though, security issues and all.
But first, I need the file handle. I think the best way of doing that would
be to use CreateFile() with 0 as the second parameter. But how would I know
if there's a file lock on the file ? Would I be able to close the file with
a simple call to Close() ?

That's a tough one, for me anyways.

--
============================
Stéphane Hébert
ste...@audiocontrole.com
============================

0 new messages