Solved

Error in building

Posted on 2006-06-21
22
428 Views
Last Modified: 2013-11-20
While trying to build my project it gives me the following error: HookManagerDlg.obj : error LNK2001: unresolved external symbol "char const * __cdecl GetMsgName(unsigned int)" (?GetMsgName@@YAPBDI@Z)
msvcrtd.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
Debug/HookManagerDlg.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

Can somebody tell me how to fix this?
0
Comment
Question by:afos21
  • 9
  • 9
  • 3
  • +1
22 Comments
 
LVL 5

Expert Comment

by:marcodalzotto
ID: 16952482
GetMsgName is it your own function?

Can you post the headers of HookManagerDlg (.h and .c)?
0
 
LVL 86

Expert Comment

by:jkr
ID: 16952726
Try to declare that function as

extern "C"
char const * __cdecl GetMsgName(unsigned int);

Could be a C++ be a name mangling problem.
0
 

Author Comment

by:afos21
ID: 16953403
// HookManagerDlg.h : header file
//

#if !defined(AFX_HOOKMANAGERDLG_H__72BF8F27_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_)
#define AFX_HOOKMANAGERDLG_H__72BF8F27_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// CHookManagerDlg dialog

class CHookManagerDlg : public CDialog
{
// Construction
public:
      CHookManagerDlg(CWnd* pParent = NULL);      // standard constructor

// Dialog Data
      //{{AFX_DATA(CHookManagerDlg)
      enum { IDD = IDD_HOOKMANAGER_DIALOG };
      CEdit            m_edCountPlb;
      CEdit            m_edCountRec;
      CEdit            m_edRevFile;
      CButton      m_btOpen;
      CButton      m_btSave;
      CButton      m_chDoClear;
      CButton      m_chNoMouse;
      CButton      m_btPlayBk;
      CButton      m_btRecord;
      //}}AFX_DATA

      CString m_sRevFile;

      void StartRecorder();
      void Stop_Recorder();

      void StartPlayBack();
      void Stop_PlayBack();

      void Cleanup();

      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CHookManagerDlg)
      public:
      virtual BOOL PreTranslateMessage(MSG* pMsg);
      protected:
      virtual void DoDataExchange(CDataExchange* pDX);      // DDX/DDV support
      //}}AFX_VIRTUAL

// Implementation
protected:
      HICON m_hIcon;

      // Generated message map functions
      //{{AFX_MSG(CHookManagerDlg)
      virtual BOOL OnInitDialog();
      virtual void OnOK() {}
      virtual void OnCancel() {};
      afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
      afx_msg void OnPaint();
      afx_msg HCURSOR OnQueryDragIcon();
      afx_msg void OnBtExit();
      afx_msg void OnBtRecord();
      afx_msg void OnBtPlayBack();
      afx_msg void OnClose();
      afx_msg void OnBtOpen();
      afx_msg void OnBtSave();
      //}}AFX_MSG
      afx_msg LONG OnServiceInfo      (WPARAM,LPARAM);
      DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_HOOKMANAGERDLG_H__72BF8F27_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_)


0
 
LVL 3

Expert Comment

by:komar
ID: 16958231
I guess GetMsgName() is a function belonging to a library you use in your project, is that true? Or did you write it your self?

Anyway, find the c or cpp file that has the implementation (body) of the GetMsgName() function and add it to your project (Goto Project -> Add To Project -> Files). You can use the IDE to do the search for you (Goto Edit -> Find In Files, and put GetMsgName in the "Find what" filed. Make sure the "In folder" filed displays the root folder of your project or the library you are using if any).
0
 
LVL 3

Expert Comment

by:komar
ID: 16958240
By the way, I was working on a project called "HookManager" when I read your question :-) My project also has a CHookManagerDlg class in it :-))
0
 

Author Comment

by:afos21
ID: 16962037
Thanx for your help komar. I followed your tips and the error was corrected but now i received another.

c:\program files\microsoft visual studio\vc98\mfc\include\afxv_w32.h(14) : fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>
Error executing cl.exe.

any idea of what that might would be?
0
 
LVL 5

Assisted Solution

by:marcodalzotto
marcodalzotto earned 100 total points
ID: 16962916
probably you have a windows.h inclusion in your .cpp or .h. You should delete it. Windows.h is included in the afx...h in the stdafx.h header.
0
 
LVL 3

Expert Comment

by:komar
ID: 16963936
Hello afos21, glad to hear that my comment helped.

I agree with marcodalzotto. Find where in the source files (c, cpp, h) the file windows.h is included. You can use the above "Find In Files" technique to locate all instances of the string (windows.h) and comment or delete these lines.
0
 

Author Comment

by:afos21
ID: 16964123
That's what i thought in the first place as well. The problem is that windows.h does not exist in ay file, that's why i decided to post it here.
0
 
LVL 3

Expert Comment

by:komar
ID: 16964320
Maybe one or more of your source files has an include to another header that internally include windows.h

