How to solve a linker error with ExitWindowsEx in Windows.h - visual-studio-2010

I am recieving the following errors when I attempt to build and run my code in Visual Studio Express 2010:
1> Generating Code...
1>Purple Health.obj : error LNK2028: unresolved token (0A000035) "extern "C" int __stdcall ExitWindowsEx(unsigned int,unsigned long)" (?ExitWindowsEx##$$J18YGHIK#Z) referenced in function "private: void __clrcall PurpleHealth::FormOutOfTime::btnLogout_Click(class System::Object ^,class System::EventArgs ^)" (?btnLogout_Click#FormOutOfTime#PurpleHealth##$$FA$AAMXP$AAVObject#System##P$AAVEventArgs#4##Z)
1>FormLauncher.obj : error LNK2028: unresolved token (0A000031) "extern "C" int __stdcall ExitWindowsEx(unsigned int,unsigned long)" (?ExitWindowsEx##$$J18YGHIK#Z) referenced in function "private: void __clrcall PurpleHealth::FormOutOfTime::btnLogout_Click(class System::Object ^,class System::EventArgs ^)" (?btnLogout_Click#FormOutOfTime#PurpleHealth##$$FA$AAMXP$AAVObject#System##P$AAVEventArgs#4##Z)
1>FormLauncher.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall ExitWindowsEx(unsigned int,unsigned long)" (?ExitWindowsEx##$$J18YGHIK#Z) referenced in function "private: void __clrcall PurpleHealth::FormOutOfTime::btnLogout_Click(class System::Object ^,class System::EventArgs ^)" (?btnLogout_Click#FormOutOfTime#PurpleHealth##$$FA$AAMXP$AAVObject#System##P$AAVEventArgs#4##Z)
1>Purple Health.obj : error LNK2001: unresolved external symbol "extern "C" int __stdcall ExitWindowsEx(unsigned int,unsigned long)" (?ExitWindowsEx##$$J18YGHIK#Z)
1>C:\Users\Graham\documents\visual studio 2010\Projects\Purple Health\Debug\Purple Health.exe : fatal error LNK1120: 3 unresolved externals
My code looks like this (With the unimportant bits edited out):
#include "FormParentalOverride.h"
#include "Windows.h"
#include <iostream>
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#pragma once
namespace PurpleHealth {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Text;
public ref class FormOutOfTime : public System::Windows::Forms::Form
{
private: System::Void btnLogout_Click(System::Object^ sender, System::EventArgs^ e) {
ExitWindowsEx(EWX_LOGOFF, SHTDN_REASON_MAJOR_APPLICATION);
//ExitWindows(0, 0);
}
};
}
Any suggestions are greatly appreciated!

Add User32.dll to your link stage.
Note: Name is misleading inasmuch that the 64 and 32 bit versions are both called user32.

use #include< windows.h> instead of #include "Windows.h"

Related

C++ LNK2005 In Inline File

As the title suggests, I have an linker error relating to my inline file. It is complaining that my dungeon_layout header that includes my dungeon_room header(which includes the inl file) defines something twice. All my headers have guards, I only include .hpp files, and yet it still gets angry when I try and overload the assignment operator. The code which it complains is such:
Where I need assignment 1:
dungeon_room dungeon_layout::getCurrentRoom()
{
...
dungeon_room temp;
for (row = levelLayout.begin(); row != levelLayout.end(); row++)
{
for (col = row->begin(); col != row->end(); col++)
{
if (col->active)
{
...
temp = *col;
...
}
}
...
}
return temp;
}
Where I need assignment 2:
dungeon_room::dungeon_room()
{
...
roomMap = tim::tileMap(20, 20, 50);
...
}
Assignment Operator 1:
tileMap tim::tileMap::operator=(const tileMap& other)
{
// nothing...
}
Assignment Operator 2:
void dungeon_room::operator=(const dungeon_room& other)
{
// nothing...
}
Header for the Tile Manager (inl file definitions for functions)
#ifndef DUNGEON_ROOM_HPP
#define DUNGEON_ROOM_HPP
...
#include "gridManager\tileManager.hpp"
...
#endif
Header for the level layout
#ifndef DUNGEON_LAYOUT_HPP
#define DUNGEON_LAYOUT_HPP
...
#include "dungeon_room.hpp"
...
#endif
Error:
1>dungeon_room.obj : error LNK2005: "private: void __cdecl
tim::tileMap::addSprite(class sf::RectangleShape,unsigned __int64)" (?addSprite#tileMap#tim##AEAAXVRectangleShape#sf##_K#Z) already defined in dungeon_layout.obj
1>dungeon_room.obj : error LNK2005: "private: void __cdecl tim::tileMap::addSprite(class sf::Sprite,unsigned __int64)" (?addSprite#tileMap#tim##AEAAXVSprite#sf##_K#Z) already defined in dungeon_layout.obj
1>dungeon_room.obj : error LNK2005: "public: void __cdecl tim::tileMap::modifyTile(int,int,int)" (?modifyTile#tileMap#tim##QEAAXHHH#Z) already defined in dungeon_layout.obj
1>dungeon_room.obj : error LNK2005: "public: void __cdecl tim::tileMap::addCollisionValue(int)" (?addCollisionValue#tileMap#tim##QEAAXH#Z) already defined in dungeon_layout.obj
1>dungeon_room.obj : error LNK2005: "public: void __cdecl tim::tileMap::drawTiles(class sf::RenderWindow &,class sf::View &)" (?drawTiles#tileMap#tim##QEAAXAEAVRenderWindow#sf##AEAVView#4##Z) already defined in dungeon_layout.obj
1>dungeon_room.obj : error LNK2005: "public: void __cdecl tim::tileMap::drawTiles(class sf::RenderWindow *,class sf::View &)" (?drawTiles#tileMap#tim##QEAAXPEAVRenderWindow#sf##AEAVView#4##Z) already defined in dungeon_layout.obj
1>dungeon_room.obj : error LNK2005: "public: void __cdecl tim::tileMap::drawTiles(class sf::RenderWindow &)" (?drawTiles#tileMap#tim##QEAAXAEAVRenderWindow#sf###Z) already defined in dungeon_layout.obj
1>dungeon_room.obj : error LNK2005: "public: void __cdecl tim::tileMap::drawTiles(class sf::RenderWindow *)" (?drawTiles#tileMap#tim##QEAAXPEAVRenderWindow#sf###Z) already defined in dungeon_layout.obj
1>dungeon_room.obj : error LNK2005: "public: void __cdecl tim::tileMap::operator=(class tim::tileMap const &)" (??4tileMap#tim##QEAAXAEBV01##Z) already defined in dungeon_layout.obj
1>dungeon_room.obj : error LNK2005: "public: __cdecl tim::tileMap::tileMap(void)" (??0tileMap#tim##QEAA#XZ) already defined in dungeon_layout.obj
1>dungeon_room.obj : error LNK2005: "public: __cdecl tim::tileMap::tileMap(float,float,float)" (??0tileMap#tim##QEAA#MMM#Z) already defined in dungeon_layout.obj
1>F:\Desktop Files\C++\Games\Dungeon_Seeker\x64\Debug\Dungeon_Seeker.exe : fatal error LNK1169: one or more multiply defined symbols found
I believe that this should be the relevant code. I've been stuck, and debugging for a while now, and it's been annoying. Please help, thanks!
The reason you are getting these errors is because the function is being compiled for each .cpp file it has been compiled in, which is then being exported multiple times, once for each .cpp file that includes your inline file.
The .inl file that contains the definition is pasted into each of the .cpp files that includes it. Meaning, when the program is linked together, there is a definition of the function, that was supposed to only be defined once, in several files. This breaks the One Definition Rule and is the reason the linker is giving you that error.
To fix it, you have three options. First, you can mark the functions as inline, which does not necessarily make the compiler inline the function, but allows the function to be defined multiple times. Second, you can move the definition of the function inside the definition of the class, which implicitly marks the functions as inline. Or you can define the function in a .cpp file.
With you code, if you still want to have the functions declared in an .inl file you can put inline in front of the definitions of the function in the error messages. In this case those functions are
tim::tileMap::addSprite
tim::tileMap::modifyTile
tim::tileMap::addCollisionValue
tim::tileMap::drawTiles //All 4 overloads
tim::tileMap::operator=
tim::tileMap::tileMap //Both constructor overloads

Getting linking error 2019 although class is not derived from CString class in VS2010

i am getting the following error
error LNK2019: unresolved external symbol "public: class
ATL::CStringT > > __thiscall
CFILicenseSettings::GetCodeStartup1(void)"
(?GetCodeStartup1#CFILicenseSettings##QAE?AV?$CStringT#DV?$StrTraitMFC_DLL#DV?$ChTraitsCRT#D#ATL#####ATL##XZ)
referenced in function
__catch$?ValidateLicense#CFIServerDlg##AAE_NXZ$0 E:\TIMSWebServerManager_lic\TIMSWebServerManager\TIMSWebServerManager.obj TIMSWebServerManager
My function defination is as follows:
CString CFILicenseSettings::GetCodeStartup1()
{
CString a = "why";
return a;
}
the declaration of the function is as follows:-
CString GetCodeStartup1();
When i searched the web for the above error i found that this error is because my class is derived from CString class,but this is not the case.....
I get this error when i call the function GetCodeStartup1();
if i comment the calling of function GetCodeStartup1(); my program compile successfully
How can i remove the error?
Thanks in advance

Serial Ports in a .DLL file

I have created .dll file in Visual C++.
It includes a function which takes two arguments and send data through serial port. Next i wanted to include this .dll in my application and call these functions. But i am unable to call these functions. Kindly Help.
Here is header file for my .dll
namespace positioncontrol
{
using namespace std;
using namespace System;
using namespace System::IO::Ports;
public ref class control
{
static int rotate(char a, String^ b);
};
}
And here is .cpp for my .dll
#include "goniometer.h"
namespace positioncontrol
{
void control::rotate(char a, String^ b)
{ SerialPort^ serialPort = gcnew SerialPort(L"COM5",9600,Parity::None,1,StopBits::One);
int inp_rotation;
array<unsigned char>^ inp_c = gcnew array<unsigned char>(2);
String^ inp_string;
inp_c[0] = a;
inp_string= b;
inp_rotation=Int32::Parse(inp_string);
inp_c[1] = (unsigned char)inp_rotation;
serialPort->Write(inp_c,0,2);
}
}
I am using this .dll in a desktop application. I have include the header file
#ifndef goniometer_h
#define goniometer_h
#include "goniometer.h"
#endif
Added the path for include directories and added .dll as a reference.
Now i am using the function defined in .dll for a click event
private: System::Void button9_Click(System::Object^ sender, System::EventArgs^ e) {
char dir;
dir = 0x42;
String^ inp_string;
inp_string=enter_degree->Text;
positioncontrol::control::rotate(dir,inp_string);
}
Now when i build my desktop application i am getting following error
1>C:\Users\DELL\Desktop\Final\Motor_Dual_API\Debug\goniometer.h(10): error C2011: 'positioncontrol::control' : 'class' type redefinition
1> c:\users\dell\desktop\final\vc++dll\debug\goniometer.dll : see declaration of 'positioncontrol::control'
1>c:\users\dell\desktop\final\motor_dual_api\motor_next\Form1.h(530): error C2027: use of undefined type 'positioncontrol::control'
1> c:\users\dell\desktop\final\vc++dll\debug\goniometer.dll : see declaration of 'positioncontrol::control'
1>c:\users\dell\desktop\final\motor_dual_api\motor_next\Form1.h(530): error C3861: 'rotate': identifier not found
1>c:\users\dell\desktop\final\motor_dual_api\motor_next\Form1.h(540): error C2027: use of undefined type 'positioncontrol::control'
1> c:\users\dell\desktop\final\vc++dll\debug\goniometer.dll : see declaration of 'positioncontrol::control'
1>c:\users\dell\desktop\final\motor_dual_api\motor_next\Form1.h(540): error C3861: 'rotate': identifier not found
Kindly help me in figuring out error.
Thanks and Regards
In C++, the namespace separator is :: rather than .. Check your using statement.
Your code does not define serialPort. Add the definition to the global namespace, to the namespace positionControl or as an auto variable in your function
From the semantic point of view, serialPort is a pointer. So must also create an instance of the object, where serialPort points to.

Opencv2.1 application build in VS2010

I have an openCv application that builds and runs fine when using the Mutithreaded Debug Dll option for code generation property. However, I would like to run the application on any computer however, the build fails in Multithreaded Debug mode giving LNK 2005 errors, some examples are
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall
std::_Lockit::~_Lockit(void)" (??1_Lockit#std##QAE#XZ) already defined
in libcpmtd.lib(xlock.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall
std::_Lockit::_Lockit(int)" (??0_Lockit#std##QAE#H#Z) already defined
in libcpmtd.lib(xlock.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "void __cdecl
std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)"
(?_Debug_message#std##YAXPB_W0I#Z) already defined in
libcpmtd.lib(stdthrow.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall
std::_Container_base12::~_Container_base12(void)"
(??1_Container_base12#std##QAE#XZ) already defined in opencv2.obj
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: "public: __thiscall
std::exception::exception(class std::exception const &)"
(??0exception#std##QAE#ABV01##Z) already defined in
LIBCMTD.lib(stdexcpt.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: void
__thiscall std::_Container_base12::_Orphan_all(void)" (?_Orphan_all#_Container_base12#std##QAEXXZ) already defined in
opencv2.obj
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: __invalid_parameter
already defined in LIBCMTD.lib(invarg.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: __CrtDbgReportW already
defined in LIBCMTD.lib(dbgrptw.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: "public: __thiscall
std::exception::exception(char const * const &)"
(??0exception#std##QAE#ABQBD#Z) already defined in
LIBCMTD.lib(stdexcpt.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: "public: virtual
__thiscall std::exception::~exception(void)" (??1exception#std##UAE#XZ) already defined in
LIBCMTD.lib(stdexcpt.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _fclose already defined
in LIBCMTD.lib(fclose.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _fprintf already defined
in LIBCMTD.lib(fprintf.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _fopen already defined
in LIBCMTD.lib(fopen.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _memmove already defined
in LIBCMTD.lib(memmove.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _free already defined in
LIBCMTD.lib(dbgfree.obj)
Any suggestions would be appreciated. I am really stuck here, there is no problem with smaller programs
Thanks
P.S I also use functions from cvBlobslib and code from LIBSVM but it should not be the problem
If you change to use /MT and /MTd, then all your dependent libraries also need to have been compiled with these settings.
If this is not the case, then these dependencies require linking to the dynamic CRT and your project is trying to link to the static CRT, causing the "already defined" errors you're seeing.

Using PCL with Visual Studio 2010

I am quite new at working with libraries, and I have some problems.
I have installed PCL and all dependencies on my computer (Windows 7, 32 bit) and I can build and use simple examples like that "Simple Cloud Visualization" example. But if I want to use more complete sample, Visual Studio 2010 reports linking errors.
If I understand correctly, I did not 'include' all necessary "Additional Dependencies" in "Linker/Input". I tried to include all .lib files from lib directory, but the error report is still the same.
Does anyone know, which .lib should be added as "Additional Dependencies" to make more complete sample work? Or is problem somewhere else?
error report:
1>main.obj : error LNK2019: unresolved external symbol "public: class vtkProperty * __thiscall vtkActor::GetProperty(void)" (?GetProperty#vtkActor##QAEPAVvtkProperty##XZ) referenced in function "public: bool __thiscall pcl::visualization::PCLVisualizer::addSphere(struct pcl::PointXYZ const &,double,class std::basic_string,class std::allocator > const &,int)" (??$addSphere#UPointXYZ#pcl###PCLVisualizer#visualization#pcl##QAE_NABUPointXYZ#2#NABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z)
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl pcl::console::print(enum pcl::console::VERBOSITY_LEVEL,char const *,...)" (?print#console#pcl##YAXW4VERBOSITY_LEVEL#12#PBDZZ) referenced in function "public: bool __thiscall pcl::visualization::PCLVisualizer::addSphere(struct pcl::PointXYZ const &,double,class std::basic_string,class std::allocator > const &,int)" (??$addSphere#UPointXYZ#pcl###PCLVisualizer#visualization#pcl##QAE_NABUPointXYZ#2#NABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z)
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall vtkSmartPointerBase::~vtkSmartPointerBase(void)" (??1vtkSmartPointerBase##QAE#XZ) referenced in function "public: __thiscall vtkSmartPointer::~vtkSmartPointer(void)" (??1?$vtkSmartPointer#VvtkLODActor####QAE#XZ)
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall vtkSmartPointerBase::vtkSmartPointerBase(void)" (??0vtkSmartPointerBase##QAE#XZ) referenced in function "public: __thiscall vtkSmartPointer::vtkSmartPointer(void)" (??0?$vtkSmartPointer#VvtkLODActor####QAE#XZ)
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall vtkSmartPointerBase::vtkSmartPointerBase(class vtkSmartPointerBase const &)" (??0vtkSmartPointerBase##QAE#ABV0##Z) referenced in function "public: __thiscall vtkSmartPointer::vtkSmartPointer(class vtkSmartPointer const &)" (??0?$vtkSmartPointer#VvtkProp####QAE#ABV0##Z)
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall vtkSmartPointerBase::vtkSmartPointerBase(class vtkObjectBase *)" (??0vtkSmartPointerBase##QAE#PAVvtkObjectBase###Z) referenced in function "public: __thiscall vtkSmartPointer::vtkSmartPointer(class vtkSmartPointer const &)" (??$?0VvtkLODActor###?$vtkSmartPointer#VvtkProp####QAE#ABV?$vtkSmartPointer#VvtkLODActor#####Z)
1>main.obj : error LNK2019: unresolved external symbol "public: class vtkSmartPointerBase & __thiscall vtkSmartPointerBase::operator=(class vtkObjectBase *)" (??4vtkSmartPointerBase##QAEAAV0#PAVvtkObjectBase###Z) referenced in function "public: class vtkSmartPointer & __thiscall vtkSmartPointer::operator=(class vtkSmartPointer const &)" (??$?4VvtkLODActor###?$vtkSmartPointer#VvtkProp####QAEAAV0#ABV?$vtkSmartPointer#VvtkLODActor#####Z)
Probably you installed the wrong PCL version (64 bit / 32 bit). Check your VS version and install PCL accordingly. Note that even if you are using a 64 bit system, your compiler may be working in 32 bit.

Resources