Simple ddraw problem
Hi guys.
Ok look at this code:
#include "stdafx.h"
#include <windows.h>
#include <ddraw.h>
HWND hWndMain;
IDirectDraw7 *pDD;
IDirectDrawSurface7 *lpPrimary, *lpBackBuffer;
void InitDirectDraw()
{
DirectDrawCreateEx(NULL, (void **)&pDD, IID_IDirectDraw7, NULL);
pDD->SetCooperativeLevel(hWndMain,
DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT);
pDD->SetDisplayMode(640, 480, 16, 0, 0);
DDSURFACEDESC2 ddsd;
ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
ddsd.dwSize = sizeof(DDSURFACEDESC2);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
DDSCAPS_FLIP |
DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 2;
pDD->CreateSurface(&ddsd, &lpPrimary, NULL);
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
lpPrimary->GetAttachedSurface(&ddsd.ddsCaps, &lpBackBuffer);
}
void ExitDirectDraw()
{
lpPrimary->Release();
lpPrimary = NULL;
pDD->Release();
pDD = NULL;
}
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:
ExitDirectDraw();
DestroyWindow(hWnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
void RegisterWindowClass()
{
WNDCLASSEX wcx;
ZeroMemory(&wcx, sizeof(WNDCLASSEX));
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.lpfnWndProc = MainWindowProc;
wcx.hInstance = GetModuleHandle(NULL);
wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcx.hCursor = NULL;
wcx.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcx.lpszMenuName = NULL;
wcx.lpszClassName = "SampleWindowClass";
RegisterClassEx(&wcx);
}
void OnIdle(void)
{
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
MSG msg;
RegisterWindowClass();
hWndMain = CreateWindowEx(WS_EX_APPWINDOW,
"SampleWindowClass", "DirectDraw Bare-Bones Sample", WS_POPUP,
0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
NULL, NULL, hInstance, NULL);
ShowWindow(hWndMain, SW_SHOW);
InitDirectDraw();
for (;
{
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!GetMessage(&msg, NULL, 0, 0))
break;
DispatchMessage(&msg);
}
OnIdle();
}
return 0;
}
ok look ok by me but when i compile he says all that:
:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(9) : error C2143: syntax error : missing '';'' before ''*''
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(9) : error C2501: ''IDirectDraw7'' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(9) : error C2501: ''pDD'' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(10) : error C2143: syntax error : missing '';'' before ''*''
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(10) : error C2501: ''IDirectDrawSurface7'' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(10) : error C2501: ''lpPrimary'' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(10) : error C2501: ''lpBackBuffer'' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(16) : error C2065: ''DirectDrawCreateEx'' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(16) : error C2065: ''IID_IDirectDraw7'' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(19) : error C2227: left of ''->SetCooperativeLevel'' must point to class/struct/union
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(23) : error C2227: left of ''->SetDisplayMode'' must point to class/struct/union
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(25) : error C2065: ''DDSURFACEDESC2'' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(25) : error C2146: syntax error : missing '';'' before identifier ''ddsd''
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(25) : error C2065: ''ddsd'' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(29) : error C2228: left of ''.dwSize'' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(30) : error C2228: left of ''.dwFlags'' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(31) : error C2228: left of ''.ddsCaps'' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(31) : error C2228: left of ''.dwCaps'' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(34) : error C2228: left of ''.dwBackBufferCount'' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(35) : error C2227: left of ''->CreateSurface'' must point to class/struct/union
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(38) : error C2228: left of ''.ddsCaps'' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(38) : error C2228: left of ''.dwCaps'' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(39) : error C2227: left of ''->GetAttachedSurface'' must point to class/struct/union
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(39) : error C2228: left of ''.ddsCaps'' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(46) : error C2227: left of ''->Release'' must point to class/struct/union
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(50) : error C2227: left of ''->Release'' must point to class/struct/union
I think i forgot to link something as he don''t read my SDK.
i don''t think it''s a linking problem. looks like a syntax problem to me. can you post what''s inside stdafx.h?
500
500
IT''s DDraw 5. If ur using VC++ DevC++ and most other utilities go to the directories and make sure u''ve included the SDK, if u have use the arrows and make sure these Direct X sdk directories are at the top of the list. When u use #include <ddraw.h> it will find the old Direct x 5 files and stop instead of looking for the direct x 9 ones. This is why u need these directories on the top of the list so that at the time of compiling it will use the newer version. Sorry for saying so much for something that could have been said in a line or two.
-Link
I linked once but now i installed my VC++ complier again and i forgot how to link my SDK,plz help.
Tools -> Options -> Directories. Add the paths for the include, source, libraries. Eg C:\DXSDK\Include for include. Make sure they are at the top of the list to override previous versions that might have come with MSVC++.
C:\Program Files\Microsoft Visual Studio\MyProjects\DDraw simple\DDraw simple.cpp(9) : error C2501: ''IDirectDraw7'' : missing storage-class or type specifiers
update ''IDirectDraw7'' if u have direct x 9 installed i don''t think this command will work. it will probably be stored as ''IDirectDraw9''.
For the directories Will O says it best.
update ''IDirectDraw7'' if u have direct x 9 installed i don''t think this command will work. it will probably be stored as ''IDirectDraw9''.
For the directories Will O says it best.
-Link
Ok thanks guys.I think i linked it right but i have another question:
Where i can find good directx 9 tutorials of directdraw?
Where i can find good directx 9 tutorials of directdraw?
quote: Original post by cleves
Ok thanks guys.I think i linked it right but i have another question:
Where i can find good directx 9 tutorials of directdraw?
They stopped updating DirectDraw after DirectX 7. With DirectX8 and later, if you want to use 2d you would utilize direct3d (DirectGraphics)...
By the way, have you got the program above to work?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement