0

I have a VS2010 Win32 console application. Within this console application I try to attach a window as child to another Win32 app. But I do not get the application linked (it compiles, just the linker issue AFAIK):

Error   1   error LNK2019: unresolved external symbol "long __stdcall viewproc(struct HWND__ *,unsigned int,unsigned int,long)" (?viewproc@@YGJPAUHWND__@@IIJ@Z) referenced in function "void __cdecl createFSXWindow(void)" (?createFSXWindow@@YAXXZ)  H:\Projects\VisualStudioNet2010\FSXTests\Menu Items\Menu Items\MenuItems.obj    Menu Items

I have added all libs from a Win32 Windows project under Linker/include:

kernel32.lib;user32.lib;gdi32.lib;winspool.lib; comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib; odbccp32.lib;%(AdditionalDependencies)

Remark: Just to clarify, I do NOT(!) try to attach the window to the console window, but another Win32 application, so it is not about "Make a win32 console app display a window"

The issue comes in once I add the window code such as:

#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>
....

// window
WNDCLASSEX wc;
wc.style = CS_HREDRAW | CS_VREDRAW ;
wc.lpfnWndProc = viewproc;

When I check the command line of the linker the only difference between my console app and an Win32 app is SUBSYSTEM:CONSOLE vs. SUBSYSTEM:WINDOWS

Any hints?

Community
  • 1
  • 1
Horst Walter
  • 13,663
  • 32
  • 126
  • 228

1 Answers1

2

The linker error just tells you that you forgot to write the viewproc() function.

You declared it, the compiler is happy, but didn't implement it, the linker is unhappy. Or you wrote it but mistyped the definition. It is not a function that's implemented in one of the standard libraries, you have to provide it. The window procedure is what you use to give a window custom behavior.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Gosh, lucky me since wc.lpfnWndProc was just in the above code example by chance. I was looking in the wrong direction, thanks! – Horst Walter Jun 11 '12 at 18:00