我想在Windows10中使用DirectX开发游戏。我曾经用CodeBlocks编写代码。以下代码将抛出以下错误:
undefined reference to `GetStockObject@4'
此Windows功能有什么问题?我不必单独初始化或编写此函数,不是吗?注释掉错误代码将编译代码,但是没有GUI ... 这是代码:
#include <windows.h>
#include"Frame.h"
//global definitions
BOOL done;
int Spiel_Zustand;
HWND hwnd;
//Function:CallBack
LRESULT CALLBACK WindowProc (HWND hwnd,UINT message, WPARAM wparam,LPARAM lparam)
{
switch(message)
{
case WM_DESTROY :
{
done=TRUE;
PostQuitMessage(0);
return 0;
}
break;
case WM_KEYDOWN:
switch(wparam)
{
case VK_ESCAPE:
{
PostMessage(hwnd,WM_CLOSE,0,0);
return 0;
}
break;
}
break;
default:
break;
}//End of switch
return DefWindowProc(hwnd,message,wparam,lparam);
}//End of CallBack
//Function:Start
int WINAPI WinMain(HINSTANCE hinst,HINSTANCE hprevinst,LPSTR lpcmdline,int ncmdshow)
{
WNDCLASSEX winclass;
MSG message;
const char szclassname[]="Klassenname";
DWORD loop_start_time;
winclass.cbSize=sizeof(WNDCLASSEX);
winclass.style=CS_HREDRAW|CS_VREDRAW;
winclass.lpfnWndProc=WindowProc;
winclass.cbClsExtra=0;
winclass.cbWndExtra=0;
winclass.hInstance=hinst;
winclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
winclass.hCursor=LoadCursor(NULL,IDC_ARROW);
winclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);//this will throw out error
winclass.lpszClassName=szclassname;
winclass.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
if(!RegisterClassEx(&winclass))
return 0;
//Create handle of windows ans save it globally
if(!(hwnd=CreateWindowEx(NULL,szclassname,"3D Gameprograming - Title",WS_POPUPWINDOW|WS_VISIBLE,0,0,400,300,NULL,NULL,hinst,NULL)))
return 0;
done=FALSE;
Spiel_Zustand=SPIEL_AUSWAHL;
//Phase 1.1:
Spiel_Initialisieren();
//Phase 1.2:: Main Looping
while(!done)
{
//Any message to handle?
while(GetMessage(&message,NULL,0,0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
//Start time of Main Loop
loop_start_time=GetTickCount;
switch(Spiel_Zustand)
{
case SPIEL_AUSWAHL:
{
//[....]
Spiel_Zustand=SPIEL_START;
}
break;
case SPIEL_START:
{
//[...]
Spiel_Zustand=SPIEL_LAEUFT;
}
break;
case SPIEL_LAEUFT:
{
//waiting for User input
//Manage User input
//Artificial Intelligence and game logic
//Rendering Frame
} break;
case SPIEL_NEUSTART:
{
//[...]
Spiel_Zustand=SPIEL_START;
}
break;
default:
break;
}//End of switch
//Restricting Frame rate
while((GetTickCount()-loop_start_time)<40);
}//End of Main Looping
//Phase 1.3
Spiel_Beenden();
return message.wParam;
}//End of Start
//Phase 2.1
int Spiel_Initialisieren(void)
{
//ToDO:initializations etc..
return 1;
}
//Phase 2.2
int Spiel_Beenden(void)
{
//ToDO:Free Memory etc..
return 1;
}
答案 0 :(得分:1)
编译_photoFile = new File(Environment.SoftSettings.AttachmentsPath, String.Format("{0}.jpg", Guid.NewGuid()));
Intent intent = new Intent(MediaStore.ActionImageCapture);
if (Build.VERSION.SdkInt >= BuildVersionCodes.N)
{
// Android 7 requirment to use content:// scheme
var uriFile = Android.Support.V4.Content.FileProvider.GetUriForFile(
context,
context.ApplicationContext.PackageName + ".provider",
_photoFile);
intent.AddFlags(ActivityFlags.GrantReadUriPermission);
intent.PutExtra(MediaStore.ExtraOutput, uriFile);
}
else
{
intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(_photoFile));
}
StartActivityForResult(intent, (int)ActivityRequestCode.Camera);
时需要链接gdi32.lib