0

I am trying to compile Microsoft Detours in Visual Studio 2013 ( not interested in compiling it through command prompt as suggested in many sites )

There is specific cpp file uimports.cpp which by itself will not compile since it does not have any headers but uses win api.

developers of detours including this file based on specific preprocessor definitions in other cpp file, logically since the file is copied as is there need not be any warning since all the win api required definitions exists in the other cpp file (e.g. creatwth.cpp):

#if DETOURS_32BIT
#define DWORD_XX                        DWORD32
#define IMAGE_NT_HEADERS_XX             IMAGE_NT_HEADERS32
#define IMAGE_NT_OPTIONAL_HDR_MAGIC_XX  IMAGE_NT_OPTIONAL_HDR32_MAGIC
#define IMAGE_ORDINAL_FLAG_XX           IMAGE_ORDINAL_FLAG32
#define UPDATE_IMPORTS_XX               UpdateImports32
#define DETOURS_BITS_XX                 32
#include "uimports.cpp"
#undef DETOUR_EXE_RESTORE_FIELD_XX
#undef DWORD_XX
#undef IMAGE_NT_HEADERS_XX
#undef IMAGE_NT_OPTIONAL_HDR_MAGIC_XX
#undef IMAGE_ORDINAL_FLAG_XX
#undef UPDATE_IMPORTS_XX
#endif // DETOURS_32BIT

#if DETOURS_64BIT
#define DWORD_XX                        DWORD64
#define IMAGE_NT_HEADERS_XX             IMAGE_NT_HEADERS64
#define IMAGE_NT_OPTIONAL_HDR_MAGIC_XX  IMAGE_NT_OPTIONAL_HDR64_MAGIC
#define IMAGE_ORDINAL_FLAG_XX           IMAGE_ORDINAL_FLAG64
#define UPDATE_IMPORTS_XX               UpdateImports64
#define DETOURS_BITS_XX                 64
#include "uimports.cpp"
#undef DETOUR_EXE_RESTORE_FIELD_XX
#undef DWORD_XX
#undef IMAGE_NT_HEADERS_XX
#undef IMAGE_NT_OPTIONAL_HDR_MAGIC_XX
#undef IMAGE_ORDINAL_FLAG_XX
#undef UPDATE_IMPORTS_XX
#endif // DETOURS_64BIT 

I am missing some compiler flag that will hint visual studio to ignore errors in uimports.cpp. or any other logical solution beside redefining the headers in uimports.cpp just to help visual studio.

4
  • Have you trued adding the preprocessor macro DETOURS_32BIT or DETOURS_64BIT to see if these errors go away? Presumably the original make file had these macros defined Commented Sep 12, 2014 at 8:08
  • Yes , i added those from start Commented Sep 12, 2014 at 8:09
  • 1
    nothing to do with VS. That's just a Fancy front-end to CL. If you look at the advanced settings on the compiler tab it shows you the compiler flags that will be passed to CL, same for the linker. Ensure the relevant onea are the same as those used in the makefile. Commented Sep 12, 2014 at 8:29
  • Than i'll simply copy the one function defined in uimports inside both define blocks, and remove the file - checked it , it works although ugly. Commented Sep 12, 2014 at 9:14

1 Answer 1

1

There are two possible solutions to this, assuming that uiImports.cpp is never supposed to be compiled "free-standing".

The first is to right click on the file in Solution Explorer, and select the "Exclude from Project" option. That will cause Visual Studio to remove it from the list of files, and it won't get compiled directly. The one downside to this is that it becomes harder to edit the file, since you can't just double click it in Solution Explorer to open it.

The other is a bit more messy, but keeps it in the solution, so it can easily be edited.

Place the following line at the top:

#ifndef DONT_COMPILE_ME

with a corresponding

#endif

at the bottom.

Then right click the file in Solution Explorer, hit properties, C/C++, Preprocessor, and add DONT_COMPILE_ME to the Preprocessor Definitions.

Sign up to request clarification or add additional context in comments.

1 Comment

Liked the second creative solution +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.