ofstream << Fehler
-
Hallo,
ich habe folgenden C++ Code:
#include "stdafx.h" #include <windows.h> #include <iostream> #include <fstream> #include "COM.h" using namespace std; /******************************************/ /* made by */ /* */ /*mm mm y y n nnn oo n nnn a */ /*m m m m y y nn n o o nn n a a */ /*m m m y n n o o n n aaaaa*/ /*m m y n n oo n n a a*/ /* */ /* www.mynona.de.vu */ /******************************************/ HANDLE hCom; DWORD COMStatus; int ComPort::SetOPEN(int PORT) { /*if(PORT<=0||PORT>4) { return WRONG_PORT; }*/ char*CP[]={"COM1","COM2","COM3","COM4"}; hCom = CreateFile(CP[PORT-1], GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); return 0; } int ComPort::SetCLOSE() { CloseHandle(hCom); return 0; } int ComPort::SetDTR(bool mode) { if(mode==ON) { EscapeCommFunction(hCom, SETDTR); // setzen } else { EscapeCommFunction(hCom, CLRDTR); // Loeschen } return 0; } int ComPort::SetRTS(bool mode) { if(mode==ON) { EscapeCommFunction(hCom, SETRTS); // setzen } else { EscapeCommFunction(hCom, CLRRTS); // Loeschen } return 0; } int ComPort::SetTXD(bool mode) { if(mode==ON) { EscapeCommFunction(hCom, SETBREAK); // setzen } else { EscapeCommFunction(hCom, CLRBREAK); // Loeschen } return 0; } bool ComPort::GetCTS() { GetCommModemStatus(hCom, &COMStatus); if(COMStatus & MS_CTS_ON) { return TRUE; } return FALSE; } bool ComPort::GetDSR() { GetCommModemStatus(hCom, &COMStatus); if(COMStatus & MS_DSR_ON) { return ON; } return OFF; } void ComPort::SetAll (bool mode) { SetRTS(mode); SetTXD(mode); SetDTR(mode); } void blinke(ComPort comp, int anz, int millisek) { int i; for(i=0;i<anz;++i) { comp.SetRTS(TRUE); //Strom auf RTS-Leitung (LED leuchtet) Sleep((DWORD)millisek); //wartet millisek Millisekunden bis es weitergeht comp.SetRTS(FALSE); //Strom weg von RTS-Leitung (LED aus) Sleep((DWORD)millisek); } } void blinkeLED(int sek, int anz, int millisek) { ComPort comp; //erzeuge Objekt für Schnittstelle comp.SetOPEN(1); //Öffne COM1 (GND hat ab jetzt Strom) comp.SetDTR(TRUE); while(!comp.GetCTS()) //Prüft ob eine Taste gedrückt wurde { blinke(comp, anz, millisek); Sleep((DWORD)sek); //wartet sek Sekunden bis es weitergeht } comp.SetCLOSE(); //Schließt Schnittstelle (Alle Pins kein Strom) } void T() { while(true){ printf("Test"); Sleep((DWORD)100); } } void ShowMessage(const char arg[]){ printf(arg); } void ShutdownNTClick() { HANDLE token; TOKEN_PRIVILEGES tokenpriv; // Token für diesen Prozess holen if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token)==0) { ShowMessage("Fehler beim OpenProcessToken"); return; } // LUID für die Shutdown Privilege holen LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tokenpriv.Privileges[0].Luid); tokenpriv.PrivilegeCount=1; tokenpriv.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; // Shutdown privilege für diesen Prozess setzen if(AdjustTokenPrivileges(token, false, &tokenpriv, 0, (PTOKEN_PRIVILEGES)NULL, 0)==NULL) { ShowMessage("Fehler bei AdjustTokenPrivileges"); return; } // Windows beenden und Rechner ausschalten if(ExitWindowsEx(EWX_LOGOFF | EWX_POWEROFF, NULL)==NULL) { ShowMessage("Fehler beim ExitWindowsEx"); return; } } BOOL nServiceRunning = false; DWORD ServiceExecutionThread(LPDWORD param); HANDLE hServiceThread; ofstream ofile; bool logfileprint(char string[]){ if(ofile){ ofile << string << "\n"; cout << string << "\n"; } return true; } BOOL StartServiceThread() { DWORD id; hServiceThread=CreateThread(0,0, (LPTHREAD_START_ROUTINE)ServiceExecutionThread, 0,0,&id); if(hServiceThread==0) { return false; } else { nServiceRunning=true; return true; } } ComPort cp; DWORD ServiceExecutionThread(LPDWORD param) { Sleep(20); while(nServiceRunning){ ComPort cp; cp.SetTXD(TRUE); Sleep(500); cp.SetTXD(FALSE); cp.SetRTS(TRUE); Sleep(500); cp.SetRTS(FALSE); cp.SetDTR(TRUE); Sleep(500); cp.SetDTR(FALSE); } return (DWORD) 0; } void main(int argc, char* argv[]) { ofile.open("log.log", ios_base::out); cp.SetOPEN(1); cp.SetAll(FALSE); StartServiceThread(); while(true){ if(cp.GetCTS()) { logfileprint("CTS active.\n"); Sleep(1000); } if(cp.GetDSR()) { logfileprint("DSR active.\n"); Sleep(1000); } } cp.SetCLOSE(); }
und COM.h
/******************************************/ /* made by */ /* */ /*mm mm y y n nnn oo n nnn a */ /*m m m m y y nn n o o nn n a a */ /*m m m y n n o o n n aaaaa*/ /*m m y n n oo n n a a*/ /* */ /* www.mynona.de.vu */ /******************************************/ #define WRONG_PORT 100 #define ON true #define OFF false class ComPort { public: int SetOPEN (int PORT); int SetCLOSE (void); int SetDTR (bool mode); int SetRTS (bool mode); int SetTXD (bool mode); bool GetCTS (); bool GetDSR (); void SetAll (bool mode); };
Wennn ich jetzt kompliere, erhalte ich folgende Fehlermeldung:
------ Neues Erstellen gestartet: Projekt: COM_Test2, Konfiguration: Release Win32 ------ Die Zwischen- und Ausgabedateien für das Projekt "COM_Test2" mit der Konfiguration "Release|Win32" werden gelöscht. Kompilieren... stdafx.cpp Kompilieren... COM_Test2.cpp Verknüpfen... COM_Test2.obj : error LNK2019: Nicht aufgelöstes externes Symbol '"struct _iobuf * __cdecl std::_Fiopen(char const *,int,int)" (?_Fiopen@std@@YAPAU_iobuf@@PBDHH@Z)', verwiesen in Funktion '"public: class std::basic_filebuf<char,struct std::char_traits<char> > * __thiscall std::basic_filebuf<char,struct std::char_traits<char> >::open(char const *,int,int)" (?open@?$basic_filebuf@DU?$char_traits@D@std@@@std@@QAEPAV12@PBDHH@Z)' COM_Test2.obj : error LNK2019: Nicht aufgelöstes externes Symbol '"public: void __thiscall std::locale::facet::_Register(void)" (?_Register@facet@locale@std@@QAEXXZ)', verwiesen in Funktion '"class std::codecvt<char,char,int> const & __cdecl std::use_facet<class std::codecvt<char,char,int> >(class std::locale const &)" (??$use_facet@V?$codecvt@DDH@std@@@std@@YAABV?$codecvt@DDH@0@ABVlocale@0@@Z)' COM_Test2.obj : error LNK2019: Nicht aufgelöstes externes Symbol '"public: class std::locale::facet const * __thiscall std::locale::_Getfacet(unsigned int)const " (?_Getfacet@locale@std@@QBEPBVfacet@12@I@Z)', verwiesen in Funktion '"class std::codecvt<char,char,int> const & __cdecl std::use_facet<class std::codecvt<char,char,int> >(class std::locale const &)" (??$use_facet@V?$codecvt@DDH@std@@@std@@YAABV?$codecvt@DDH@0@ABVlocale@0@@Z)' COM_Test2.obj : error LNK2001: Nichtaufgelöstes externes Symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB) COM_Test2.obj : error LNK2019: Nicht aufgelöstes externes Symbol '"public: void __thiscall std::_String_base::_Xlen(void)const " (?_Xlen@_String_base@std@@QBEXXZ)', verwiesen in Funktion '"public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::append(unsigned int,char)" (?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ID@Z)' COM_Test2.obj : error LNK2019: Nicht aufgelöstes externes Symbol '"public: void __thiscall std::ios_base::_Addstd(void)" (?_Addstd@ios_base@std@@QAEXXZ)', verwiesen in Funktion '"protected: void __thiscall std::basic_ios<char,struct std::char_traits<char> >::init(class std::basic_streambuf<char,struct std::char_traits<char> > *,bool)" (?init@?$basic_ios@DU?$char_traits@D@std@@@std@@IAEXPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@_N@Z)' COM_Test2.obj : error LNK2001: Nichtaufgelöstes externes Symbol "__int64 std::_Fpz" (?_Fpz@std@@3_JA) COM_Test2.obj : error LNK2019: Nicht aufgelöstes externes Symbol '"public: void __thiscall std::_String_base::_Xran(void)const " (?_Xran@_String_base@std@@QBEXXZ)', verwiesen in Funktion '"public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::erase(unsigned int,unsigned int)" (?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z)' Release/COM_Test2.exe : fatal error LNK1120: 8 unaufgelöste externe Verweise Das Build-Protokoll wurde unter "file://c:\Dokumente und Einstellungen\Maximilian\Eigene Dateien\Visual Studio Projects\COM_Test2\Release\BuildLog.htm" gespeichert. COM_Test2 - 9 Fehler, 0 Warnung(en) ---------------------- Fertig ---------------------- Neues Erstellen: 0 erfolgreich, 1 fehlgeschlagen, 0 übersprungen
Woran liegt das?
-
Dieser Thread wurde von Moderator/in HumeSikkins aus dem Forum C++ in das Forum MFC (Visual C++) verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
Keiner ne Idee?
-
Wirklich keiner?
-
Schick mir doch mal das Projekt zu, dann kann ich mal reinschauen... jochen adddd kalmbachnet doottt de