I'm trying access the class in my library but I get undefined reference. I have tried some random things but I still don't get what's wrong. Maybe I should go to the easy way and write all in a different way but I need to know what I did wrong to improve. You can see the code. Error:
main.cpp:
#include <stdlib.h>
#include <windows.h>
#include "game.h"
int __attribute__((constructor)) Start();
int __attribute__((destructor)) End();
HANDLE Icon = getIcon("./icono.ico");
HCURSOR Cursor = getCursor("./Test.cur");
int Start(){
};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow)
{
Window MainWindow = Window(Icon, "Test", "Test", WS_OVERLAPPEDWINDOW, Cursor, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, NULL, NULL, hInstance, NULL);
//MainWindow.enable(nCmdShow);
//GameLoop();
};
int End(){
};
game.cpp:
//Headers
#include "game.h"
//Functions
LRESULT CALLBACK WindowsProcedure(HWND, UINT, WPARAM, LPARAM);
//Variables
//Objects
struct Vector2{
float X;
float Y;
};
struct Vector3{
float X;
float Y;
float Z;
};
struct Color3{
int R;
int G;
int B;
};
struct Color4{
int R;
int G;
int B;
float A;
};
Window::Window(HANDLE Icon, const char*ID, const char*Title, DWORD Style, HCURSOR Cursor, int X, int Y, int Width, int Height, HWND Parent, HMENU Child, HINSTANCE Instance, LPVOID LpParam)
{
//IDC_ARROW
//instance = GetModuleHandle(0);
windowsClass.cbSize = sizeof(WNDCLASSEX);
windowsClass.style = 0;
windowsClass.lpfnWndProc = WindowsProcedure;
windowsClass.cbClsExtra = 0;
windowsClass.cbWndExtra = 0;
windowsClass.hInstance = Instance;
windowsClass.hIcon = (HICON) Icon;
windowsClass.hCursor = Cursor;
windowsClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
windowsClass.lpszMenuName = NULL;
windowsClass.lpszClassName = ID;
windowsClass.hIconSm = (HICON) Icon;
RegisterClassEx(&windowsClass);
window = CreateWindow(ID, Title, Style, X, Y, Width, Height, Parent, Child, Instance, LpParam);
//pthread_create(&Thread, NULL, Background, (void*)NULL);
};
//Function
void Window::enable(int nCmdShow){
ShowWindow(window, nCmdShow);
}
HWND Window::getWindow(){
return this->window;
};
void Window::setIcon(HANDLE Icon){
if (Icon) {
SendMessage(this->window, WM_SETICON, ICON_SMALL, (LPARAM)Icon);
SendMessage(this->window, WM_SETICON, ICON_BIG, (LPARAM)Icon);
}else{
std::cout<<"Icon not found!"<<std::endl;
};
};
void Window::setCursor(HCURSOR Cursor){
SetCursor(Cursor);
};
void Window::close(){
DestroyWindow(this->window);
};
//Events
//int Window::onSizeEvent();
//int Window::onCloseEvent(HWND);
//Functions
HANDLE getIcon(const char*Icon_Path){
return (HANDLE)LoadImage(0, Icon_Path, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
};
HCURSOR getCursor(const char*Cursor_Path){
if (!LoadCursorFromFile(Cursor_Path)){
std::cout<<"Cursor file not found, 0 was returned!!"<<std::endl;
}
return LoadCursorFromFile(Cursor_Path);
}
void GameLoop(){
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
LRESULT CALLBACK WindowsProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
switch (msg){
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
break;
}
return 0;
};
game.h:
#ifndef GAME_H
#define GAME_H
#include <pthread.h>
#include <iostream>
#include <windows.h>
struct Vector2;
struct Vector3;
struct Color3;
struct Color4;
class Window{
private:
HWND window;
WNDCLASSEX windowsClass;
pthread_t Thread;
public:
Window(HANDLE Icon, const char*ID, const char*Title, DWORD Style, HCURSOR Cursor, int X, int Y, int Width, int Height, HWND Parent, HMENU Child, HINSTANCE Instance, LPVOID LpParam);
//Function
void enable(int nCmdShow);
HWND getWindow();
void setIcon(HANDLE Icon);
void setCursor(HCURSOR Cursor);
void close();
//Events
int onSizeEvent();
int onCloseEvent(HWND);
};
HCURSOR DEFAULT_CURSOR = LoadCursor(NULL, IDC_ARROW);
HANDLE getIcon(const char*Icon_Path);
HCURSOR getCursor(const char*Cursor_Path);
void GameLoop();
#endif