Can you post all the includes in your stdafx.h here? Also any other includes from other cpp's and h's?
0
 

Author Comment

by:afos21
ID: 16968343
stdafx.h
#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxdtctl.h>            // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>                  // MFC support for Windows Common Controls
--------------------------------------------------------------------------------
hookmanager.h
#include "resource.h"
--------------------------------------------------------------------------------
// HookService.cpp
//

#include "stdafx.h"
#include "malloc.h"

#include "HookService.h"
--------------------------------------------------------------------------------
// HookManagerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "HookManager.h"
#include "HookManagerDlg.h"

#include "HookService.h"
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Expert Comment

by:komar
ID: 16968529
- All seem ok. What about the includes inside .h files, can you list them here?
- What about the includes inside the file that has GetMsgName() implementation.
- Do you see the same error in both debug and release configuration.
- Try removing the file you recently added (the file that has GetMsgName() implementation) and compile (Release and Debug) and tell me what you see.
0
 

Author Comment

by:afos21
ID: 16969886
stdafx.h
#if !defined(AFX_STDAFX_H__72BF8F29_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_)
#define AFX_STDAFX_H__72BF8F29_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers

#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxdtctl.h>            // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>                  // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT


//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STDAFX_H__72BF8F29_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_)

That's how it exactly looks like!!!
--------------------------------------------------------------------------
// HookManagerDlg.cpp : implementation file (which includes the getmsgname function)
//

#include "stdafx.h"
#include "HookManager.h"
#include "HookManagerDlg.h"

#include "HookService.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


struct S_SAVE_EVENTMSG
{
      S_SAVE_EVENTMSG() { memset(this,0,sizeof(S_SAVE_EVENTMSG)); }

      UINT  message;
      UINT  paramL;
      UINT  paramH;
      DWORD time;
};

static char BASED_CODE szFilter[] = "Macros Files (*.rev)|*.rev|All Files (*.*)|*.*||";

extern LPCSTR GetMsgName(UINT nCode);

Komar i followed your advice and the result was the same. It gives me the same error
0
 
LVL 5

Expert Comment

by:marcodalzotto
ID: 16970062
I've tried to include windows.h in my MFC project, and comile without problems... maybe some compiler options?
Make secure you have #pragma once as a first line of every MFC class .h. I have it in mine.
0
 
LVL 3

Expert Comment

by:komar
ID: 16971137
Hello afos21. Again, all seem OK.

- You did not post the contents of the file that has the implementation of GetMsgName() function. The one you posted above has the declaration only.
- Use the same "Find In Files" technique described above to find all instances of the word "include" and post everything you see in the find window (bottom of the IDE) here.

Thanks,
Khalid.
0
 

Author Comment

by:afos21
ID: 16971247

