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.
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. 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.
//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
[quote=56361:@Matthew Combatti] //If not Windows, we need to exit this function #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)
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 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.