5 Replies - 225 Views - Last Post: 04 August 2013 - 11:03 AM Rate Topic: -----

#1 IntVoid  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 29
  • Joined: 21-July 13

Making a reference instance of DirectX window handler?

Posted 03 August 2013 - 04:41 PM

The Problem: I'm trying to use my fontwrapper I created in my new framework, but the draw function requires me to pass in the window handler so it knows what to write to. The problem here is that my window handler is in a separate file, "EntryPoint.cpp" to be exact. Now I already externalized it and linked the header file associated with main window handler so I can make the argument pass into the drawtext function.

The issue is that when I pass it in, and compile I am getting a linker error.

error LNK2001: unresolved external symbol "struct HWND_ *GAMECORE::g_hMainWnd" (?g_hMainWnd@GAMECORE@@3PAUHWND_@@A)
error LNK1120: 1 unresolved externals.

I compiled the code without making the call to drawtext and passing the variable and it compiles and runs appropiately.
The drawtext function for my fontwrapper works fine in the EntryPoint.cpp file, but the problem is that I need to make the calls in a different file due to the structure of the program. (Waaay too much code to implement into one massive file!)

Now I was thinking of making a reference to the main window object:
HWND g_hMainWnd;



Though I honestly do not know how. Another idea that came up is why I am getting a linker error when the window object is properly externalized?

I am unsure of exactly how to proceed.

To be clear, I do know how to make pointers, and references, though I do not know if its possible to actually make a reference of an object that is already created to pass to a function that requires it as a target parameter.

Heres some of the code (It only shows relevant code, all unneeded code was gutted for sake of clarity):

EntryPoint.cpp
#include "GameCore.h"

CORE::HARDWARE::D3D11::D3D11_ROOT g_Root;
HINSTANCE g_hInstance;
HWND g_hMainWnd;
BOOL g_bAppRunning;



GameCore.h
#pragma once

#include <Windows.h>
#include <stdio.h>

#include "_internal/CORE.h"
#include "./BASECODE/BASE_CORE.h"

using namespace CORE::HARDWARE::D3D11;

namespace GAMECORE {
	// Main Application Module
	class MainApp {
	public:
		static void _OnInitialize(float time, IMAGE& screen, D3D11_ROOT& root);
		static void _OnUninitialize(float time, IMAGE& screen, D3D11_ROOT& root);
		static void _OnFrame(float time, IMAGE& screen, D3D11_ROOT& root);
		static void _OnUpdate(float time, IMAGE& screen, D3D11_ROOT& root);
	};

	//extern SimpleText Font;
	extern HWND g_hMainWnd;
}



Core.cpp
#include "BASE_CORE.h"
#include "../GameCore.h"

using namespace CORE::HARDWARE::D3D11;
using namespace CODE::DATA;
using namespace GAMECORE;

namespace BASE_CODE {

	FMOD::Sound *ThemeMusic;
	
	void OnInitialize(float time, IMAGE& screen, D3D11_ROOT& root) {

		FontSystem.Initialize(g_hMainWnd);

		//FMOD Initialization
		FMOD::System_Create(&soundSystem);
		soundSystem->init(1024, FMOD_INIT_NORMAL, 0);
		soundSystem->createSound(".\\RESOURCES\\SOUNDS\\09 - No Fear.wav", FMOD_HARDWARE, 0, &ThemeMusic);
		ThemeMusic->setMode(FMOD_LOOP_NORMAL);
		soundSystem->playSound(FMOD_CHANNEL_FREE, ThemeMusic, false, 0);

		DATA::Initialize_Data_Model();
		DATA::InitializeScenes(root);
		DATA::_CameraObject.Initialize(time, screen, root);
		DATA::_SkyBoxObject.Initialize(time, screen, root);
		DATA::_ArenaObject.Initialize(time, screen, root, "./RESOURCES/TEXTURES/ArenaTexture.png");

		// Create Robots
		DATA::CreateObject(new BattleBotObject(time, screen, root, "./RESOURCES/TEXTURES/BattleBotTexture_1.png", 1));
		DATA::CreateObject(new BattleBotObject(time, screen, root, "./RESOURCES/TEXTURES/BattleBotTexture_2.png", 2));
		DATA::CreateObject(new BattleBotObject(time, screen, root, "./RESOURCES/TEXTURES/BattleBotTexture_3.png", 3));
		DATA::CreateObject(new BattleBotObject(time, screen, root, "./RESOURCES/TEXTURES/BattleBotTexture_4.png", 4));
		DATA::CreateObject(new BattleBotObject(time, screen, root, "./RESOURCES/TEXTURES/BattleBotTexture_5.png", 5));
		DATA::CreateObject(new BattleBotObject(time, screen, root, "./RESOURCES/TEXTURES/BattleBotTexture_6.png", 6));

	}



Is This A Good Question/Topic? 0
  • +

Replies To: Making a reference instance of DirectX window handler?

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Making a reference instance of DirectX window handler?

Posted 03 August 2013 - 07:59 PM

Just by quickly looking, you need to move

extern HWND g_hMainWnd;



outside the GAMECORE namespace. Can't see why that wouldn't work.
Was This Post Helpful? 1
  • +
  • -

#3 IntVoid  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 29
  • Joined: 21-July 13

Re: Making a reference instance of DirectX window handler?

Posted 03 August 2013 - 11:59 PM

View PostButchDean, on 03 August 2013 - 07:59 PM, said:

Just by quickly looking, you need to move

extern HWND g_hMainWnd;



outside the GAMECORE namespace. Can't see why that wouldn't work.


I... Wow... Haha, it worked like a charm. I can't believe I didn't catch that! You are a savior!

Staring at code too long today haha.
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Making a reference instance of DirectX window handler?

Posted 04 August 2013 - 04:25 AM

Awesome. Be careful where you put declarations in C++.

Using 'extern' is legacy functionality from C, plus the fact that the original declaration was in the global namespace and you declared the extern within your own namespace which doesn't work.

I *think* that is why the linker got confused.

This post has been edited by ButchDean: 04 August 2013 - 04:26 AM

Was This Post Helpful? 0
  • +
  • -

#5 IntVoid  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 29
  • Joined: 21-July 13

Re: Making a reference instance of DirectX window handler?

Posted 04 August 2013 - 10:54 AM

Yeah, that's exactly why the linker got confused. It is working like a charm now. Didn't do much functionality last night as I fixed it right before I hit the sack, but I can't believe I didn't see what I did wrong. The joys of programming!
Was This Post Helpful? 0
  • +
  • -

#6 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Making a reference instance of DirectX window handler?

Posted 04 August 2013 - 11:03 AM

You'll spot these things with experience.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1