• Advertisement

Archived

This topic is now archived and is closed to further replies.

Strange Error message

This topic is 5656 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

I was trying to compile a .cpp file with the free borland compiler and I got this error message. Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland WinTut.cpp: Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland Error: Unresolved external ''_main'' referenced from C:\BORLAND\BCC55\LIB\C0X32.OBJ what does it mean and how can i fix it?

Share this post


Link to post
Share on other sites
Advertisement
You have created a Console application which requires a main function.. ie.

void main()
{
}

whereas a windows application uses

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{

}

Share this post


Link to post
Share on other sites
But it wont compile so what do i do heres the whole code:

#ifndef _WINDOWS_ // if windows.h is not included...
#include <windows> // include it!
#endif
#include "WinTut.h" //include WinTut header file


WinTut::WinTut(HINSTANCE hIns)
{
hInst = hIns;

winTutWndCls.cbSize = sizeof(WNDCLASSEX);
winTutWndCls.style = NULL;
winTutWndCls.lpfnWndProc = WndProc;
winTutWndCls.cbClsExtra = 0;
winTutWndCls.cbWndExtra = 0;
winTutWndCls.hInstance = hInst;
winTutWndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winTutWndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
winTutWndCls.hbrBackground = (HBRUSH)(COLOR_WINDOW);
winTutWndCls.lpszMenuName = NULL;
winTutWndCls.lpszClassName = "WinTutClass";
winTutWndCls.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&winTutWndCls))
{
MessageBox(NULL, "Grrr!\nCould not register window class!", "ERROR", MB_OK | MB_ICONERROR);
}

hWnd = CreateWindowEx(WS_EX_APPWINDOW, "WinTutClass", "WinTut!", WS_OVERLAPPEDWINDOW, 0, 0, 300, 400, NULL, NULL, hInst, NULL);

if(hWnd == NULL)
{
MessageBox(NULL, "Could not create Window! ", "ERROR", MB_OK | MB_ICONERROR);
}
}

void WinTut::show(void)
{
ShowWindow(hWnd, SW_SHOW);
}



int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
{

MSG Msg;

WinTut mainWindow(hInst);
mainWindow.show();

while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;

}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{

case WM_CLOSE:

DestroyWindow(hWnd);

break;

case WM_DESTROY:

PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

Share this post


Link to post
Share on other sites
I think what you need is

bcc32 -W file.cpp

Add the -W will cause the linker to link windows start up code.

Hope this helps.

Share this post


Link to post
Share on other sites

  • Advertisement