warning C4229: anachronism used : modifiers on data are ignored
The segment below is part of a larger function in a larger file. I have reduced it to what I think are the essentials for explaining my current problem.
I am using Visual Studio 2010.
The line with the call to RegConnectRegistryA is causing the compiler to warn me thusly: "warning C4229: anachronism used : modifiers on data are ignored". That is the only warning or error in the compiler output. The build does succeed, and the executable runs as expected. But I do want to get rid of that warning. (I think it's been there for many months, to be honest.)
extern "C" __declspec(dllexport) void whoOpsRegistryGetREG_SZ(
LPCSTR szServer,
LPCSTR szKey,
LPCSTR szValue,
char* szReturn,
int iSize)
{
HKEY hKey;
LONG WINAPI lReturn = ::RegConnectRegistryA(
szServer,
HKEY_LOCAL_MACHINE,
&hKey);
}
What I read in other posts leads me to believe that it is somehow related to the #includes. So here they are. If you need the contents of any of the header files in quotes, le开发者_如何学运维t me know.
#include "stdafx.h"
#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <objidl.h>
#include <wchar.h>
#include <stdio.h>
#include <stdarg.h>
#include <lm.h>
#include "whoOpsPrivate.h"
#include "whoOps.h"
#include "jni.h"
#include "whoOps_TaskScheduler.h"
#include "whoOps_ServiceMangler.h"
#include "whoOps_RegistryRaptor.h"
#include "../../cyclOps.h"
Thanks!
Looks to me like the problem is that WINAPI
is actually a calling convention (IIRC it turns out to mean stdcall
) so it makes no sense to apply that to the declaration of the variable lResult
. I don't have a Windows development environment handy to test, but I strongly suspect the warning would go away if you remove WINAPI
.
It is mostlikely because you are putting WINAPI on the variable declaration of lReturn
. WINAPI expands to __stdcall
which specifies a function call convention and has little no meaning on variable declarations.
The MSDN page on the warning indicates that using a Microsoft modifier on a data declaration is a dated/anachronistic practice. If a Microsoft data modifier is being used to modify something on that specific line, my best guess is that it's hidden in either the LONG or WINAPI macro.
I'm not familiar with the Windows API myself, so I can't speak from experience, but...apparently, the WINAPI macro is defined as __stdcall in windef.h. Unless you've called that same macro somewhere else without incident, I'd bet that's your culprit.
NM, beaten to it by two people. :p
精彩评论