this is the error I am getting during linking:
main.obj : error LNK2001: unresolved external symbol "long __stdcall windowProcess(struct HWND__ *,unsigned int,unsigned int,long)" (?windowProcess##YGJPAUHWND__##IIJ#Z)
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/main.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
main.exe - 3 error(s), 0 warning(s)
here is my source code
#include <windows.h>
//#include <stdlib.h>
//#include <string.h>
#include "stdafx.h"
//1. Declaring windowProcess of type LRESULT
//2. WIN API
//3. WIndow Class
//4. Register Class
//5. Create Window
//6. Show Window
// The main window class name
const char myClassName[] = "myClass";
//1. Moving towards 1st step & showing the ass of Window Process
LRESULT CALLBACK windowProcess(HWND,UINT,WPARAM,LPARAM);
//2. Using win api
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevIntance,
LPSTR lpcmdLine,
int comandNumber){
WNDCLASS wc;
wc.style=CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc=windowProcess;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_APPLICATION));
wc.hbrBackground=NULL;
wc.lpszMenuName=NULL;
wc.lpszClassName=myClassName;
//3. Registering Wnd Class
if(!RegisterClass(&wc))
{
MessageBox(NULL,"Class didnot get registered","An Simple Window Application",NULL);
}
//hint=hInstance;
//4. registering window class
HWND hWnd=CreateWindow(myClassName,"Title f Window",WS_OVERLAPPEDWINDOW,0,0,500,100,NULL,NULL,hInstance,NULL);
if(!hWnd)
{
MessageBox(NULL,"window didnt created","An Simple Windw Application",NULL);
}
//5. Now after window has been created lets show this window
ShowWindow(hWnd,comandNumber);
UpdateWindow(hWnd);
return 1;
}//winapi WinMain function ends
The error tells you that the function
LRESULT CALLBACK windowProcess(HWND,UINT,WPARAM,LPARAM);
is only declared and defined nowhere.
Check Project props -> Linker -> System -> SubSystem.
Related
I'm trying to compile a Win32 app with MinGW, whose code can be found here. The source code compiles into an object just fine, but when I try and link it, this happens:
> gcc -o bin\updown.exe obj\updown.o -s -lcomctl32 -Wl,--subsystem,windows
obj\updown.o:updown.c:(.text+0x3ac): undefined reference to `StringCbPrintfW'
collect2.exe: error: ld returned 1 exit status
The only time this function appears is in the following snippet:
#include <windows.h>
#include <commctrl.h>
#include <strsafe.h>
...
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam) {
LPNMUPDOWN lpnmud;
UINT code;
switch(msg) {
...
case WM_NOTIFY:
...
const int asize = 4;
wchar_t buf[asize];
size_t cbDest = asize * sizeof(wchar_t);
StringCbPrintf(buf, cbDest, L"%d", value);
SetWindowText(hStatic, buf);
}
break;
...
}
...
}
Your project can define STRSAFE_LIB before including strsafe.h, and then link to strsafe.lib. Note that strsafe.h will use a #pragma comment(lib, "strsafe.lib") statement if STRSAFE_LIB is defined, but I don't know if that pragma works in MinGW or not, so you may have to link to the .lib manually.
#include <windows.h>
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR szCmdLine, int CmdShow)
{
MessageBoxW(NULL,szCmdLine, L"Title", MB_OK);
return 0;
}
I presume you're using Visual Studio. In project properties, under General, check Character Set. It should be Unicode.
With Unicode, the toolchain assumes your entry point is wWinMain, with multibyte it assumes WinMain.
I must use main() and call a function from windows.h.
The following code wants a WinMain() function to be used instead of main().
#include <windows.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
int vk_Shift = 16;
while (1)
{
if (GetAsyncKeyState(vk_Shift) < 0)
{
printf("Shift is pressed\n");
}
}
}
Error
Error 1 error LNK2019: unresolved external symbol _WinMain#16
referenced in function ___tmainCRTStartup
Error 2 error LNK1120: 1 unresolved externals
How can I get this work in VS2013?
Okay, guys, I got it.
Felix Palmen's advice works.
... ... I guess configuring it as "console" application should do the trick.
So, what I did is, I changed my project's preference from WIDOWS to CONSOLE.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm trying to compile an application from source code with Visual Studio 2015 Enterprise. I've run into some problems.
When I try to compile, I get several errors related to BOOL being an undefined type. I've tried including winmindef.h and windef.h to no avail. Here's some of the function declarations in the code that throw errors:
void GetCheatName ( int CheatNo, char * CheatName, int CheatNameLen );
BOOL LoadCheatExt ( char * CheatName, char * CheatExt, int MaxCheatExtLen);
void RefreshCheatManager ( void );
void SaveCheatExt ( char * CheatName, char * CheatExt );
BOOL TreeView_GetCheckState(HWND hwndTreeView, HTREEITEM hItem);
BOOL TreeView_SetCheckState(HWND hwndTreeView, HTREEITEM hItem, BOOL fCheck);`
When I include the following in the .h file, the problem is still not resolved
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
typedef int BOOL;
If it helps, I am trying to compile PJ64, and may need to change some setting in order to compile, but I'm not sure which.
Any help at all is appreciated!
---UPDATE---
Here are the complete compile errors (I've omitted most of the warnings):
1>cl : Command line warning D9007: '/Gm' requires '/Zi or /ZI'; option ignored
1> Cheat.c
1>Cheat.c(55): error C2059: syntax error: '<parameter-list>'
1>Cheat.c(56): error C2059: syntax error: '{'
1>Cheat.c(233): warning C4267: '=': conversion from 'size_t' to 'WORD', possible loss of data
1>Cheat.c(326): warning C4267: '=': conversion from 'size_t' to 'WORD', possible loss of data
1>Cheat.c(346): warning C4267: '=': conversion from 'size_t' to 'WORD', possible loss of data
1>Cheat.c(982): error C2059: syntax error: '<parameter-list>'
1>Cheat.c(998): error C2059: syntax error: '{'
1>Cheat.c(999): error C2449: found '{' at file scope (missing function header?)
1>Cheat.c(1012): error C2059: syntax error: '}'
The complete code for the project I am trying to compile can be found here.
This is -part- of the code that was compiled and threw the above errors. I've left the vast majority of the code out because it is too lengthy to include here. I've left comments indicating which lines threw errors.
#include <Windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <windef.h>
#include <stdio.h>
#include "main.h"
#include "cheats.h"
#include "cpu.h"
#include "resource.h"
#define UM_CHECKSTATECHANGE (WM_USER + 100)
#define UM_CHANGECODEEXTENSION (WM_USER + 101)
#define IDC_MYTREE 0x500
#define MaxCheats 300
#define SelectCheat 1
#define EditCheat 2
#define NewCheat 3
HWND hManageWindow = NULL;
HWND hSelectCheat, hAddCheat, hCheatTree;
CHEAT_CODES Codes[MaxCheats];
int NoOfCodes;
void GetCheatName ( int CheatNo, char * CheatName, int CheatNameLen );
BOOL LoadCheatExt ( char * CheatName, char * CheatExt, int MaxCheatExtLen);
void RefreshCheatManager ( void );
void SaveCheatExt ( char * CheatName, char * CheatExt );
BOOL TreeView_GetCheckState(HWND hwndTreeView, HTREEITEM hItem); //(line 55, error thrown.)
BOOL TreeView_SetCheckState(HWND hwndTreeView, HTREEITEM hItem, BOOL fCheck); //(line 56)
LRESULT CALLBACK ManageCheatsProc (HWND, UINT, WPARAM, LPARAM );
void ApplyCheats (void) {
//lots 'o code
}
BOOL CheatActive (char * Name) {
//more code
}
LRESULT CALLBACK CheatsCodeExProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
//Too much code to contain in this post...
}
LRESULT CALLBACK CheatsCodeQuantProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
//code
}
//Because of the inmensity of code, I will skip to the lines that throw errors.
BOOL TreeView_GetCheckState(HWND hwndTreeView, HTREEITEM hItem) { //line 982, error thrown.
//code here
}
BOOL TreeView_SetCheckState(HWND hwndTreeView, HTREEITEM hItem, BOOL fCheck) //line 999, error thrown
{ //line 1000, error thrown
//Lots o code
} // line 1013, error thrown
If more code is desired, I'll gladly post!
I've checked the code you gave a link to.
BOOL type is properly included. To check that you can compile Cheat.c with /P option.
All the problems are caused by upgrade of the project from Visual Studio 6 to Visual Studio 2015.
If you will investigate the pre-processor ouput you will see the transformation:
BOOL TreeView_GetCheckState(HWND hwndTreeView, HTREEITEM hItem); //(line 55, error thrown.)
BOOL TreeView_SetCheckState(HWND hwndTreeView, HTREEITEM hItem, BOOL fCheck); //(line 56)
pre-processed to:
BOOL ((((UINT)(SendMessageA((HWND hwndTreeView), (0x1100 + 39), (WPARAM)(HTREEITEM hItem), 0xF000))) >> 12) -1);
BOOL { TVITEMA _ms_TVi; _ms_TVi.mask = 0x0008; _ms_TVi.hItem = (HTREEITEM hItem); _ms_TVi.stateMask = (0xF000); _ms_TVi.state = ((((BOOL fCheck)?2:1) << 12)); SendMessageA((HWND hwndTreeView), (0x1100 + 13), 0, (LPARAM)(TVITEMA *)&_ms_TVi);};
It's not what you expect to see in your function declarations.
Both of these TreeView_GetCheckState and TreeView_SetCheckState are standard macroses defined in CommCtrl.h. Remove your old functions and use these macroses.
sendmessage callback error in visual studio 2012
I am recieving following errors in this C function?
error C2220: warning treated as error - no 'object' file generated
warning C4100: 'wParam' : unreferenced formal parameter
warning C4100: 'hwnd' : unreferenced formal parameter
LRESULT CALLBACK WndProc (HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_COPYDATA:
{
COPYDATASTRUCT* copy_data = (COPYDATASTRUCT*)(lParam);
const char* str = (const char* )(copy_data->lpData);
/* Also fixed the parameter list for "%.*s" */
printf("Message (%u): %.*s\n", copy_data->dwData, (int)copy_data->cbData, str);
}
}
}
The error is that you told the compiler to treat warnings as errors, and you have two warnings about arguments that is not used in the function.
The simplest solution is to actually skip naming those arguments, like so:
LRESULT CALLBACK WndProc (HWND, UINT message, WPARAM, LPARAM lParam)
For a solution working in C, then you have to actually use the arguments, even if you don't do anything with them. This can be done with e.g. using them in an expression and throw away the result, like
(void) hwnd;
(void) wParam;
Or use the macros defined in winnt.h (which should be included for you by default) for this:
UNREFERENCED_PARAMETER(hwnd);
UNREFERENCED_PARAMETER(wParam);
See e.g. this article.