-1

I try to compile a skeleton DLL in Visual C++ 2010. I disabled precompiled headers (I have reasons to do that) and compile DLL with one function with trivial body. However, compilation failed on file dllmain.cpp with a lot of errors like that:

\microsoft visual studio 10.0\vc\include\cstring(18): error C2039: 'memchr' : is not a member of '`global namespace''

My dllmain.cpp code follows:

// dllmain.cpp : Defines the entry point for the DLL application.
#include <Windows.h>

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

For me it looks like this code never calls any string-related functions, so why does Visual C++ access CString during its compilation at all and why does it search for memchr function? Compiler command line from log follows:

CL.exe  /c /ZI /nologo /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _WINDOWS /D _USRDLL /D MYDLL_EXPORTS /D _WINDLL /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MTd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt dllmain.cpp
Vitalii
  • 4,434
  • 4
  • 35
  • 77
  • 2
    Have you checked this answer http://stackoverflow.com/questions/531916/error-c2039-memchr-is-not-a-member-of-global-namespace ? – Zuljin May 02 '13 at 09:57
  • I can paste your code into an empty project and compile ok in Debug and Release. It's probably something related to @Zuljin's comment. – Roger Rowland May 02 '13 at 10:09
  • @Zuljin, thanks, you right, I have header, so it is the reason. It is still question why does C++ access it, I never reference this header in my code, but it is more question to Microsoft that to Stack Overlow. – Vitalii May 02 '13 at 10:25
  • `Windows.h` includes lots of stuff behind the scenes including some C standard library headers like `string.h` – Zuljin May 02 '13 at 10:47

1 Answers1

0

If you're baffled by such problems ask for the precompiled output and look at the error place in the .i file. You may discover the effect of some macro, or that the includes are missing or unexpected ones got picked up.

A lighter version is to turn on 'show includes' in C++/advanced.

Balog Pal
  • 16,195
  • 2
  • 23
  • 37