Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
File access is denied
Message
From
30/11/2020 02:28:46
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
File access is denied
Miscellaneous
Thread ID:
01677327
Message ID:
01677327
Views:
70
Sir I am converting frx into jpg then copy converted jgp file to clipboard.
So I have these codes
Set Safety Off

Public yout
Do declaration
Do create_jpg
Do image_to_clipboard
*---------------------------------------------------------
* this procedure converts frx into jpg
Procedure create_jpg
m.yrep=Addbs(Justpath(Sys(16,1)))
Set Defa To (yrep)
m.yout=m.yrep+"output"

If !Directory(m.yout)
	Md (m.yrep+"output")
Else
	Erase (m.yout+"\*.*")
Endi

Local afile
afile=(_Samples + "\Solution\Reports\Colors.frx")

#Define OutputNothing -1
#Define OutputEMF 100
#Define OutputJPEG 102
#Define OutputGIF 103
#Define OutputPNG 104
#Define OutputBMP 105
#Define OutputTIFF 101
#Define OutputTIFFM 201

oListener =Newobject("ReportListener")
oListener.ListenerType=3
Report Form (afile) Preview Object oListener

myext=[.]+Alltrim('JPG')
ntype=OutputJPEG
m.yout=m.yrep+"output"

For nPageno=1 To oListener.PageTotal
	cOutputFile = m.yout+"\myreport"+Trans(nPageno)+myext
	oListener.OutputPage(nPageno, cOutputFile,m.ntype)
Next

If Not Inlist(ntype,OutputTIFFM,1000,1001)
	Run/N "explorer"  &yout
Endi

reporlistener=Null
Release ReportListener
Endproc

*---------------------------------------------------------
* this procedure copy converted jpg to bmp then copy bmp to clipboard
Procedure image_to_clipboard

#Define CF_BITMAP 2
#Define CF_DIB 8
#Define IMAGE_BITMAP 0
#Define LR_LOADFROMFILE 16
#Define LR_MONOCHROME 0x00000001

fso=Createobject("scripting.filesystemobject")
fld=fso.getfolder(yout) && read file from foldr one by one

For Each fil In fld.Files
	Local m.oo
	m.oo=Newobject("image")
	m.oo.Picture=m.yout+"\"+(fil.Name)

	Local lnWidth,lnHeight
	lnWidth=m.oo.Width
	lnHeight=m.oo.Height

	nBitmap=0
	hbm=0
	GdipCreateBitmapFromFile(Strconv(m.yout+"\"+(fil.Name)+0h00,5),@nBitmap)
	GdipCreateHBITMAPFromBitmap(nBitmap,@hbm,0)
	lhBmp = CopyImage(hbm, 0, m.lnWidth, m.lnHeight,0)
	If OpenClipboard(0)!= 0
		EmptyClipboard()
		SetClipboardData(CF_BITMAP, lhBmp)
		CloseClipboard()
	Endif
Next

Endproc
*---------------------------------------------------------
Procedure declaration

Declare Integer OpenClipboard In User32 Integer
Declare Integer CloseClipboard In User32
Declare Integer EmptyClipboard In User32
Declare Integer SetClipboardData In User32 Integer,Integer
Declare Integer LoadImage In WIN32API Integer,String,Integer,Integer,Integer,Integer
Declare Integer GetClipboardData In User32 Integer
Declare Integer GdipCreateBitmapFromHBITMAP In GDIPlus.Dll Integer, Integer, Integer @
Declare Integer GdipSaveImageToFile In GDIPlus.Dll Integer,String,String @,String @
Declare Long GdipCreateHBITMAPFromBitmap In GDIPlus.Dll Long nativeImage, Long @, Long
Declare Long GdipCreateBitmapFromFile In GDIPlus.Dll String FileName, Long @nBitmap
Declare Long    GdipCreateBitmapFromFile    In GDIPlus.Dll String FileName, Long @nBitmap
Declare Long CopyImage In WIN32API Long hImage, Long, Long, Long , Long
Endproc
The codes work fine FIRST time. no error occurs. you can see converted file in bmp format in folder

But when I run above codes SECOND time then it show this error messages
https://res.cloudinary.com/engineering-com/image/upload/v1606721114/tips/is_cpasxy.png

Is it possible to get rid of this error message?

I sure the error is in these lines
nBitmap=0
	hbm=0
	GdipCreateBitmapFromFile(Strconv(m.yout+"\"+(fil.Name)+0h00,5),@nBitmap)
	GdipCreateHBITMAPFromBitmap(nBitmap,@hbm,0)
	lhBmp = CopyImage(hbm, 0, m.lnWidth, m.lnHeight,0)
	If OpenClipboard(0)!= 0
		EmptyClipboard()
		SetClipboardData(CF_BITMAP, lhBmp)
		CloseClipboard()
	ENDIF
Please help
Reply
Map
View

Click here to load this message in the networking platform