Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a console application in c++ that Works, but in VC++ forms application I get the following errors, any idea how to correct it?
error :
Error 6 error LNK2028: unresolved token (0A000013) "extern "C" struct HDC__ * __stdcall GetDC(struct HWND__ *)" (?GetDC@@$$J14YGPAUHDC__@@PAUHWND__@@@Z) referenced in function "private: void __clrcall sysinfo::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@sysinfo@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) sysinfo.obj sysinfo

note I have included <windows.h> in stdafx.h of the project
code
C++
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 
			  double i,c,d,f,g,k;
			  char l; 
			  HDC hdc = GetDC(GetDesktopWindow());
    DWORD ret = GetDeviceCaps(hdc, HORZSIZE);
    DWORD ret2 = GetDeviceCaps(hdc, VERTSIZE);
   // std::cout << "Your screen size in inches is " << ret/25.4 << "\" x " << ret2/25.4 << "\" \n";
    ReleaseDC(GetDesktopWindow(), hdc);


I have to use variables for hdc etc.?
Posted
Comments
Richard MacCutchan 6-Dec-14 9:14am    
That is because you have not included the Windows DLL that handles those API calls. However, as Philippe points out below, this is the wrong way to do it. If you want to create a very basic Windows application then do not use Winforms in C++. Use the template provided with Visual Studio, and add the appropriate code in the WM_PAINT handler.

1 solution

Are you sure that you want to use Win API directly? One of the main advantage of WinForms is that it abstract the API so you almost never need it.

I think that you can uses WinForms classes like Screen Class[^].

Otherwise, you need to properly configure your project options to link the appropriate libraries. By the way, using 2 technology might cause some conflicts so you might need to uses distinct precompiled files or distinct projects and properly adjust compiler and linker options.

I would recommand to uses a separate DLL for the stuff that access the API if your application use the API a lot as it should help minimize conflict and improve the maintainability if you decide to not use the API directly anymore in the future since those calls would be isolated.

In pratice, you should very rarely need to use the API directly in typical WinForms applications particulary for common stuff like GDI.

Neverthless, the following links might help you :

http://msdn.microsoft.com/en-us/library/9z5820hw(v=vs.110).aspx[^]
http://msdn.microsoft.com/en-us/library/System.Drawing.Graphics(v=vs.110).aspx[^]
 
Share this answer
 
Comments
Member 3892343 6-Dec-14 11:16am    
Thank you, the reason is that I am not expert in C++ but I like to code the "old" way. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900