0
votes

Here is a simple example for DHCP client API, https://msdn.microsoft.com/en-us/library/windows/desktop/aa363345(v=vs.85).aspx

I'm working in Visual Studio 2012 with console application c++, it has a failure when building:

1>------ Build started: Project: ConsoleApplication2, Configuration: Debug Win32 ------

1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

1>D:\visual work place\ConsoleApplication2\Debug\ConsoleApplication2.exe : fatal error LNK1120: 1 unresolved externals

Can anybody know how to solve this problem?, thanks

1
you don't have a main in the example.Jean-François Fabre

1 Answers

0
votes

There are lots of hits when Google-ing this error. Here's one.

There's a mismatch between your C code and your VStudio project type.

Your app's entrypoint is probably int main(int argc, char **argv) (this is one of its most general forms) which in MS world is corresponding to a Console application.

But MS has defined other application types. One of them is a GUI (window based) which doesn't require a console. For that one MS defined an entrypoint as: int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow). You can find more details about it on MSDN.

When building the application's executable, the linker must know what type the application has. That is specified by the /SUBSYSTEM setting.

That is set when you create your (Visual C++) project based on your choice:

  • Win32 Console Application
  • Win32 Project

And I think the latter is the default.

In order to fix things, you need to change your linker setting to match your code (well there could be the other way around too, but that would be more complicated). In order to do that, in VStudio IDE go to your Project Properties -> Linker -> System -> SubSystem and change it from Windows (/SUBSYSTEM:WINDOWS) to Console (/SUBSYSTEM:CONSOLE).