yoavrofe wrote:
Hello all,
I'm trying to run a small program on both PPC and CE devices.
I am calling SHGetAutoRunPath only when running on a PPC platform.
However, since this function depends on aygshell.dl, which doesn't
exist on the CE platform, the program does not run at all on the CE
platform.
if(lstrcmpi(lpCmdLine, _T("install")) == 0)
{
// Card has been inserted. We NEVER get here on a CE platform!
TCHAR szSDAutorunFullPath[MAX_PATH+1]; // Compact Flash path
SHGetAutoRunPath(szSDAutorunFullPath);
.....
}
Is there a way to make the program run on both platforms without
recompiling it?
Define a semantically abstract interface to represent the underlying
platform. Implement this interface separately for each platform you
support, defining each such implementation in a separate source code module.
Your main routine, the client of the platform access modules, should
access the platform only through the abstract interface. Your build
system can then select the correct, platform-specific implementation to
link into your application for each build target. If you find there is
a lot of common code among the platform-specific modules, factor it into
a separate "platform support" module.
IOW, your driver routine probably shouldn't be calling something like
SHSomeHorridLookingFunctionName directly, anyway. Instead, it should be
calling platform.cardInserted, where "platform" is of a type defined by
the build system. If you want to stick with the C-like coding style
above, you might just declare:
void platformCardInserted();
Multiple compiled object modules can define platformCardInserted, as
long as the build system links exactly one into your application for any
given build target.
Victor suggested #ifdef'ing out the platform-specific line. If it
really is just a very small amount of platform-specific code, that may
be the best thing to do; however: (1) it still requires target-specific
behavior in the build system, to pass -DPLATFORM=WHATEVER, and (2) as
Victor pointed out, it requires a separate compilation, rather than a
separate link, for each platform.