Source in Header und cpp aufteilen
-
Hallo zusammen,
ich hab da mal ne Anfängerfrage. Ich habe ein Programm geschrieben und da ichs nicht besser wusste hab ich alles in die Header Datei reingeschmissen.
#ifndef _SOPAS_USB_HOST_ #define _SOPAS_USB_HOST_ #include <setupapi.h> #include "usbInterface.h"; extern "C" { #include <hidsdi.h> } class usbHost { public: usbHost( ); // ~usbHost( ); int getNumInterfaces( void ); bool getUsbInterface( int, usbInterface* ); bool getUsbInterface( int, int, TCHAR*, usbInterface* ); bool getInterfacePath( int, int, TCHAR*, TCHAR* ); private: int numInterfaces; int hidGetNumInterfaces( ); void hidGetUsbInterfaces( ); usbInterface* foundUsbInterfaces; }; bool usbHost::getUsbInterface( int number, usbInterface* usb_interface ) { *usb_interface = foundUsbInterfaces[number]; return ( number <= numInterfaces ); ... #endif }so in der Art kann man sich das vorstellen. Jetzt würde ich das ganze gerne in eine Header und in eine .cpp Datei unter VC++2005 aufteilen, nur wenn ich den Deklarationsteil in die cpp Datei packe, dann mault mir der Compiler vor
fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?was mach ich denn falsch?
(in der cpp Datei include ich dann nur noch den Header)
Grüße Nils
-
Du hast die vorkompilierte Headerdatei nicht ausgeschaltet, also musst du ganz zu Anfang in der cpp stdafx.h einbinden:
#include "stdafx.h" #include "meineHeader.h"Wenn du mal im Forum suchst solltest du auch fündig werden, wie man die vorkompilierte Header los wird (ich schalte sie grundsätzlich aus).
-
#ifndef _SOPAS_USB_HOST_ #define _SOPAS_USB_HOST_ #include "usbInterface.h"; class usbHost { public: usbHost( ); int getNumInterfaces( void ); ... }; #endif // _SOPAS_USB_HOST_Ok so sieht der Header jetzt aus, die cpp so:
#include "stdafx.h" #include "usbHost.h" #include <setupapi.h> extern "C" { #include <hidsdi.h> } bool usbHost::getUsbInterface( int number, usbInterface* usb_interface ) { *usb_interface = foundUsbInterfaces[number]; return ( number <= numInterfaces ); }aber irgendwie geht das trotzdem nicht

-
Hi,
schalte doch mal die "precompiled header" ab.
Mir machen die auch mehr Probleme als sie positiv bringen.Gruß,
Simon2.
-
Und "geht nicht" ist keine Fehlermeldung.
-
Also die neuen Fehlermeldungen sind:
1>------ Build started: Project: USB Create File, Configuration: Debug Win32 ------ 1>Compiling... 1>stdafx.cpp 1>Compiling... 1>USB Create File.cpp 1>c:\dokumente und einstellungen\deagga-prakti-asw\desktop\langner\c++ projekte\usb create file\usb create file\usbinterface.h(45) : warning C4996: 'wcscpy' was declared deprecated 1> c:\programme\microsoft visual studio 8\vc\include\wchar.h(992) : see declaration of 'wcscpy' 1> Message: 'This function or variable may be unsafe. Consider using wcscpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' 1>usbHost.cpp 1>c:\winddk\3790.1830\inc\wxp\setupapi.h(56) : error C2143: syntax error : missing ';' before '*' 1>c:\winddk\3790.1830\inc\wxp\setupapi.h(56) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\winddk\3790.1830\inc\wxp\setupapi.h(56) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\winddk\3790.1830\inc\wxp\commctrl.h(30) : error C2146: syntax error : missing ';' before identifier 'HRESULT' 1>c:\winddk\3790.1830\inc\wxp\commctrl.h(30) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\winddk\3790.1830\inc\wxp\commctrl.h(30) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\winddk\3790.1830\inc\wxp\prsht.h(98) : error C2065: 'CALLBACK' : undeclared identifier 1>c:\winddk\3790.1830\inc\wxp\prsht.h(98) : error C2065: 'LPFNPSPCALLBACKA' : undeclared identifier 1>c:\winddk\3790.1830\inc\wxp\prsht.h(98) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\winddk\3790.1830\inc\wxp\prsht.h(98) : fatal error C1903: unable to recover from previous error(s); stopping compilation 1>Build log was saved at "file://c:\Dokumente und Einstellungen\DEAGga-prakti-asw\Desktop\Langner\C++ Projekte\USB Create File\USB Create File\Debug\BuildLog.htm" 1>USB Create File - 10 error(s), 1 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========die bekomme ich auch, wenn ich precompiled headers ausschalte

-
da sind irgendwelche Macros nicht definiert vermute ich mla
muste mal schauen welche..unter windoof sind die Wichtigsten Macros:WINDOWS_LEAN_AND_MEAN WIN32 _WIN32 WINNT (NT_VERSION)Ich bin mir net 100% sicher ob das letzte richitg geschriebn ios. bite korrigiren wenn falsch.
MfG Shade3737