Original Post
Hi, there.
I have a DiretX source.
The source is no compile error, but exist link error.
I dont'' know problem.
Please, help me.
Development Evironment : vc++6.0 DirectX9.0 SDK
error message:
--------------------Configuration: api - Win32 Debug--------------------
Linking...
main.obj : error LNK2001: unresolved external symbol _DirectDrawCreate@12
Debug/api.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
api.exe - 2 error(s), 0 warning(s)
source code:
#include <windows.h>
#include <ddraw.h>
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 400
#define BIT_COLOR 8
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
BOOL InitDirectDraw(HWND);
VOID CloseDirectDraw();
VOID Draw();
LPDIRECTDRAW lpDD = NULL;
LPDIRECTDRAWSURFACE lpPrimary = NULL;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPreInst, LPSTR szCmdLine, int iCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIconSm = NULL;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "Hi";
RegisterClassEx(&wc);
hwnd = CreateWindow("Hi", "Hello!", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInst, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
LPSTR strMsg = "DirectX create failed";
LPSTR strTitle = "Error!";
switch (iMsg) {
case WM_CREATE:
if ( ! InitDirectDraw(hWnd) )
MessageBox(hWnd, strMsg, strTitle, MB_OK | MB_ICONERROR);
Draw();
return 0;
case WM_KEYDOWN:
switch (wParam) {
case VK_ESCAPE:
CloseDirectDraw();
PostQuitMessage(0);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}
BOOL InitDirectDraw(HWND hWnd)
{
HRESULT hr;
hr = DirectDrawCreate(NULL, &lpDD, NULL);
if ( hr != DD_OK ) return FALSE;
/*hr = lpDD->QueryInterface((IID_IDirectDraw, (LPVOID*)lpDD7);
if ( hr != DD_OK ) return FALSE;*/
hr = lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT);
if ( hr != DD_OK ) return FALSE;
hr = lpDD->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, BIT_COLOR);
if ( hr != DD_OK ) return FALSE;
DDSURFACEDESC ddsd;
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
lpDD->CreateSurface(&ddsd, &lpPrimary, NULL);
return TRUE;
}
VOID CloseDirectDraw()
{
if(lpPrimary != NULL)
lpPrimary->Release();
if (lpDD != NULL) {
lpDD->Release();
}
}
VOID Draw()
{
LPSTR str = "Hello!";
HRESULT hr;
HDC hDC;
hr = lpPrimary->GetDC(&hDC);
if(hr == DD_OK)
{
TextOut(hDC, 300, 200, str, strlen(str));
lpPrimary->ReleaseDC(hDC);
}
}