[futurebasic] Re: [FB] Saving a picture of a window to a jpeg file

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2010 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Sun, 24 Oct 2010 15:22:03 +1300
WinGammon@... wrote:

> What I want to do is to save a file to the desktop. I don't want to ask the user for the file name and location, just save the file. I have tried to create an FSSpec then converting it to a CFURLRef using the following but it crashes the program.
> 
> filename = "BoardScreenShot.jpg"
> Fn FSMakeFSSpec( gDesktopFileSpec.vRefNum, gDesktopFileSpec.parID,fileName,fSpec )
> fSpec.name  = fileName
> 
> fn FD_FSSpecCreateCFURL( fSpec, url )

The error return values from FSMakeFSSpec() and FD_FSSpecCreateCFURL() may be helpful in diagnosing the crash.

Alternatively, you could do without gDesktopFileSpec, as in the code below.

'--------
include "Util_FileDirectory.incl"
dim as CFURLRef  fileUrl, folderUrl
dim as OSStatus  err

err = fn FD_SpecialDirectoryCreateCFURL( _kUserDomain, _kDesktopFolderType, @folderUrl )
if ( err ) then stop "FD_SpecialDirectoryCreateCFURL error " + str$( err ) : end
err = fn FD_PathCreateCFURL( @"BoardScreenshot.jpg", folderUrl, @fileUrl )
CFRelease( folderUrl )
if ( err ) then stop "FD_PathCreateCFURL error " + str$( err ) : end
//
//.. your code that uses fileUrl...
//
CFRelease( fileUrl )
'--------

Robert P.