Gå til innhold

Problem med kompilering av program: Mangler windows.h (Visual C++ Express)


Anbefalte innlegg

Hei!

 

Jeg tenkte jeg skulle prøve meg på OpenGL, så jeg kjøpte Denne boka. Nå er jeg ferdig med å skrive det første eksempelet i Visual C++ Express, og jeg skulle kompilere det:

 

#include <windows.h>

HWND Window;

LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 switch (msg)
 {
   case WM_DESTROY: PostQuitMessage(0); break;
 }
 return (DefWindowProc(hWnd, msg, wParam, lParam));
}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevious, LPSTR LpCmdString, CmdShow)
{
 WNDCLASS wc;
 MSG      msg;

 WNDCLASS wc;
 wc.cbClsExtra = 0;
 wc.cbWndExtra = 0;
 wc. hbrBackground = (HBRUSH)GetStockObject(LTGREY_BRUSH);
 wc.hCursor = LoadCursor (NULL, IDC_ARROw);
 wc.hIcon = LoadIcon (NULL, IDI_ APPLICATION);
 wc.hInstance = hInstance;
 wc.lpfnWndProc = WndProc;
 wc.lpszClassName = "ME";
 wc.lpszMenuName = NULL;
 wc.style = CS:OWNDC | CS_HREDRAW | CS_VREDRAW;

 if (!RegisterClass(&wc))
 {
   MessageBox (NULL, "Error: Cannot Register Class", "ERROR", MB_OK;
   return (0);
 }

 Window = CreateWindow("Me", "Map Editor", WS:OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0,
          640, 480, NULL, NULL, hInstance, NULL);

 if (Window == NULL)
 {
   MessageBox (NULL, "Error: Failed to Create Window", "ERROR!", MB:OK);
   return (0);
 }

 while (1)
 {
   if (PeekMessage (&msg , NULL, 0, 0, PM_REMOVE))
   {
     if (msg.message === WM_QUIT?) break;
     TranslateMessage (&msg);
     DispatchMessage (&msg);
   }
 }

 return (1);
}

 

Så jeg trykket på Build>>Build OpenGLEks1_1. Men denne meldingen kommer opp i Output vinduet:

 

.\OpenGLSourceCode.cpp(1) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory

 

Jeg trodde windows.h var inkludert i Visual C++?

 

Takker for alle (seriøse) svar!

 

Med vennlig hilsen,

Miromurr

Lenke til kommentar
Videoannonse
Annonse

Det er til å handle med filar, du veit, skrive og lese.

 

Døme:

istream file("data.dat", ios::app);

 

Denne skal då opne data.dat i append mode (og file blir då namnet på objektet.)

Endret av Arne
Lenke til kommentar

// writing on a text file
#include <iostream>
#include <fstream>
using namespace std;

int main () {
 ofstream myfile ("example.txt");
 if (myfile.is_open())
 {
myfile << "This is a line.\n";
myfile << "This is another line.\n";
myfile.close();
 }
 else cout << "Unable to open file";
 return 0;
}

Så det er fstream du er ute etter, og nei. Windows SDK og windows.h er ikke inkludert i express utgaven. Idiotisk spør du meg. :p

Lenke til kommentar

Hei!

 

Jeg har et problem igjen...

Nå har jeg lastet ned Platform SDK, og nå funker det å inkludere windows.h. Problemet nå er at det kommer en haug med nye feil:

 

 

.\OpenGLSourceCode.cpp(14) : error C2061: syntax error : identifier 'CmdShow'

.\OpenGLSourceCode.cpp(15) : error C2731: 'WinMain' : function cannot be overloaded

.\OpenGLSourceCode.cpp(14) : see declaration of 'WinMain'

.\OpenGLSourceCode.cpp(19) : error C2370: 'wc' : redefinition; different storage class

.\OpenGLSourceCode.cpp(16) : see declaration of 'wc'

.\OpenGLSourceCode.cpp(22) : error C2065: 'LTGREY_BRUSH' : undeclared identifier

.\OpenGLSourceCode.cpp(23) : error C2065: 'IDC_ARROw' : undeclared identifier

.\OpenGLSourceCode.cpp(24) : error C2065: 'IDI_' : undeclared identifier

.\OpenGLSourceCode.cpp(24) : error C2146: syntax error : missing ')' before identifier 'APPLICATION'

.\OpenGLSourceCode.cpp(24) : error C2059: syntax error : ')'

.\OpenGLSourceCode.cpp(27) : error C2440: '=' : cannot convert from 'const char [3]' to 'LPCWSTR'

Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

.\OpenGLSourceCode.cpp(29) : error C2065: 'CS' : undeclared identifier

.\OpenGLSourceCode.cpp(29) : error C2143: syntax error : missing ';' before ':'

.\OpenGLSourceCode.cpp(29) : error C2143: syntax error : missing ';' before ':'

.\OpenGLSourceCode.cpp(33) : error C2143: syntax error : missing ')' before ';'

.\OpenGLSourceCode.cpp(33) : error C2664: 'MessageBox' : cannot convert parameter 2 from 'const char [29]' to 'LPCTSTR'

Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

.\OpenGLSourceCode.cpp(38) : error C2065: 'WS' : undeclared identifier

.\OpenGLSourceCode.cpp(38) : error C2143: syntax error : missing ')' before ':'

.\OpenGLSourceCode.cpp(38) : error C2059: syntax error : ')'

.\OpenGLSourceCode.cpp(42) : error C2065: 'MB' : undeclared identifier

.\OpenGLSourceCode.cpp(42) : error C2143: syntax error : missing ')' before ':'

.\OpenGLSourceCode.cpp(42) : error C2059: syntax error : ')'

.\OpenGLSourceCode.cpp(50) : error C2059: syntax error : '='

 

 

Jeg forstår ikke en ting av det, så er det noen som kan være veldig snille å ta en titt på koden min og se hva som er feil?

Lenke til kommentar

Det er en del programmeringsfeil

- Der det står bare "CmdShow" skal det stå int CmdShow (eller noe)

 

- Du har puttet inn mellomrom mellom strukturen og feltet

- Du har glemt parantes etter MessageBox funksjonen

- Du har skrevet MB:OK og CS:OWNDC (som forøvrig også er unødvendig) istedet for MB_OK

- Det heter _tWinMain ikke WinMain

- Du _UNICODE er definert, men du bruker ASCII strings, legg til L før strings som skal være unicode (f.eks. L"Hello World!")

Lenke til kommentar

Nå har jeg fikset på alt det der, men nå trenger jeg vist en eller annen uuid.lib...

 

LINK : fatal error LNK1104: cannot open file 'uuid.lib'

 

Og nå står det "Linking..." istedenfor "Compiling..." i Build-Loggen, altså:

 

 

------ Build started: Project: OpenGLdev_Ex1, Configuration: Debug Win32 ------

Linking...

LINK : fatal error LNK1104: cannot open file 'uuid.lib'

Build log was saved at "file://c:\Documents and Settings\Miromurr\Mine dokumenter\Visual Studio 2005\Projects\OpenGLdev_Ex1\OpenGLdev_Ex1\Debug\BuildLog.htm"

OpenGLdev2 - 1 error(s), 0 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

 

 

Hva betyr dette? Jeg har jo uansett ikke inkludert noen uuid.lib..?

 

Takker for alle svar!

 

Miromurr

 

Edit: Jeg sjekket include mappen, men der fant jeg bar uuids.h...

Endret av Miromurr
Lenke til kommentar

Ok, jeg fant filen jeg lette etter, nå kom dette opp:

 

 

Linking...

OpenGLSourceCode.obj : error LNK2028: unresolved token (0A00001A) "extern "C" void __stdcall PostQuitMessage(int)" (?PostQuitMessage@@$$J14YGXH@Z) referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)

