Mac OS X ignoring Compiler Directives?

Recently encountered trouble with a cross-platform custom control which has always worked with Real Studio and Xojo (Xojo on Windows). A developer has tested the control on Mac OS X and a User32 error was raised. Not sure which version of Xojo this was, but the compiler completely ignored the directive to ignore the function if the target was not Windows.

  //If not Windows, we need to exit this function :-)
  #If Not TargetWin32 Then Return Nil
  
  //Need this to get the "Real" Window/Object Handles
  Declare Function GetDC Lib "User32" (HWND As Integer) As Integer

I do not have access to my Mac at the moment and know that this had been a bug in the start of Xojo, but was wondering if it is fixed as of current builds?

Simple test really, put the above in a test application’s open event or a button action event, compile and try it out. Please verify or deny that this bug has or hasn’t been fixed as of 2013 r4.1.

Thank You,
Matthew

That is not the right way to of it … It should be

#If targetWin32 Declare Function GetDC Lib "User32" (HWND As Integer) As Integer 'other win32 specific code maybe: Return GetDC(HWND) #endif

The way you did it Xojo will try to compile that declare on OSX and thus the error

Of course you could do the other wayarroung but all platform specific code needs to be in #if#endIf blocks

In a hurry I typed it as I did in the first post…although the code is as you posted. While trying to work on a few projects and find out if the bug has been fixed for Mac OS X since 2013 r1, I have been slightly absent minded today. :slight_smile: Yes…all directives must be encapulated by the #if #else/#elseif #endif tags. 2013 r1 seemed to neglect the directives and we had a run-in a bit ago with a developer being unable to run the debug build. I’m unsure if the developer is running 2013 r1 or the most recent release. Thanks Karen. In my absent minded-ness earlier I also uploaded the newest Custom-EditField with bugs fixed for Xojo (no dreaded ThreadAccessingUI anymore) and forgot to mention its the replacement for the old one found at code.google.com/custom-editfield, and requires the Images from the original package. :slight_smile:

Original Code:

  //If not Windows, we need to exit this function :-)
  #If Not TargetWin32 Then
 
  Declare Function GetDC Lib "User32" (HWND As Integer) As Integer
  Declare Function BitBlt Lib "GDI32" (DCdest As Integer, xDest As Integer, yDest As Integer, nWidth As Integer, nHeight As Integer, _
  DCdource As Integer, xSource As Integer, ySource As Integer, rasterOp As Integer) As Boolean
  //If we don't release an object after hooking into its resources...we'll have a memory leak :-p
  Declare Function ReleaseDC Lib "User32" (HWND As Integer, DC As Integer) As Integer
  
  //Lets use two options incase windows is older and lacks captureblt api
  Const CAPTUREBLT = &h40000000
  Const SRCCOPY = &HCC0020
  
  //Create a Picture object to hold our hooked screenshot
  Dim screenCap As New Picture(MapWidth, MapHeight, 24)
  //Get the "Real" HTMLViewer Handle for Capture..Xojo returns a bogus 'pseudo handle'
  Dim HTMLViewerDC as Integer = GetDC(MapViewer .Handle)
  
  Call BitBlt(screenCap.Graphics.Handle(1),0,0,MapWidth , MapHeight , HTMLViewerDC, -2, -2, SRCCOPY or CAPTUREBLT)
  //Function may be called again..so lets release the object to prevent memory leak...
  Call ReleaseDC(MapViewer.Handle, HTMLViewerDC)
  //Return our "Snapshot"
  Return screenCap
#else
  return Nil
#endif

:slight_smile:

You have

#IF Not TargetWin32 THEN

It should be

#IF TargetWin32 THEN

[quote=56361:@Matthew Combatti] //If not Windows, we need to exit this function :slight_smile:
#If Not TargetWin32 Then
[/quote]

That code executes if you are NOT on Windows…

I think you want:

[code]#if Not TargetWin32
Return NIL
#else

Declare Function GetDC Lib “User32” (HWND As Integer) As Integer
Declare Function BitBlt Lib “GDI32” (DCdest As Integer, xDest As Integer, yDest As Integer, nWidth As Integer,

Return screenCap
#endif
[/code]

I’ll just leave it… I did it again deleting the first line without posting the whole thing. The code without everything else

#if targetWin32 Then

’ Do windows stuff

#else
return nil
#endif

The point of the post is…
IT HAS BEEN A BUG IN RECENT Xojo Releases…

Is it still?

Too many things going on at once. The code is not pertinent… has the directives issue been fixed in recent releases for Mac (I’m on Windows)? In the meantime, I read the post about using flags and directives not being ignored in Modules… I believe we may have the issue fixed using the work-around method…

Hope that didn’t sound harsh…writing is too impersonal. Sorry Karen. Indeed I have the code right, It just wasn’t working as it does with every other release (for mac os x) including Real Studio (on mac)

I ran the following code in the IDE in OSX 9.1 and Windows 7 in teh default window open event:

[quote]#If TargetWin32
MsgBox “win32”
#else
MsgBox" OS X"
#endif[/quote]

On OS X the Msgbox said “Mac OS”

In Win 7 it said “win32” …

Do you see the issue in compiled apps or maybe just Mac apps compiled on Windows?

  • Karen

Just Mac apps compiled on Mac…it has never appeared on Windows at all. And I really am sorry for the caps, I wasn’t meaning to be rude by any means or intent. I knew it was an issue in 2013 r1, after that I haven’t tried compiling any apps containing directives on Mac. The Xojo Developer’s Library contains directives, and that was one of the issues that prevented it from being released under the Xojo compilation upon first release…until It was discovered that you could compile the Mac version on Windows and it would function fine on Mac. Odd.

I’m just not seeing it… in Xojo 2013R3 Or 4

On OS X when I run in the IDE the flowing code runs just fine but on Win 7 I get a syntax error.

#If TargetWin32 x === 321 MsgBox "win32" #else MsgBox" OS X" #endif

And for the flowing code compiles and runs fine on Windows but not OSX

#If TargetWin32 MsgBox "win32" #else x === 321 MsgBox" OS X" #endif

So if there was bug it’s gone now…

[quote=56370:@Matthew Combatti]The point of the post is…
IT HAS BEEN A BUG IN RECENT Xojo Releases…

Is it still?[/quote]

I’ve never heard of such a bug, never seen it be reported in Feedback, and certainly not fixed it.

I have used these target directives in RealBasic, RealStudio and XOJO and they worked all the time…

The key thing to remember is the “#” before the IF and ENDIF
and to NOT put any code following the THEN on the same line.

These are directives NOT logic points as a normal IF/THEN would be.

The code inside the directive is included (or not) during the compile phase based on the TARGET in the directive and the OS that XOJO is running under at the moment, exactly as Karens examples above show.