Conditional Compilation Question

G

Guest

I have a solution that consists of a WinForms app and a Pocket PC app. Each
of these two projects shares a 3rd project that is a compiled library file
(DLL).

The items in the library are pretty much common to both apps but there are a
few differences. For example, there's no "Beep" function for Pocket PCs.
So, to get around these few exceptions I put some conditional compilation
statements in where required Thus, for example, Beep took on this form:

#if (POCKETPC)
Debug.Writeline("");

#else
[DllImport("kernel32.dll")]
public static extern bool Beep (int freq, int duration);
#endif

Where "POCKETPC" is a tag I define at the very start of my Pocket PC app's
main form.

Everything *appears* to compile properly but I'm wondering two things:

1. Is this a correct & safe way to do things?

2. Are the resultant DLLs that go onto the two respective computers actually
compiled differently?
 
S

Scott Roberts

I have a solution that consists of a WinForms app and a Pocket PC app. Each
of these two projects shares a 3rd project that is a compiled library file
(DLL).

The items in the library are pretty much common to both apps but there are a
few differences.
1. Is this a correct & safe way to do things?


Is it not possible to factor differences out into their respective apps and
make the library be exactly the same for both apps? That would be *my*
preference.

In your example, instead of optionally declaring "Beep()" I would create a
"UserNotify" singleton class in each app that knows how to "notify" the user
for that particular type of application. The 3rd DLL would simply call the
"Notify()" (or "Beep()" if you prefer) method of the singleton - which would
work regardless of the type of application running.
 

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