help solve linking problem, thanks

This is a discussion on help solve linking problem, thanks within the Windows Programming forums, part of the Platform Specific Boards category; Hi i am new to win32 programming and have written a program that creates a simple window pane that does ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    133

    help solve linking problem, thanks

    Hi i am new to win32 programming and have written a program that creates a simple window pane that does nothing except to exit.

    There is some linking problem i experience which i dont have know how to solve. I hope someone is able to debug this for me. The file is compiled under VC++

    I will post the code here, let me know if u need the other files such as resource definitions:


    stdSDK.h
    Code:
    #if !defined (stdSDK_H)
    #define stdSDK_H
    
    #define STRICT				// Enable strict type-checking of Windows handles
    #include <windows.h>			// Fundamental Windows header file
    #include <windowsx.h>		// Useful Windows programming extensions
    #include <commctrl.h>		// Common Controls declarations
    #include <tchar.h>
    #include "resource.h"
    
    #include "Extensions.h"         // WINDOWSX.H extensions
    
    #include "Utility.h"            // Application-independent
                                    //  debugging and utility functions
    #endif

    pane.cpp
    Code:
    #include "stdSDK.h"
    
    HWND createMainWindow(HINSTANCE hinst, int nCmdShow)
    {
    	HWND hwnd;
    	TCHAR ClassName[MAX_RESOURCESTRING+1];
    	TCHAR title[MAX_RESOURCESTRING+1];
    
    	// load class name into ClassName
    	VERIFY(LoadString(hinst,IDR_MAINWINDOW,ClassName,DIM(ClassName)));
    	// load title name into title
    	VERIFY(LoadString(hinst,IDS_TITLE,title,DIM(title)));
    
    	hwnd = CreateWindowEx(0,			// extended window style
    						  ClassName,	// class name
    						  title,		// title
    						  WS_OVERLAPPEDWINDOW,	// window style
    						  CW_USEDEFAULT,		// default x-pos of window			
    						  0,	// y-pos of window, set 0 and use showWindow() to determine later
    						  400,	// width of window	
    						  400,	// height of window
    						  NULL, // parent of window
    						  LoadMenu(hinst, MAKEINTRESOURCE(IDR_MAINWINDOW)),	// handle of menu
    						  hinst,	//handle of application
    						  NULL);	// user defined parameters, hardly any use for it
    	if(!hwnd)
    		return NULL;
    	
    	// make window appear
    	ShowWindow(hwnd,nCmdShow);
    	// force window to update
    	UpdateWindow(hwnd);
    
    	return hwnd;
    }
    
    void mainWindow_onDestroy(HWND hwnd)
    {
    	PostQuitMessage(0);
    }
    
    void mainWindow_onCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
    {
    
    	switch(id)
    	{case ID_FILE_EXIT:	DestroyWindow(hwnd);
    					return;
    	default: FORWARD_WM_COMMAND(hwnd,id,hwndCtl,codeNotify,DefWindowProc);
    }
    
    }
    
    LRESULT CALLBACK wndProc(HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)
    {
    	switch(message)
    	{
    	case WM_DESTROY:	// when window is close,
    					return HANDLE_WM_DESTROY (hwnd,wParam,lParam,mainWindow_onDestroy);
    	case WM_COMMAND:   // when user select an item in the menu
    					return HANDLE_WM_COMMAND (hwnd,wParam,lParam,mainWindow_onCommand);
    
    	default: return DefWindowProc(hwnd, message, wParam, lParam);
    	}
    }
    
    // NOTE: DIFFERENCE BETWEEN WM_DESTROY AND WM_CLOSE
    // WM_CLOSE REFERS THAT THERE IS REQUEST TO CLOSE THE WINDOW
    // W_DESTROY REFERS THAT THE WINDOW IS CLOSED
    
    bool registerWindowClasses(HINSTANCE hinst, UINT resPoolID)
    {
    	
    	WNDCLASSEX wc;
    	TCHAR ClassName[MAX_RESOURCESTRING+1];
    
    	// load class name into ClassName
    	VERIFY(LoadString(hinst,resPoolID,ClassName,DIM(ClassName)));
    
    	// fill in window classs structure with parameters that describe the main window
    	wc.cbSize = sizeof(WNDCLASSEX);
    	wc.style = CS_HREDRAW | CS_VREDRAW ;
    	wc.lpfnWndProc = (WNDPROC) wndProc;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = hinst;
    	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
    	wc.lpszMenuName = MAKEINTRESOURCE(resPoolID);
    	wc.lpszClassName = ClassName;
    	wc.hIconSm = LoadIcon(NULL,IDI_WINLOGO);
    
    	// register class into Windows and return the ATOM result
    	// 0 if fail
    	if(RegisterClassEx(&wc))
    	return true;
    	else return false;
    }
    	
    bool  initInstance(HINSTANCE hinst, UINT resPoolID, int nCmdShow)
    {
    	// register window class
    	if(!registerWindowClasses(hinst,resPoolID))
    		return false;
    	
    	// initialize common controls DLL
    	// you must call this function beofre using any common control
    	InitCommonControls();
    
    	// create the application's main frame window
    	if(!createMainWindow(hinst,nCmdShow))
    	return false;
    
    	return true;
    }
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow)
    {
    	MSG msg;
    	
    	// instance initialization
    	if(!initInstance(hInstance,IDR_MAINWINDOW,nCmdShow))
    		return 0;
    
    	// GetMessage() :
    	// first parameter stores the message obtained from message loop
    	// second parameter specify the window handle for which to retrieve a msg
    	// if second parameter is NULL, the next message belonging to the application is obtained
    	// 3rd and 4th specify the range of message to obtain
    	// GetMessage() return 0 when WM_QUIT is retrieved
    
    	while(GetMessage(&msg,NULL,0,0))
    	{TranslateMessage(&msg); // translate the virtual keys for WinProc to intepret
    	 DispatchMessage(&msg); // send message to WinProc
    	}
    
    	return msg.wParam;
    
    }

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    Menu: Project -> Settings -> Link (tab) -> Input (category) -> Object/Library modules:
    Append: comctl32.lib

    Post the actual errors you get next time.

    gg

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    133

    sorry

    oops, it slipped my mind.

    PHP Code:
    Linking...
    pane.obj error LNK2001unresolved external symbol "int __cdecl assertFailedOnLine(char const *,int)" (?assertFailedOnLine@@YAHPBDH@Z)
    pane.obj error LNK2001unresolved external symbol __imp__InitCommonControls@0
    LIBCD
    .lib(crt0.obj) : error LNK2001unresolved external symbol _main
    Debug
    /pane.exe fatal error LNK11203 unresolved externals
    Error executing link
    .exe.

    pane.exe 4 error(s), 0 warning(s

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    133
    sorry, i added the library(it solved the initCommonControls() problem) and there are still problems:

    --------------------Configuration: pane - Win32 Debug--------------------
    Compiling...
    pane.cpp
    Linking...
    pane.obj : error LNK2001: unresolved external symbol "int __cdecl assertFailedOnLine(char const *,int)" (?assertFailedOnLine@@YAHPBDH@Z)
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/pane.exe : fatal error LNK1120: 2 unresolved externals
    Error executing link.exe.

    pane.exe - 3 error(s), 0 warning(s)

  5. #5
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135
    error LNK2001: unresolved external symbol _main
    I'd say you've created a console application. The compiler is expecting WinMain as the entry point not main. You can change this after creating the project. In VC++ 7 its under the Linker/subsystem tab. You need to change this to /SUBSYSTEM:WINDOWS instead of /SUBSYSTEM:CONSOLE.

    The other error, i'm not sure about.

  6. #6
    Registered User
    Join Date
    Sep 2003
    Posts
    133

    Last error

    Thanks dalek. I must have clicked the win32 console for project by accident. So close to my first own application. Someone pls give this newbie some hope.

    --------------------Configuration: pane - Win32 Debug--------------------
    Compiling resources...
    Compiling...
    pane.cpp
    Linking...
    pane.obj : error LNK2001: unresolved external symbol "int __cdecl assertFailedOnLine(char const *,int)" (?assertFailedOnLine@@YAHPBDH@Z)
    Debug/pane.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    pane.exe - 2 error(s), 0 warning(s)

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    The other one is most likely from your use of VERIFY(), which is an MFC macro.

    Remove all uses of VERIFY() for the time being...

    gg

  8. #8
    Registered User
    Join Date
    Sep 2003
    Posts
    133
    Cool! It worked, thanks to ur brillance.
    As far as i know, verify is a macro that can check the return value of LoadString. Any idea why it didnt work there? Or perhaps it's not time for me to know that at my level(i have no knowledge of MFC).

  9. #9
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    VERIFY() is the same as ASSERT() except the code is not removed in non-debug builds, just the verification.

    You can use it if you want to, you'll just have to link in MFC libs. Say "Use MFC in a Static Library" in VC++6.0 projects settings.

    gg
    Last edited by Codeplug; 05-29-2004 at 11:16 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 09-14-2008, 06:17 PM
  2. Problem I Can't solve...
    By ferniture in forum C Programming
    Replies: 3
    Last Post: 07-15-2008, 02:51 AM
  3. Grrr.... SDL Linking Problem
    By 7EVEN in forum Game Programming
    Replies: 5
    Last Post: 08-12-2005, 08:44 PM
  4. DJGPP linking problem
    By Saleop in forum C++ Programming
    Replies: 1
    Last Post: 07-03-2005, 05:58 PM
  5. Replies: 2
    Last Post: 04-25-2005, 11:59 AM

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