Help for Declare in Xojo19r2

my projects make use of macOSLib (64-bit). As I said in another post, the only module that does not compile is FileManager; but commenting 5 or 6 lines (not needed in my projects) everything runs all right.

Yet there is a function (DeviceName) that I need, but the debugger stops at f.MacVRefNum: type “folderitem” has no member named MacVRefNum
(6th line of the function, below).

Can anybody tell me how to solve the issue?
[At the end of the DeviceName function-code I pasted also its calling function, where the calling line is the 4th above the bottom].


[code]Public Function DeviceName(extends f as FolderItem) as String
//# DeviceName returns the BSD name of the volume containing f as found in the directory /dev. Only local volumes have such names.
#if TargetMacOS
soft declare function FSGetVolumeParms lib “Cocoa” (ByRef paramBlock as HIOParam) as Int32//or int64?
dim paramBlock as HIOParam
paramBlock.ioVRefNum = f.MacVRefNum// <<< here: type “folderitem” has no member named MacVRefNum
//the following line is a trick to work around the inability to assign a pointer to a structure
//to a field of type Ptr.
dim infoBuffer as new MemoryBlock(GetVolParmsInfoBuffer.Size)
paramBlock.ioBuffer = infoBuffer
paramBlock.ioReqCount = infoBuffer.Size

dim OSError as Integer = FSGetVolumeParms(paramBlock)
if OSError <> 0 then
  return ""
end if

dim infoBufferPtr as GetVolParmsInfoBuffer = paramBlock.ioBuffer.GetVolParmsInfoBuffer(0)
if infoBufferPtr.vMServerAddr = 0 then
  if infoBufferPtr.vMDeviceID <> nil then
    dim s as MemoryBlock = infoBufferPtr.vMDeviceID
    dim BSDName as String = s.CString(0)
    return DefineEncoding(BSDName, Encodings.SystemDefault)
    return ""
  end if
  // vMServerAddr <> 0 means it's a network device, which apparently won't have a BSD name.
  return ""
end if

#pragma unused f
End Function

//////DeviceName’s calling function:

[code]//# This function, using code from the Apple sample project VolumeToBSDNode, looks up the class name of an IOObject using IO Kit. It will return
//# IOCDMedia for a CD, IODVDMedia for a DVD, and IOMedia for anything else. Thus this function will tell you whether a local volume is a CD or DVD.
//@ It returns "’ for network volumes or if an error occurs.

#if targetMacOS
const IOKitFramework = “IOKit.framework”
const kIOMasterPortDefault = nil //see IOKitLib.h
const IO_OBJECT_NULL = nil
const kIOMediaClass = “IOMedia”
const kIOServicePlane = “IOService”
const kIORegistryIterateRecursively = &h00000001
const kIORegistryIterateParents = &h00000002
const kIOCDMediaClass = “IOCDMedia”
const kIOMediaWholeKey = “Whole”
const kCFAllocatorDefault = nil

soft declare function IOBSDNameMatching lib IOKitFramework (masterPort as Ptr, options as Integer, bsdName as CString) as Ptr
soft declare function IOServiceGetMatchingService lib IOKitFramework (masterPort as Ptr, matching as Ptr) as Ptr
// /usr/include/device/device_types.h:typedef char io_name_t[128];

soft declare function IORegistryEntryCreateIterator lib IOKitFramework (entry as Ptr, plane as CString, options as Integer, ByRef iterator as Ptr) as Integer
soft declare function IOObjectConformsTo lib IOKitFramework (obj as Ptr, className as CString) as Boolean
soft declare function IORegistryEntryCreateCFProperty lib IOKitFramework (entry as Ptr, key as CFStringRef, allocator as Ptr, options as Integer) as Ptr
soft declare function IOObjectGetClass lib IOKitFramework (obj as Ptr, className as Ptr) as Integer
soft declare function IOObjectRetain lib IOKitFramework (obj as Ptr) as Integer
soft declare function IOObjectRelease lib IOKitFramework (obj as Ptr) as Integer

//the documentation for this function suggests that we don’t need to free dPtr (it’s a CFMutableDictionaryRef) because we pass it to IOServiceGetMatchingService
//which consumes a reference. Some testing with CFGetRetainCount confirms this.
dim dPtr as Ptr = IOBSDNameMatching(kIOMasterPortDefault, 0, f.DeviceName)
if dPtr = nil then
return “”
end if[/code]

MacVRefNum was alredy deprecated in 2015r1… since 2010r5.

Its - then - replacement is also deprecated and removed in 2019r2 (FolderItem.MacFSRef ).

And I forgot the 2019r2 replacement…

Did you searched in the apple developer documentation the name of the API that returns a number to reference a file when you want to open … a file ?

Lon time ago, that was the File Manager who was in charge of these stuff. A simple quest and I was lost:

File Manager is Deprecated at Apple:

Have a look at declare not working in 64-bit . Scroll down to the statfs declare.
I assume the “file system id” (see “man statfs”) should do the trick.
No expensive plugin needed.


I’m really embarrassed, as you had already solved the same identical issue two years ago and I had utterly forgotten not only your answer, but even the fact that I had actually started that topic.

And I can’t understand why tow years ago, after applying your code to the project I was working on, I did not modify the offending code of this particular project too.

I guess it has something to do with my age (72). So please accept my thanks and my apology.

Glad to help :wink: