I have a linker problem when compiling my Win32 project written in C.
My Linker Errors
1.)Error 1 error LNK2001: unresolved external symbol "void __cdecl InitButtonControl(void)" (?InitButtonControl@@YAXXZ)
2.)Error 2 error LNK1120: 1 unresolved externals
My Little Project is to create a
Win32 Custom Control using Child Windows
. Really a
button
. There're
2
source files in my project:
1.
button.c
- contains window procedure and some other stuff about the button.
2.
main.c
- contains the
WinMain
function and a Dialog Procedure to test the control.
Code of BUTTON.C
#include "button.h"
LRESULT CALLBACK ButtonProc(HWND hwnd,UINT msg,WPARAM w,LPARAM ww)
{
return DefWindowProc(hwnd,msg,w,ww);
}
void InitButtonControl()
{
WNDCLASSEX wc;
wc.cbSize = sizeof(wc);
wc.lpszClassName = szButtonClass;
wc.hInstance = GetModuleHandle(0);
wc.lpfnWndProc = ButtonProc;
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hIcon = 0;
wc.lpszMenuName = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.style = 0;
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof( ButtonInfo * );
wc.hIconSm = 0;
RegisterClassEx(&wc);
}
Code of MAIN.C
#include <Windows.h>
#include "resource.h"
#include "button.h"
BOOL CALLBACK DlgProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
InitButtonControl();
DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,DlgProc);
return 0;
}
BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
case IDOK:
PostMessage(hwnd,WM_CLOSE,0,0);
break;
}
return TRUE;
case WM_CLOSE:
EndDialog(hwnd,0);
return TRUE;
}
return FALSE;
}
The Place of the problem in Code
I'm sure that the problem is in the
InitButtonControl()
function in BUTTON.C source file. I figured it out by simply commenting the
InitButtonControl()
function call in
WinMain
[see MAIN.c].
Please Help me to solve the problem ! I've been trying for days.
############QUESTION IMPROVEMENT#########
Hey I found the Big Problem. I copies all of my source files and started a new project. Then Compiled it. Then my program worked nicely. So there is no problem with my source code, i'm pretty sure.
So, definitely the case is with the compiler. Maybe with the compiler settings. Please Need Help !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
########################################
Further Information:
OS : Windows 7
Compiler : MS Visual C++ 2010
Architecture : 64-bit