OpenGLSourceCode.obj : error LNK2028: unresolved token (0A00001F) "extern "C" struct HICON__ * __stdcall LoadCursorW(struct HINSTANCE__ *,wchar_t const *)" (?LoadCursorW@@$$J18YGPAUHICON__@@PAUHINSTANCE__@@PB_W@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

OpenGLSourceCode.obj : error LNK2028: unresolved token (0A000022) "extern "C" int __stdcall TranslateMessage(struct tagMSG const *)" (?TranslateMessage@@$$J14YGHPBUtagMSG@@@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

OpenGLSourceCode.obj : error LNK2028: unresolved token (0A000025) "extern "C" struct HICON__ * __stdcall LoadIconW(struct HINSTANCE__ *,wchar_t const *)" (?LoadIconW@@$$J18YGPAUHICON__@@PAUHINSTANCE__@@PB_W@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

OpenGLSourceCode.obj : error LNK2028: unresolved token (0A00002C) "extern "C" int __stdcall PeekMessageW(struct tagMSG *,struct HWND__ *,unsigned int,unsigned int,unsigned int)" (?PeekMessageW@@$$J220YGHPAUtagMSG@@PAUHWND__@@III@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

OpenGLSourceCode.obj : error LNK2028: unresolved token (0A000034) "extern "C" struct HWND__ * __stdcall CreateWindowExW(unsigned long,wchar_t const *,wchar_t const *,unsigned long,int,int,int,int,struct HWND__ *,struct HMENU__ *,struct HINSTANCE__ *,void *)" (?CreateWindowExW@@$$J248YGPAUHWND__@@KPB_W0KHHHHPAU1@PAUHMENU__@@PAUHINSTANCE__@@PAX@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

OpenGLSourceCode.obj : error LNK2028: unresolved token (0A000037) "extern "C" int __stdcall MessageBoxW(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBoxW@@$$J216YGHPAUHWND__@@PB_W1I@Z) referenced in function "extern "C" int __cdecl MessageBox(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBox@@$$J0YAHPAUHWND__@@PB_W1I@Z)

OpenGLSourceCode.obj : error LNK2028: unresolved token (0A000038) "extern "C" unsigned short __stdcall RegisterClassW(struct tagWNDCLASSW const *)" (?RegisterClassW@@$$J14YGGPBUtagWNDCLASSW@@@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

OpenGLSourceCode.obj : error LNK2028: unresolved token (0A00003C) "extern "C" void * __stdcall GetStockObject(int)" (?GetStockObject@@$$J14YGPAXH@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

OpenGLSourceCode.obj : error LNK2028: unresolved token (0A00003D) "extern "C" long __stdcall DefWindowProcW(struct HWND__ *,unsigned int,unsigned int,long)" (?DefWindowProcW@@$$J216YGJPAUHWND__@@IIJ@Z) referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)

OpenGLSourceCode.obj : error LNK2028: unresolved token (0A000041) "extern "C" long __stdcall DispatchMessageW(struct tagMSG const *)" (?DispatchMessageW@@$$J14YGJPBUtagMSG@@@Z) referenced in function "extern "C" long __cdecl DispatchMessage(struct tagMSG const *)" (?DispatchMessage@@$$J0YAJPBUtagMSG@@@Z)

OpenGLSourceCode.obj : error LNK2019: unresolved external symbol "extern "C" long __stdcall DispatchMessageW(struct tagMSG const *)" (?DispatchMessageW@@$$J14YGJPBUtagMSG@@@Z) referenced in function "extern "C" long __cdecl DispatchMessage(struct tagMSG const *)" (?DispatchMessage@@$$J0YAJPBUtagMSG@@@Z)

OpenGLSourceCode.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall MessageBoxW(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBoxW@@$$J216YGHPAUHWND__@@PB_W1I@Z) referenced in function "extern "C" int __cdecl MessageBox(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBox@@$$J0YAHPAUHWND__@@PB_W1I@Z)

OpenGLSourceCode.obj : error LNK2019: unresolved external symbol "extern "C" long __stdcall DefWindowProcW(struct HWND__ *,unsigned int,unsigned int,long)" (?DefWindowProcW@@$$J216YGJPAUHWND__@@IIJ@Z) referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)

OpenGLSourceCode.obj : error LNK2019: unresolved external symbol "extern "C" void __stdcall PostQuitMessage(int)" (?PostQuitMessage@@$$J14YGXH@Z) referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)

OpenGLSourceCode.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall TranslateMessage(struct tagMSG const *)" (?TranslateMessage@@$$J14YGHPBUtagMSG@@@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

OpenGLSourceCode.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall PeekMessageW(struct tagMSG *,struct HWND__ *,unsigned int,unsigned int,unsigned int)" (?PeekMessageW@@$$J220YGHPAUtagMSG@@PAUHWND__@@III@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

OpenGLSourceCode.obj : error LNK2019: unresolved external symbol "extern "C" struct HWND__ * __stdcall CreateWindowExW(unsigned long,wchar_t const *,wchar_t const *,unsigned long,int,int,int,int,struct HWND__ *,struct HMENU__ *,struct HINSTANCE__ *,void *)" (?CreateWindowExW@@$$J248YGPAUHWND__@@KPB_W0KHHHHPAU1@PAUHMENU__@@PAUHINSTANCE__@@PAX@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

OpenGLSourceCode.obj : error LNK2019: unresolved external symbol "extern "C" unsigned short __stdcall RegisterClassW(struct tagWNDCLASSW const *)" (?RegisterClassW@@$$J14YGGPBUtagWNDCLASSW@@@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

OpenGLSourceCode.obj : error LNK2019: unresolved external symbol "extern "C" struct HICON__ * __stdcall LoadIconW(struct HINSTANCE__ *,wchar_t const *)" (?LoadIconW@@$$J18YGPAUHICON__@@PAUHINSTANCE__@@PB_W@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

OpenGLSourceCode.obj : error LNK2019: unresolved external symbol "extern "C" struct HICON__ * __stdcall LoadCursorW(struct HINSTANCE__ *,wchar_t const *)" (?LoadCursorW@@$$J18YGPAUHICON__@@PAUHINSTANCE__@@PB_W@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

OpenGLSourceCode.obj : error LNK2019: unresolved external symbol "extern "C" void * __stdcall GetStockObject(int)" (?GetStockObject@@$$J14YGPAXH@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)

C:\Documents and Settings\Miromurr\Mine dokumenter\Visual Studio 2005\Projects\OpenGLdev2\Debug\OpenGLdev2.exe : fatal error LNK1120: 22 unresolved externals

 

 

Jeg er helt desperat nå, hva i ***** skal jeg gjøre :p ??? Jeg orker ihvertfall ikke å lese gjennom alt det der!

 

Edit: Det er faktisk "bare" 23 feilmeldinger, i Visual C++ var hver melding på en egen linje. Hver melding starter med OpenGLSourceCode.obj (Navnet på Source filen i projektet)

 

Miromurr

 

Edit2: Her er den nye Source-koden:

 

#include <windows.h>

HWND Window;

LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 switch (msg)
 {
   case WM_DESTROY: PostQuitMessage(0); break;
 }
 return (DefWindowProc(hWnd, msg, wParam, lParam));
}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevious, LPSTR LpCmdString, int CmdShow)
{
 WNDCLASS wc;
 MSG      msg;

 wc.cbClsExtra = 0;
 wc.cbWndExtra = 0;
 wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
 wc.hCursor = LoadCursor (NULL, IDC_ARROW);
 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
 wc.hInstance = hInstance;
 wc.lpfnWndProc = WndProc;
 wc.lpszClassName = L"ME";
 wc.lpszMenuName = NULL;
 wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;

 if (!RegisterClass(&wc))
 {
   MessageBox (NULL, L"Error: Cannot Register Class", L"ERROR", MB_OK);
   return (0);
 }

 Window = CreateWindow(L"Me", L"Map Editor", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0,
 640, 480, NULL, NULL, hInstance, NULL);

 if (Window == NULL)
 {
   MessageBox (NULL, L"Error: Failed to Create Window", L"ERROR!", MB_OK);
   return (0);
 }

 while (1)
 {
   if (PeekMessage (&msg , NULL, 0, 0, PM_REMOVE))
   {
     if (msg.message == WM_QUIT) break;
     TranslateMessage (&msg);
     DispatchMessage (&msg);
   }
 }

 return (1);
}

Endret av Miromurr
Lenke til kommentar

Eg veit ikkje om dette kan vere relevant, men dette fann eg på spill.hihm.no:

Så et siste steg før vi kan starte med å faktisk lage vårt første program!

 

Vi må skifte en fil. «C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults\corewin_express.vsprops» .(gitt at du har installert programmet der)

Åpne denne filen i notisblokk, og skift ut linjen

 

AdditionalDependencies="kernel32.lib"

 

med

 

AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib"

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...