Jump to content
  • Advertisement
Sign in to follow this  
Makoy

Linking error

This topic is 5450 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

First of all, Hello Gamedev! I would like to ask for help because I'm having trouble linking this code of mine. I tried compiling it but it seems to work fine. But when I tried linking it, it displays two errors. Linking... LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/window.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. window.exe - 2 error(s), 0 warning(s) This is my code. Please do take a look at it. Thanks in advance :)
[sourcecode]
#include<d3dx9.h>             

#define D3DFVF_D3DVertex (D3DFVF_XYZ|D3DFVF_DIFFUSE)

// Here are our Direct3D objects.  The first is used to get access to Direct3D
// and the second will be used to render to the screen.
LPDIRECT3D9 Direct3D_Object = NULL;
LPDIRECT3DDEVICE9 D3D_Device = NULL;



// This is the Windows procedure (WndProc).  This handles messages that the
// windows operating sends to your application.
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
       {
		   case WM_KEYUP:
            // If the user presses the escape key then exit the application.
            if(wParam == VK_ESCAPE)
               PostQuitMessage(0);
            break;

         case WM_DESTROY:
         case WM_CLOSE:
            PostQuitMessage(0);
            break;

            default:
               break;
       }

    return DefWindowProc( hwnd, message, wParam, lParam );
}


// This is the WinMain class.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
   HWND hwnd;                 // Handle to the window.
   WNDCLASSEX windowClass;    // Window class object.
   bool done = false;         // Used to test if the app is running or not.

   // This is the Window class.
   windowClass.cbSize = sizeof(WNDCLASSEX);           // size of the WNDCLASSEX structure.
   windowClass.style = CS_HREDRAW | CS_VREDRAW;       // style of the window.
   windowClass.lpfnWndProc = WndProc;                 // Address to the windows procedure.
   windowClass.cbClsExtra = 0;                        // Extra class information.
   windowClass.cbWndExtra = 0;                        // Extra window information.
   windowClass.hInstance = hInstance;                 // Handle of application Instance.
   windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);// Window Icon.
   windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Load mouse cursor.
   windowClass.hbrBackground = NULL;                  // Background color.
   windowClass.lpszMenuName = NULL;                   // Menu.
   windowClass.lpszClassName = "UGPClass";            // Name of the window class.
   windowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);// Minimized window icon.

   // You must register you class with Windows.
   if(!RegisterClassEx(&windowClass))
      return 0;

   // Create the window.
   hwnd = CreateWindowEx(NULL,      // The extended window style.
                         "UGPClass",// Window class.
                         "Direct3D Tutorial by The Programming Ace",// Window name.
                          WS_OVERLAPPEDWINDOW | WS_VISIBLE |         // Window style.
                          WS_SYSMENU |WS_CLIPCHILDREN |              // Window style.
                          WS_CLIPSIBLINGS,                           // Window style.
                          100, 100,                                  // X, Y coords.
                          400, 400,                                  // Window size.
                          NULL,                                      // Handle to parent window.
                          NULL,                                      // Menu.
                          hInstance,                                 // Handle to app instance.
                          NULL);                                     // Pointer to window.


   // If there was an error with creating the window, then close the program.
   if(!hwnd)
      return 0;


   ShowWindow(hwnd, SW_SHOW);    // Show the window.
   UpdateWindow(hwnd);           // Update its display.


   done = false;  // false = run program, true means stop.
   return 0;
}
[/sourcecode]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by dhanji
you probably created a Windows Console app, when you should be creating a Windows Application.

Yep, exactly. Remember, main() is the entry function for all console applications, and WinMain() is the entry funcion for all windows applications.

Also, before you exit the application, make sure you destroy your winclass with a call to UnregisterClass(). Like this:


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HWND hwnd; // Handle to the window.
WNDCLASSEX windowClass; // Window class object.

... All your code here

UnregisterClass( "UGPClass", hInstance );
return 0;
}

Share this post


Link to post
Share on other sites
Quote:

Yep, exactly. Remember, main() is the entry function for all console applications, and WinMain() is the entry funcion for all windows applications.

Also, before you exit the application, make sure you destroy your winclass with a call to UnregisterClass(). Like this:



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HWND hwnd; // Handle to the window.
WNDCLASSEX windowClass; // Window class object.

... All your code here

UnregisterClass( "UGPClass", hInstance );
return 0;
}


Bro have you checked my code? I got it in one of the tutorials. I just pasted it in a new sheet and saved as windows.cpp. I have no trouble compiling it but when I linked it, that's where the problem occured.

Share this post


Link to post
Share on other sites
Quote:
Original post by Makoy
Bro have you checked my code? I got it in one of the tutorials. I just pasted it in a new sheet and saved as windows.cpp. I have no trouble compiling it but when I linked it, that's where the problem occured.
Yes, this is not a problem with your code. It's a problem with your project. You created a Win32 Console project, instead of just a plain Win32 project.

Also, remember to add the call to UnregisterClass().

Share this post


Link to post
Share on other sites
Quote:
Original post by circlesoft
Also, before you exit the application, make sure you destroy your winclass with a call to UnregisterClass(). Like this:

You don't have to do this. According to MSDN (doc page for UnregisterClass):
Quote:
Remarks

...

All window classes that an application registers are unregistered when it terminates.

...

Share this post


Link to post
Share on other sites
Quote:

Yes, this is not a problem with your code. It's a problem with your project. You created a Win32 Console project, instead of just a plain Win32 project.


So my friend are you saying that I should create a project first then add the cpp file to the project?

Share this post


Link to post
Share on other sites
Quote:
Original post by Makoy
Quote:

Yes, this is not a problem with your code. It's a problem with your project. You created a Win32 Console project, instead of just a plain Win32 project.


So my friend are you saying that I should create a project first then add the cpp file to the project?
Yep, exactly [smile]. Make sure it's a Win32 Project, and not a Win32 Console Project.

Quote:
You don't have to do this. According to MSDN (doc page for UnregisterClass)
...
Ah, okay I didn't know that it wasn't required. However, it's still good programming practice. You shouldn't resort to the operating system to clean up a mess that *you* made.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!