-
LNK2001 Error ?
I get the LNK2001 linking error when trying to build this code in MSVC++5
I have looked at the help files and i think it has something to do with Extern variables or something, but i dont understand why? The code compiles with 0 errors and 0 warnings
here is the code as i cant seem to post attachements yet :(
///////////////////////////////////////////////////////////////////////////////////
MAIN.CPP
#include <windows.h>
#include "generic.h"
HINSTANCE hInst; // current instance
LPCTSTR lpszAppName = "Generic";
LPCTSTR lpszTitle = "Generic";
BOOL RegisterWin95(CONST WNDCLASS* lpwc);
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg; //message
HWND hWnd; //windows handler
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = 0;
wc.hIcon = LoadIcon(hInstance,lpszAppName);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = lpszAppName;
wc.lpszClassName = lpszAppName;
if (!RegisterWin95(&wc))
return false;
hInst = hInstance;
hWnd = CreateWindow(lpszAppName,lpszTitle,
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,
CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
if (!hWnd)
return false;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
BOOL RegisterWin95(CONST WNDCLASS* lpwc)
{
WNDCLASSEX wcex;
wcex.style = lpwc->style;
wcex.lpfnWndProc = lpwc->lpfnWndProc;
wcex.cbClsExtra = lpwc->cbClsExtra;
wcex.hInstance = lpwc->hInstance;
wcex.hIcon = lpwc->hIcon;
wcex.hCursor = lpwc->hCursor;
wcex.hbrBackground = lpwc->hbrBackground;
wcex.lpszMenuName = lpwc->lpszMenuName;
wcex.lpszClassName = lpwc->lpszClassName;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.hIconSm = LoadIcon(wcex.hInstance,"SMALL");
return RegisterClassEx(&wcex);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_TEST :
break;
case IDM_EXIT :
DestroyWindow(hWnd);
break;
}
break;
case WM_DESTROY :
PostQuitMessage(0);
break;
default :
return(DefWindowProc(hWnd,uMsg,wParam,lParam));
}
return(0L);
}
///////////////////////////////////////////////////////////////////////////////////
Here is "generic.h"
#define IDM_EXIT 100
#define IDM_TEST 200
#define IDM_ABOUT 300
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK About (HWND,UINT,WPARAM,LPARAM);
////////////////////////////////////////////////////////////////////////////////////
Please please someone try this code out in MSVC++ 5 or later and see what my problems are? Or even point me in the direction of a solution?
Thanks for your time.
-
When you get an linker error, it normally specifies what function can't be found. Without you posting this I'm not sure where the problem is, but it's probably your project settings. Make sure your linking it as a Win32 application and not a Win32 console application.
-
Compiles and links okay with VC++ 6.0 Pro on NT4.
-
Ok, thx adrianxw
Hmm it works in MSCV++6 but not 5, perhaps its my project settings.. :(
Ill check the settings out.. im pretty sure its nothing to do with a function or code as it compiles clean. :confused:
thx all
-
Off topic, I like the name.
kamikazeecows
Reminds me of something I read in the news a few years back.
A Japanese trawler had to pull into Russian harbour after serious damage nearly caused it to sink.
Appears that they were hit by a couple of cows. Try explaining that to customs.
Later it was revealed that some rustlers had used a cargo plane to load up a herd of cows. During the flight the cows got spooked. To save the plane the rustlers opened up the rear door and let the cows out over the ocean.
It was a reputable news paper so could be true.
-
Haha nice story
Haha thanks, glad to someone appreciates besides me :p
Me and my friend made up stupid names like this for hotmail addresses and this was my one, his was something like destructivepanda, or something like that, we had loads written down somewhere, haha ill look for them sometme and post em if u wish.
As to the problem i posted above i still havent solved it yet and its plaguing me !!! :(
Ah well ill work it out soon enough...
-
I'll have another look at it tomorrow.
-
Try changing
APIENTRY
to
PASCAL
I use APIENTRY for DLL's, PASCAL for exe.
Does the complier tell you what function / var is causing the error?
-
I did this, try the same...
Open VC++
File->New->choose workspace Tab->give it a name, (I called it abc), and click OK.
File->New-> choose project Tab if it is not already chosen, and select "Win32 Application" - NOT Win32 Console App or any of the others->give it a name, (again I called it abc), and check the "Add to current workspace" radio button, then click OK. On the next screen select "An empty project" for the application type. If it gives you another screen saying that no files will be created just say OK.
File->New-> choose Files Tab, if it is not already chosen, and select "C/C++ Header File" -> give it the name generic.h and click OK.
Cut and paste these lines into the new header file...
#define IDM_EXIT 100
#define IDM_TEST 200
#define IDM_ABOUT 300
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK About (HWND,UINT,WPARAM,LPARAM);
File->New choose Files Tab, if it is not already chosen, and select "C/C++ Source File" -> give it a name, (abc) and click OK.
Cut and paste these lines into the new source file...
#include <windows.h>
#include "generic.h"
HINSTANCE hInst; // current instance
LPCTSTR lpszAppName = "Generic";
LPCTSTR lpszTitle = "Generic";
BOOL RegisterWin95(CONST WNDCLASS* lpwc);
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg; //message
HWND hWnd; //windows handler
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = 0;
wc.hIcon = LoadIcon(hInstance,lpszAppName);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = lpszAppName;
wc.lpszClassName = lpszAppName;
if (!RegisterWin95(&wc))
return false;
hInst = hInstance;
hWnd = CreateWindow(lpszAppName,lpszTitle,
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,
CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
if (!hWnd)
return false;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
BOOL RegisterWin95(CONST WNDCLASS* lpwc)
{
WNDCLASSEX wcex;
wcex.style = lpwc->style;
wcex.lpfnWndProc = lpwc->lpfnWndProc;
wcex.cbClsExtra = lpwc->cbClsExtra;
wcex.hInstance = lpwc->hInstance;
wcex.hIcon = lpwc->hIcon;
wcex.hCursor = lpwc->hCursor;
wcex.hbrBackground = lpwc->hbrBackground;
wcex.lpszMenuName = lpwc->lpszMenuName;
wcex.lpszClassName = lpwc->lpszClassName;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.hIconSm = LoadIcon(wcex.hInstance,"SMALL");
return RegisterClassEx(&wcex);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_TEST :
break;
case IDM_EXIT :
DestroyWindow(hWnd);
break;
}
break;
case WM_DESTROY :
PostQuitMessage(0);
break;
default :
return(DefWindowProc(hWnd,uMsg,wParam,lParam));
}
return(0L);
}
Now press F7...
When I do, I get
Compiling...
abc.cpp
Linking...
abc.exe - 0 error(s), 0 warning(s)
Try this, and tell me what happens.
-
Ah thx
Thx so much ill try out these things later when i get home, thx !
-
IT WORKS
Hey Zen, Andrewxw thanks so much for the information, it WORKS !
It was the simple case of doing what you said andrexw
I can now go on with my project and get some work done ! :p
Cheers.
Now for the tough bit....
-
>>> Now for the tough bit....
What's that, admitting that you got my name wrong? ;)
LOL. Good luck!!!!!!