Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile Error - Simple Win32 Program

Status
Not open for further replies.

neos

Programmer
Oct 28, 2000
36
CA
I wrote this prorgam, but when I try and compile I get the error "Unresolved external '_main' referenced from D:\BORLAND\BCC55\LIB\COX32.OBJ". The compile does generate the .obj, and .tds files, but not the .exe. Here is the program:

#define STRICT
#include <windows.h>

LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
switch (iMsg) {
case WM_LBUTTONDOWN:
MessageBox(hWnd, &quot;Left mouse button pressed&quot;, &quot;6E69636F6C65282A29&quot;, MB_OK);
return 0;
case WM_RBUTTONDOWN:
MessageBox(hWnd, &quot;Right mouse button pressed&quot;, &quot;6E69636F6C65282A29&quot;, MB_OK);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, int iCmdShow) {
const char *const szAppName = &quot;Windows&quot;;
WNDCLASSEX wndclass;
HWND hWnd;
MSG msg;

wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

RegisterClassEx(&wndclass);

hWnd = CreateWindow(szAppName, &quot;Windows&quot;, WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);

while (GetMessage(&msg, NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
 
In plain language, compile it with:
bcc32 -tW myprog
instead of:
bcc32 myprog
This makes the compiler create a Windows vs a DOS-style exe file.
 
as zBuilder mentioned, you're not compiling it properly, create a new project of type Win32 GUI, then compile it, the way you have it set up, it's looking for main(){} not WinMain(){}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top