PDA

View Full Version : Windows APIs & loading pictures into userforms at runtime in Office for Mac



RichardWorth
06-02-2016, 02:13 PM
Hi,

Despite the nay-sayers, the Windows APIs are available in:


Applications:Microsoft Office 2011:Office:MicrosoftOffice.framework:MicrosoftOffice


I used these to write a routine to load a picture into a userform at run time (YES - at runtime). However, I think the sandbox is becoming a problem in Office 2016. The equivalent file for Excel 2016 seems to be in


Applications:Microsoft Excel.app:Contents:Frameworks:MicrosoftOffice.framework:MicrosoftOffice


While I can open this file with VBA the API calls say that this is file is not found even though it exists (and it is in Excel's sandbox area).


For example,


#If Mac Then
#If MAC_OFFICE_VERSION >= 15 Then
'2016 or later
Private Declare Function GetDC Lib "Applications:Microsoft Excel.app:Contents:Frameworks:MicrosoftOffice.framework:MicrosoftOffice" _
(ByVal hWnd As Long) As Long
#Else
'2011
Private Declare Function GetDC Lib "Applications:Microsoft Office 2011:Office:MicrosoftOffice.framework:MicrosoftOffice" _
(ByVal hWnd As Long) As Long
#End If


Calling GetDC in Excel 2011 works fine but in 2016 it says the file is not found.

Is there any way to call DLLs in Office 2016?

If this can be solved, then I'll let everyone have my routine for loading bitmap files in userforms at runtime. In other words, it works fine in Excel 2011, but not Excel 2016.

Thanks,

Richard
PS. I tried the CALL excel 4.0 macro sheet and it didn't work either.
PPS. If it is impossible to call DLLs from Office 2016 for Mac then I will make available my initial workaround for loading pictures into a userform at runtime - modify a frx file and import it - clunky and slow, but it works.
PPPS. If you do try to play around with the Windows APIs do not have anything of value open on your machine. Code which works perfectly in Windows can crash a Mac. Nevertheless, API calls used to read pointsperpixel etc worked fine.

Schwieb
06-03-2016, 09:12 AM
Hi Richard,

The root issue here is that Apple has deprecated HFS on the Mac, so Mac Office 2016 no longer uses or supports HFS paths. You must use POSIX paths (with "/" as the directory separator) in Mac Office 2016. You need to use the format "/Applications/Microsoft Excel.app/Contents/Frameworks/MicrosoftOffice.framework/MicrosoftOffice" instead now.

In this particular case, the sandbox is not the problem. However, if you are developing code that uses any sort of external dll.framework not from Office or from the OS, the sandbox will interfere. There are a couple of documented places for installing external content that are supported by sandbox entitlements. I'd post a link but this site wont let me (It thinks I'm spamming it). You can email me at 'eriksc at Microsoft dot com' and I can send you the link directly.

Schwieb
Principal Software Engineer
Apple Platform Experiences Group
Microsoft

RichardWorth
06-03-2016, 01:18 PM
Hi Richard,
You need to use the format "/Applications/Microsoft Excel.app/Contents/Frameworks/MicrosoftOffice.framework/MicrosoftOffice" instead now.


Thank you!!!!!!! I had been made aware of the need to use '/' - but I did not have the slash before 'Applications'. GetDC works now for Excel 2016 so I can test the whole routine!!

So it wasn't the litter box, er, I mean sandbox ... :P

Richard :D :D :D