CF #ifdef's

M

Mark Johnson

Also, what are the pre-processor symbols I should use for checking for

I have not found a standard way of doining this.
There is no pre-processor symbols like DEBUG for this.
I use to the following work around:

(I am using a German Version, so I am not sure of the English expressions -
would like to have them BTW for Documentation)
Set the following in Framework.Compact Projects :

\Project\Properties\
Configuration : all configurations
\Configuration Properties\Set pre-processor for Compiling : COMPACT

The following works correctly :

#if (DEBUG && !COMPACT)
#warning Net.Framework (Debug) is defined
#elif (!DEBUG && !COMPACT)
#warning Net.Framework (Release) is defined
#elif (DEBUG && COMPACT)
#warning Net.Framework.Compact (Debug) is defined
#else
#warning Net.Framework.Compact (Release) is defined
#endif

a Sample of code that will run on both Mashines :

#if COMPACT
pn_Panel.Capture = true;
IntPtr hWnd = Win32Window.GetCapture();
pn_Panel.Capture = false;
p_IntPtr = OpenNETCF.WinAPI.Core.GetDC(hWnd);
#else
p_IntPtr = p_Graphics.GetHdc();
p_Graphics.ReleaseHdc(p_IntPtr);
#endif

When shown in VS, the "inactive code" will be grey to show that it will not
be compiled.

Hope this helps

Mark Johnson, Berlin Germany
(e-mail address removed)
 
C

Chris Tacke, eMVP

Since binaries are retargetable, there's no way for the compiler to know
what you're going to run the assemby on. Use
System.Environment.OSVersion.Platform to decide at run time what to do.
 
M

Mark Johnson

But it is not allway possible to compile Framework Code that is not
supported on the Compact
- like p_IntPtr = p_Graphics.GetHdc();
thus here the #ifdefs are usefull.
Do you have a practical Sample where you would use
System.Environment.OSVersion.Platform ?

Mark Johnson, Berlin Germany
(e-mail address removed)
 
C

Chris Tacke, eMVP

The problem here is that you need to link against a core. Linking agains
the CF will fail becasue you're calling desktop-only code. If you link to
the desktop core, it will build, but desktop binaries are not retargetable
to the device.

In this case, I don't think there's any possible way to make an assembly
that will run on both platforms (at least not with the framework versions
that are released).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top