C:\Senior\HookManager_src\HookManager.cpp(4):#include "stdafx.h"
C:\Senior\HookManager_src\HookManager.cpp(5):#include "HookManager.h"
C:\Senior\HookManager_src\HookManager.cpp(6):#include "HookManagerDlg.h"
C:\Senior\HookManager_src\HookManager.h(4):#if !defined(AFX_HOOKMANAGER_H__72BF8F25_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_)
C:\Senior\HookManager_src\HookManager.h(5):#define AFX_HOOKMANAGER_H__72BF8F25_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_
C:\Senior\HookManager_src\HookManager.h(12):      #error include 'stdafx.h' before including this file for PCH
C:\Senior\HookManager_src\HookManager.h(15):#include "resource.h"            // main symbols
C:\Senior\HookManager_src\HookManager.h(49):#endif // !defined(AFX_HOOKMANAGER_H__72BF8F25_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_)
C:\Senior\HookManager_src\HookManager.rc(3):#include "resource.h"
C:\Senior\HookManager_src\HookManager.rc(8):// Generated from the TEXTINCLUDE 2 resource.
C:\Senior\HookManager_src\HookManager.rc(10):#include "afxres.h"
C:\Senior\HookManager_src\HookManager.rc(27):// TEXTINCLUDE
C:\Senior\HookManager_src\HookManager.rc(30):1 TEXTINCLUDE DISCARDABLE
C:\Senior\HookManager_src\HookManager.rc(35):2 TEXTINCLUDE DISCARDABLE
C:\Senior\HookManager_src\HookManager.rc(37):    "#include ""afxres.h""\r\n"
C:\Senior\HookManager_src\HookManager.rc(41):3 TEXTINCLUDE DISCARDABLE
C:\Senior\HookManager_src\HookManager.rc(53):    "#include ""res\\HookManager.rc2""  // non-Microsoft Visual C++ edited resources\r\n"
C:\Senior\HookManager_src\HookManager.rc(54):    "#include ""afxres.rc""         // Standard components\r\n"
C:\Senior\HookManager_src\HookManager.rc(213):// Generated from the TEXTINCLUDE 3 resource.
C:\Senior\HookManager_src\HookManager.rc(225):#include "res\HookManager.rc2"  // non-Microsoft Visual C++ edited resources
C:\Senior\HookManager_src\HookManager.rc(226):#include "afxres.rc"         // Standard components
C:\Senior\HookManager_src\HookManagerDlg.cpp(4):#include "stdafx.h"
C:\Senior\HookManager_src\HookManagerDlg.cpp(5):#include "HookManager.h"
C:\Senior\HookManager_src\HookManagerDlg.cpp(6):#include "HookManagerDlg.h"
C:\Senior\HookManager_src\HookManagerDlg.cpp(8):#include "HookService.h"
C:\Senior\HookManager_src\HookManagerDlg.h(4):#if !defined(AFX_HOOKMANAGERDLG_H__72BF8F27_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_)
C:\Senior\HookManager_src\HookManagerDlg.h(5):#define AFX_HOOKMANAGERDLG_H__72BF8F27_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_
C:\Senior\HookManager_src\HookManagerDlg.h(78):#endif // !defined(AFX_HOOKMANAGERDLG_H__72BF8F27_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_)
C:\Senior\HookManager_src\HookService.cpp(4):#include "stdafx.h"
C:\Senior\HookManager_src\HookService.cpp(5):#include "malloc.h"
C:\Senior\HookManager_src\HookService.cpp(7):#include "HookService.h"
C:\Senior\HookManager_src\MsgDefs.cpp(1):#include "stdafx.h"
C:\Senior\HookManager_src\StdAfx.cpp(1):// stdafx.cpp : source file that includes just the standard includes
C:\Senior\HookManager_src\StdAfx.cpp(5):#include "stdafx.h"
C:\Senior\HookManager_src\StdAfx.h(1):// stdafx.h : include file for standard system include files,
C:\Senior\HookManager_src\StdAfx.h(2)://  or project specific include files that are used frequently, but
C:\Senior\HookManager_src\StdAfx.h(6):#if !defined(AFX_STDAFX_H__72BF8F29_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_)
C:\Senior\HookManager_src\StdAfx.h(7):#define AFX_STDAFX_H__72BF8F29_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_
C:\Senior\HookManager_src\StdAfx.h(15):#include <afxwin.h>         // MFC core and standard components
C:\Senior\HookManager_src\StdAfx.h(16):#include <afxext.h>         // MFC extensions
C:\Senior\HookManager_src\StdAfx.h(17):#include <afxdtctl.h>            // MFC support for Internet Explorer 4 Common Controls
C:\Senior\HookManager_src\StdAfx.h(19):#include <afxcmn.h>                  // MFC support for Windows Common Controls
C:\Senior\HookManager_src\StdAfx.h(26):#endif // !defined(AFX_STDAFX_H__72BF8F29_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_)
C:\Senior\HookManager_src\resource.h(2):// Microsoft Developer Studio generated include file.
0
 
LVL 3

Expert Comment

by:komar
ID: 16975412
One again all seem OK. None of the includes in your project directly or indirectly include windows.h!

You should ask your self the following questions?
- What was the last thing you made before this error started to appear.
- What happens if you remove the cpp file that has GetMsgName() implementation. Does the error disapper. If yes, then please show me the contents of this file. If no, then this issue should be posted in a different question because the original issue is resolved.

Thanks,
Khalid.
0
 
LVL 3

Expert Comment

by:komar
ID: 16990659
Hello afos21.
Please see this: http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21900127.html

It might help you get rid of the windows.h thing. I suggest doing a rebuild all on the project because sometimes the information in the pre-compiled headers (PCH) are old and yet still there!

Good luck.
Khalid.
0
 

Author Comment

by:afos21
ID: 17027311
#if !defined(AFX_HOOKMANAGER_H__72BF8F25_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_)
#define AFX_HOOKMANAGER_H__72BF8F25_0402_11D5_B5B5_FFA54F5F1A7B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
      #error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"            // main symbols
 

this definition is included in the header file of my main application. Is it suppose to look like that?
0
 

Author Comment

by:afos21
ID: 17031247
Ok, one last thing that might be the problem. If it doesn't help then i will close this thread, give the points and open a new one. When trying to open the workspace, i have two workspaces. The Hookmanager.dsw and HookmanagerDlg.dsw. Is it supposed to be like this? Should they suppose to be in just one workspace together?
0
 
LVL 3

Accepted Solution

by:
komar earned 400 total points
ID: 17033405
>> Is it supposed to be like this?

You should have one .dsw file in general. The other .dsw does not necessarily mean your project has problems. It may be that the other .dsw is for another project or maybe an older version of the same project. Try opening the other .dsw and compile. Maybe that will fix your problem.

By the way, are you using the HookManager code for codeproject.com. If yes, then try downloading the source again and apply whatever changes you made to the source again because that code compiles without errors as far as I remember.

- Khalid.
0
 

Author Comment

by:afos21
ID: 17051614
Thanx komar. Is just my stupiditily the problem to this thread. 400 pts for komar and 100 for marcodalzotto
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now