so Im trying to use the zeromemory macro,and i included windows.h,but i get that error.Ideeas?
No target arhitecture error
Please post a minimal code example (including project settings) that replicates this error.
#include <Windows>
#include <XInput.h>
void GamePad::check_connection(){
for(DWORD i = 0; i < XUSER_MAX_COUNT && controllerID == -1;i++){
XINPUT_STATE state;
ZeroMemory(&state, sizeof(XINPUT_STATE));
if(XInputGetState(i,&state) == ERROR_SUCCESS)
controllerID = i;
}
}
i have no ideea what could cause this
There's a thread about it on MSDN here http://social.msdn.microsoft.com/Forums/vstudio/en-US/c88faa9b-3d66-4586-a2ec-6f1a6e34c882/win64-error-no-target-architecture?forum=vcgeneral but I couldn't see a definitive answer.
My solution would be this:
#include <Windows>
#include <XInput.h>
void GamePad::check_connection(){
for(DWORD i = 0; i < XUSER_MAX_COUNT && controllerID == -1;i++){
XINPUT_STATE state = {0}; // Does same thing as ZeroMemory
//ZeroMemory(&state, sizeof(XINPUT_STATE));
if(XInputGetState(i,&state) == ERROR_SUCCESS)
controllerID = i;
}
}
and let the compiler do it for you.
I always use that method to zero out structs on the stack. Maybe ZeroMemory can be slightly more optimised, I dunno, but surely the compiler can optimise it anyway? You'd have to look at the assembly output to see if there are any differences.
The = {0} thing always works if the struct has no constructors defined and is portable, and doesn't rely on macros or function calls. The reason it works is that if you don't initialise all members of a struct (or array) (EDIT: but you do provide an initialiser for at least one field) the rest get zero initialised, so if you zero initialise the first member everything gets zeroed.
I always use that method to zero out structs on the stack. Maybe ZeroMemory can be slightly more optimised, I dunno, but surely the compiler can optimise it anyway?
ZeroMemory is a macro that wraps memset.
{0} will try to call default constructors of the members. So the *code speed* depends on the structure.
Right I'd probably only recommend my way for POD structs then (which is basically everything in the Win32 API).
Not if you want your API to be compatible with C, which can be important. Win32 is all C anyway, even the COM (ActiveX) stuff has C bindings via macros.
You can use the preprocessor to exclude constructors and other C++ related stuff from C builds anyway.