## Elixir42

Many thanks 'rubberman' for your swift reply. Apologies if I posted this in the wrong place.

Your biggest problem in the future will be using Visual Studio

May I ask you to elaborate on what problems I would get?

## Elixir42

Background:
I just figured out how to solve my unresolved external symbols by just dragging the project files from explorer (contained in exe's directory) and plonking them in the dll project, under thier own filter!

Original Situation:
I was getting 'unresolved external symbols' errors because I was #include-ing files that my dll needed that resided in the exe's project folder. Guessing I would figure that the .obj files would get built and the .dll would not know where they were to link to them.

My Question:

• Will this cause any problems in the future? - having two different .obj files. One for the .dll and one for the .exe?
• Is there a better way of doing this. - I tried adding the directory of the .exe's .obj files to the .dll's linker settings but it didn't work.

## Elixir42

Hi 'Wise & Wonderful Daniwebbers',

Why do I keep loosing my project settings when I add a new project to an existing solution? I have to go to every project, in the solution and re-configure each project's:

• Include Directories;
• Library Directories;
etc.,

Which of the solution files, if any, can I backup then restore when it happens?

• *.vcxproj?
• *.vcxproj.user?
• *.vcxproj.filters?
other?

## Elixir42

Hi,

The problem I am having is that the returned object, from a dll factory, is not lasting for more than the function scope that recieves it. Despite reading How to prevent the static initialisation order fiasco I fail to see how it even applies to my code. g_spEngineLog is the global that is in question. I have declared it as extern in CEngine header and defined it in the implementation. I Hope this is right!

// This is the factory function inside a dll:

extern "C" IMPEXP void* CreateClassInstance(bool bBinary)
{
if (bBinary)
return (static_cast<void*>(new CLog<CFileBinary>));
else
return (static_cast<void*>(new CLog<CFileText>));

} // CreateClassInstance

// This is the function body that uses it. Note that back in main(), or in any other function for that matter, it is not accessable:

    {
// Create engine
g_spGlobalEngine = BOOSTSP<CEngine>(new CEngine);
//g_spEngineLog = BOOSTSP<ISerialization>(g_spGlobalEngine->CreateLog(false));

// Create function pointer
fpVoidFunctBool CreateVoidObj;

// Initialise SP with factory function

// Name of factory function
std::string sFactoryFunction(LPCSTR("CreateClassInstance"));

// Get the function pointer
CreateVoidObj = spDLL->GetFunctionPtr<fpVoidFunctBool>(sFactoryFunction);

// Call factory and initialise GlobalSP with a pointer to the object.
g_spEngineLog = BOOSTSP<ISerialization>(static_cast<ISerialization*>(CreateVoidObj(CENGINELOG_IS_BINARY)));

// Open
std::string sLogFilename(nsStringTable::sEngineLogFilename.c_str());

// For testing purposes
g_spEngineLog->SetNumber(45);
i = g_spEngineLog->GetNumber();

g_spEngineLog->OpenOutput(sLogFilename, std::ios::trunc);
*g_spEngineLog << "CEngine::Create(): '" << sLogFilename <<
"' started on: " << g_spGlobalEngine->GetDate() <<
" at: " << g_spGlobalEngine->GetTime() << std::endl;
}

// Out of scope at the end here.

## Elixir42

Thanks for that Mike. I realise about that first point - I was just testing the global in that funtion. On the other points I have done that. Plus CSingleton::Create only get called once anyhow. Maybe I didn't understand what you meant.

I'm still stuck on why in the sample it works but not in my project. Here are 2 of my original project functions:

Just as above but: g_spEngineLog is g_spLog and g_spGlobalEngine is g_spSingleton

/*************************************************************************
**  Function    : Create
**  Description : Manufacture CEngine instance and create engine log.
**************************************************************************/
void CEngine::Create(void)
{
if (!g_spGlobalEngine)
{
// Create engine and start log
g_spGlobalEngine.reset(new CEngine());
g_spEngineLog = g_spGlobalEngine->CreateLog(false);

// Open
std::string sLogFilename(nsStringTable::sEngineLogFilename.c_str());

// For testing purposes
int i = g_spEngineLog->GetNumber(); // <== ACCESS VIOLATION
g_spEngineLog->SetNumber(45);
i = g_spEngineLog->GetNumber();

g_spEngineLog->OpenOutput(sLogFilename, std::ios::trunc);
*g_spEngineLog << "CEngine::Create(): '" << sLogFilename <<
"' started on: " << g_spGlobalEngine->GetDate() <<
" at: " << g_spGlobalEngine->GetTime() << std::endl;
}
} // Create

/*************************************************************************
**  Function    : CreateLog
**************************************************************************/
BOOSTSP<ISerialization> CEngine::CreateLog(bool is_Binary)
{
// Create function pointer
fpVoidFunctBool CreateVoidObj;

// Initialise SP with factory function

// Name of factory function
std::string sFactoryFunction(LPCSTR("CreateClassInstance"));

// Get the function pointer
CreateVoidObj = spDLL->GetFunctionPtr<fpVoidFunctBool>(sFactoryFunction);

// Static class member
// Call FF and initialise SP with a pointer to the object.
s_SP.reset(static_cast<ISerialization*>(CreateVoidObj(is_Binary)));

return s_SP;
} // CreateLog

How am I getting out of scope...! In the debugger the g_spEngineLog goes red indicating that the ...

## Elixir42

Hi,

When I initialise then access the g_spMyLog shared pointer, from within the CSingleton::CreateLog member function, it works ok. Accessing the SP from the static member function of CSingleton::Create() causes an access violation in the original project and an abort in this sample project displayed below.

In the original project I think the object is going out of scope somewhere but I don't know where. The factory function is created within a DLL as return (static_cast<void*>(new CMyLog)); which is then static_cast to a CMylog* straight into a shared_ptr like this: g_spMyLog.reset(static_cast<CMyLog*>(CreateVoidObj(is_Binary))); but that's not included here.

// File: CSingleton.h

#pragma once

#include "CMyLog.h"
#include <string>
#include <boost\shared_ptr.hpp>
#include <boost\make_shared.hpp>

#define BOOSTSP boost::shared_ptr
#define BOOSTMKSHD boost::make_shared

class CSingleton
{
public:
static void Create(void);
static void Destroy(void);

~CSingleton(void) {}

BOOSTSP<CMyLog> CreateLog(bool is_Binary);

protected:
CSingleton(void) {} // Hidden constructor

private:
// PRIVATE SEMANTICS
CSingleton(const CSingleton& other) {}                     // Copy constructor
friend void swap(CSingleton& first, CSingleton& second) {} // Swap implementation
CSingleton& operator=(CSingleton other) {}                 // Assignment operator
CSingleton(CSingleton&& other) {}                          // Move constructor
};

extern BOOSTSP<CSingleton> g_spSingleton;
extern BOOSTSP<CMyLog> g_spLog;

// File: CSingleton.cpp

#include "CSingleton.h"
#include "CMyLog.h"

BOOSTSP<CSingleton> g_spSingleton = nullptr;
BOOSTSP<CMyLog> g_spLog = nullptr;
void Create(void);
void Destroy(void);

void CSingleton::Create(void)
{
if (!g_spSingleton)
{
// Create engine and start log
g_spSingleton.reset(new CSingleton());
g_spLog = g_spSingleton->CreateLog(false);

//
int i = g_spLog->Get(); // << Abort has been called ERROR
g_spLog->Set(245);
i = g_spLog->Get();
}

} // Create

BOOSTSP<CMyLog> CSingleton::CreateLog(bool is_Binary)
{
static BOOSTSP<CMyLog> sp; // Ignore this.

g_spLog = BOOSTSP<CMyLog>(new CMyLog());
g_spLog->Set(1234); // <== ...

## Elixir42

you could have googled and produced... 1km = 1000m, 1m = 100cm, 1km = 100,000cm. So then...

int iCentimeters = /*Whatever space shuttle records in cm*/;
int iMeters = int(iCentimeters / 100);
int iKilometers = int(iMeters / 1000);

The int() will cast away the floating point result. Now just output it to screen. Use float for a more accurate result. Have a go...

## Elixir42

Its true you have to make an effort on your own behalf. But here is the sugar you are after. Read boost.Serialization
(All of it!) and here is how to write and read - you can choose whether you want binary or text. Let me know if you need more help.

#include <iostream>
#include <fstream>
#include <boost\archive\xml_iarchive.hpp>    // XML In
#include <boost\archive\xml_oarchive.hpp>    // XML Out
#include <boost\archive\text_iarchive.hpp>   // Text In
#include <boost\archive\text_oarchive.hpp>   // Text Out
#include <boost\archive\binary_iarchive.hpp> // Binary In
#include <boost\archive\binary_oarchive.hpp> // Binary Out

int main()
{

{
// ofstream ofs("filename.txt", std::ios::trunc);
ofstream ofs("filename.bin", std::ios::binary);

//boost::archive::xml_oarchive oa(ofs, iFlags);
//boost::archive::text_oarchive oa(ofs, iFlags);
boost::archive::text_oarchive oa(ofs, iFlags);
int i = 42;
string s = "hello";
oa << i << s;
}
{
ifstream ifs("filename.bin", std::ios::binary);

//boost::archive::xml_iarchive ia(ifs, iFlags);
//boost::archive::text_iarchive ia(ifs, iFlags);
boost::archive::text_iarchive ia(ifs, iFlags);
int i = 9;
string s;
ia >> i;
ia >> s;
cout << i << " " << s.c_str();
}

cin.get();
return 0;
}

It writes an integer and a string then reads it from a binary file. Read in the same way you have written out. I hope it starts you out on the right path.

## Elixir42

Its true you have to make an effort on your own behalf. But here is the sugar you are after. Read http://www.boost.org/doc/libs/1_55_0/libs/serialization/doc/index.html
(All of it!) and here is how to write and read - you can choose whether you want binary or text. Let me know if you need more help.

#include <iostream>
#include <fstream>
#include <boost\archive\xml_iarchive.hpp>    // XML In
#include <boost\archive\xml_oarchive.hpp>    // XML Out
#include <boost\archive\text_iarchive.hpp>   // Text In
#include <boost\archive\text_oarchive.hpp>   // Text Out
#include <boost\archive\binary_iarchive.hpp> // Binary In
#include <boost\archive\binary_oarchive.hpp> // Binary Out

int main()
{

{
// ofstream ofs("filename.txt", std::ios::trunc);
ofstream ofs("filename.bin", std::ios::binary);

//boost::archive::xml_oarchive oa(ofs, iFlags);
//boost::archive::text_oarchive oa(ofs, iFlags);
boost::archive::text_oarchive oa(ofs, iFlags);
int i = 42;
string s = "hello";
oa << i << s;
}
{
ifstream ifs("filename.bin", std::ios::binary);

//boost::archive::xml_iarchive ia(ifs, iFlags);
//boost::archive::text_iarchive ia(ifs, iFlags);
boost::archive::text_iarchive ia(ifs, iFlags);
int i = 9;
string s;
ia >> i;
ia >> s;
cout << i << " " << s.c_str();
}

cin.get();
return 0;
}

It writes an integer and a string then reads it from a binary file. Read in the same way you have written out. I hope it starts you out on the right path.

## Elixir42

ok ok...
It was a silly question. That's why noone replied to me. You obviously use a pointer to the object. Heres an OTT version using smart pointers:

    boost::shared_ptr<boost::archive::binary_oarchive> m_spBinOA; // Bin Out
boost::shared_ptr<boost::archive::binary_iarchive> m_spBinIA; // Bin In

Then in some implementation somwhere...

// Set flags for boost

// Create boost binary output archive
ISerialization::m_spBinOA =
boost::make_shared<boost::archive::binary_oarchive>
(m_ofs, m_iBoostFlags);

Tada: now I have just paid Daniweb to put my own post here since noone replied :P (hehe)

## Elixir42

Hi Kind-DaniWebbers,

How do you initialise a boost::archive:binary_oarchive in a different place to where you declare it?
So:

class CBase {
std::ofstream m_ofs;
boost::archive:binary_oarchive m_binOA(); // <== default constructor
virtual void Open(std::string& s) = delete;
};

class CDerived : CBase {
void Open(std::string& s) override
{
CBase::m_ofs("filename.bin", std::ios::binary);
CBase::m_binOA(CBase::m_ofs, /*flags*/); // <== says error C2660: '...'::m_binOA' :
// function does not take 2 arguments
}
};

I am trying to create different interfaces for XML, TXT and BIN. So I just derive from the one I want. Is this the way to do it? I struggling to design this. Please can I have some help.

Thanks.

## Elixir42

Thanks @Mike_2000_17
Thanks @Ancient\nDragon

Great answers I really appreciate it. I was just reading the tutorials for boost.Serialization, funny that.

## Elixir42

Dear Kind DaniWebbers,

I am trying to overload the fstream operators (ofstream/ifstream), so that I can save a class to a 'Binary' file and also display it with cout. But the ways in which each need to be implemented is different. Please can you show me how to define different operators for each.

Here is my test class:

class CBase
{
public:
//CBase(void) {};
CBase(int i = 0,
float f = float(0.0),
double d = double(0.0),
char c = 'A') :
iMyInt(i),
fMyFloat(f),
dMyDouble(d),
cMyChar(c) {}
~CBase(void) {}

int    iMyInt;
float  fMyFloat;
double dMyDouble;
char   cMyChar;

friend std::ostream& operator<<(std::ostream& os, CBase& obj)
{
os << obj.iMyInt << " " <<
obj.fMyFloat <<  " " <<
obj.dMyDouble <<  " " <<
obj.cMyChar;

//os.write((char *)&obj.iMyInt, sizeof(obj.iMyInt));
//os.write((char *)&obj.fMyFloat, sizeof(obj.fMyFloat));
//os.write((char *)&obj.dMyDouble, sizeof(obj.dMyDouble));
//os.write((char *)&obj.cMyChar, sizeof(obj.cMyChar));

return os;
}

friend std::istream& operator>>(std::istream& is, CBase& obj)
{

is >> obj.iMyInt >>
obj.fMyFloat >>
obj.dMyDouble >>
obj.cMyChar;

return is;
}
};

## Elixir42

So why shouldn't I put everything in PCHs?

## Elixir42

Thank you Ancient Dragon.
Do i need to specify which, out of the entire list of headers in stdafx.h, that I want to include or do I get the whole shabang? Does the compiler only link in what I call/reference/instatiate ?

## Elixir42

I have read tutorials using my google-fu on how to set up Pre-Compiled Headers, and now I wanted to clear up a few questions:

If all the 'to be pre-compiled' headers go in one file - "stdafx.h" then how do you say you only want 1 of those files in your 'unstable' class headers/implementations?
If the said PCH header only goes at the top of your implementation (.cpp) file then how is your class in the header (.h) file supposed to know about objects?
Does the compiler know because it is included before the implementation includes its own header?
Arrrh there any pitfalls I should know about?

## Elixir42

Yes that's it!
I can't believe I didn't think of that!
God bless you and thanks...!

## Elixir42

I can make it work if I call GetProcAddress manually and pass in a public made handle from the class. But this is not very encapsulated though.
Please can you advise me, as to the remedy of the error, as I'd like to use the templated member function

CDLLLoader::GetProcAddress

## Elixir42

That's great, thank you, but there is a bug in:

CreateFoo = spDLL->GetProcAddress("CreateFooClassInstance");

as it gives me the error: error C2783: 'FuncPtrType CDLLLoader::GetProcAddress(const char *) const' : could not deduce template argument for 'FuncPtrType'

I tried other permutations including .template keyword and even stipulating the template argument type like:

CreateFoo = spDLL->GetProcAddress<fpFunct1>("CreateFooClassInstance");

but this gives me this error:
error C2780: 'FuncPtrType CDLLLoader::GetProcAddress(const char *) const' : expects 1 arguments - 2 provided
Thank you, humbley, for your time.

## Elixir42

Dear Kind-Coders,

I am trying to learn to use boost::shared_ptr to manage the lifetime of a DLL, but I am having a type conversion problem whilst setting it up.

#include <boost/make_shared.hpp>
int main()
{
{
class CMyClass {
public:
CMyClass() {}
~CMyClass() {}

int MyInt;
};

typedef void* (*fpFunct1)();

fpFunct1 CreateFoo;

/***********************************************
Build error because cannot convert
from 'HINSTANCE__ *' to 'HINSTANCE__ **'
************************************************/

// get the function pointer

// get pointer to object
auto pMyClass = boost::make_shared<CMyClass*>
(static_cast<CMyClass*> (CreateFoo()));

(*pMyClass)->MyInt = 9;

} // See destructor/custom_deleter here (FreeLibrary())

return 0;
}

As it is I get the error:
...boost_1_55_0\boost\smart_ptr\shared_ptr.hpp(364): error C2440: 'initializing' : cannot convert from 'HINSTANCE__ *' to 'HINSTANCE__ **'

If I do boost::shared_ptr<HINSTANCE__> spHDL (LoadLibrary("DllMain.dll"), FreeLibrary); instead I get the error:
...error C2664: 'GetProcAddress' : cannot convert parameter 1 from 'HINSTANCE__' to 'HMODULE'

Please can you show me how this is supposed to be done correctly.
Elixir42

## Elixir42

Sorry about the lazyness of not returning values or not initialising the pointers. They are fixed as -
return true in Sip1..5
and
CPerson* pP1 = new CPerson also pP2

I missed the addition of the first argument in the declaration because I was hung up on looking at intellisence's red line on the caller. Which still hasn't gone - even though it compiles and runs perfectly.

Thanks and blessings to you.

## Elixir42

I'm sorry I can't figure this out. I tried
auto fp_Sip = mem_fn(&CAle::Sip1);
Then call as fp_Sip(Ale, pP1, pP2);
But I cant specify auto within the class declaration. I need to use auto with mem_fn because I dont know who to declare the function with the right amount of parameters for both the function requirements and to satisfy mem_fn.

...Please can you show me an example...?

## Elixir42

Hi I'm trying to create an array of function pointers contained within a class, the C++11 way. Can I have some help with this as I'm getting a bit mixed up. Here's what I have done so far. They are made up classes to define the problem.

#include <iostream>
#include <functional>
#include <vector>

using namespace std;

class CPerson;

class CAle
{
public:
CAle(void) {};
~CAle(void) {};

bool Sip1(CPerson* pPerson1, CPerson* pPerson2) { cout << "Sip 1" << endl; };
bool Sip2(CPerson* pPerson1, CPerson* pPerson2) { cout << "Sip 2" << endl; };
bool Sip3(CPerson* pPerson1, CPerson* pPerson2) { cout << "Sip 3" << endl; };
bool Sip4(CPerson* pPerson1, CPerson* pPerson2) { cout << "Sip 4" << endl; };
bool Sip5(CPerson* pPerson1, CPerson* pPerson2) { cout << "Sip 5" << endl; };
};

enum enSIPS
{
enSip1 = 0,
enSip2,
enSip3,
enSip4,
enSip5,
enSipCount
};

class CPerson
{
public:
CPerson(void) {};
~CPerson(void) {};

typedef std::function<bool(CPerson*, CPerson*)> FUNCTIONPOINTER;
vector<FUNCTIONPOINTER> fp_Sip;
};

int main(void)
{
CAle Ale;
CPerson Person;

Person.fp_Sip.push_back(mem_fn(&CAle::Sip1));
Person.fp_Sip.push_back(mem_fn(&CAle::Sip2));
Person.fp_Sip.push_back(mem_fn(&CAle::Sip3));
Person.fp_Sip.push_back(mem_fn(&CAle::Sip4));
Person.fp_Sip.push_back(mem_fn(&CAle::Sip5));

CPerson* pP1, *pP2;
for (auto it = Person.fp_Sip.begin(); it != Person.fp_Sip.end(); ++it)
(*it)(pP1, pP2); // <== Error No instance of function

Person.fp_Sip.at(enSip3)(pP1, pP2); // <== Error No instance of function

cout << "End of program...!";
cin.get();
return 1;
};

Errors:
c:\program files (x86)\microsoft visual studio 11.0\vc\include\xrefwrap(462): error C2440: 'newline' : cannot convert from 'CPerson ' to 'CAle '

and more

## Elixir42

I have finally sorted. btw I didn't post the source. The solution involved carefully looking at the current translation unit and seeing when the undefined class is first (pre)defined. Then open the class and put its include of the class into the implementation instead of the header. Now when it comes around the culprite class to ask for the header it is not yet defined. So it can now define it for itself. I hope I explained it ok? so in the above example I put the #include "CStats.h" called by CSprite.h into the implementation of the CSprite source and it works ok. I do this for each base class undefined error. So some things get included in the header and some in the source.

## Elixir42

Hi,

Please may I have your help on this one. The error is:
1>------ Build started: Project: DXTB 17, Configuration: Debug Win32 ------
1> Main.cpp
1> _MyDebug Defined...
1> _Main Defined...
1> _CApplication Defined...
1> _CSpriteManager Defined...
1> _CSprite Defined...
1> CStats Called...
1> _CStats Defined...
1> _CVector3F Defined...
1> _CText Defined...
1> _CFile Defined...
1> _CMap Defined...
1> _CTile Defined...
1> _CCollisionManager Defined...
1> _CEntity Defined...
1> _CCamera2D Defined...
1> _TPhysics Defined...
1>
CStats Called...
1>d:\code\dx tuts\projects\dxtb_curr\dxtb 17_2\dxtb 17\ccamera2d.h(28): error C2504: 'CStats' : base class undefined

I have header gaurds and pertinent forward declarations where neccassary. I am defining CStats as a base class of CSprite though CSpriteManager. Also as a base class of CCamera2D. Before you say - there are no semicolons missing!

This is CStats:

#pragma message("__CStats Called...")

#ifndef CStats_h
#define CStats_h

#include "MyDebug.h"
#ifdef PRAMGA_MESSAGE_DEFINED
#pragma message("_CStats Defined...")
#endif

#include <d3dx9.h>
#include "CVector3F.h"

class CVector3F;

class CStats
{
public:
CStats(void);
~CStats(void);

// Coordinates
CVector3F* m_pWorldPosition;
CVector3F* m_pScreenPosition;

/*SNIP*/
};

#endif // CStats

This is CCamera2D that the error is produced by:

#ifndef CCamera2D_h
#define CCamera2D_h

#include "MyDebug.h"
#ifdef PRAMGA_MESSAGE_DEFINED
#pragma message("_CCamera2D Defined...")
#endif

#include <d3dx9.h>

#include "TPhysics.h"
#include "CStats.h"
#include "CEntity.h"

class CStats; //<== May not need to be

class CCamera2D: public CStats
{
public:
CCamera2D(void);
~CCamera2D(void);

enENTITYTYPE m_enEntityType;

void ApplyPhysics(void);

// Set velocity for a direction until vel limit is reached
inline void MoveLeft(void)  { m_Physics.VelocityLeft(); }
inline void MoveRight(void) { m_Physics.VelocityRight(); }
inline void MoveUp(void)    { m_Physics.VelocityUp(); }
inline void MoveDown(void)  { m_Physics.VelocityDown(); } ...

## Elixir42

****SOLVED**
Ok, you need to work out the ratio between the window and backbuffer and times it with the x and y like this:

RECT ClientRect;
GetClientRect(m_hWindow,&ClientRect);

ScreenToClient(m_hWindow, &m_MousePos);

Points[0] = D3DXVECTOR2(m_pMyObjectHere->GetScreenPos()->GetCenterX(),
m_pMyObjectHere->GetScreenPos()->GetCenterY());
Points[1] = D3DXVECTOR2(m_MousePos.x * (float(FULLSCREEN_WIDTH) / ClientRect.right),
m_MousePos.y * (float(FULLSCREEN_HEIGHT) / ClientRect.bottom));

This works whether the window is windowed, bordered, borderless or fullscreen. Make sure you use/convert your variables here to floats to preserve the exponent. Yippee...!!!

## Elixir42

Thanks Ancient Dragon. The coordinates I pass come from GetCursorPos(). How do I translate from Client to 1920x1080. Maybe times by the differance between windowed res and fullscreen? But how do you do that? Here's my attempt:

// Get mouse position in screen coordinates
GetCursorPos(&m_MousePos);

// Translate to client coorndinates
ScreenToClient(m_hWindow, &m_MousePos);

// Save and later pass to line function
Points[0] = D3DXVECTOR2(m_pAnyObject->GetScreenPos()->GetCenterX(),
m_pAnyObject->GetScreenPos()->GetCenterY());
Points[1] = D3DXVECTOR2(float(m_MousePos.x),
float(m_MousePos.y));

To make it clearer my window is displaying a squashed (on purpose) fullscreen image.

## Elixir42

Hi ,

Please can anyone help. I have a window(1280x768) that contains a resolution(1920x1080). I am trying to use ScreenToClient to obtain the mouse coordinates while in windowed format. I am drawing a line from a subject to the mouse cursor which works fine in fullscreen but not in windowed.

The ScreenToClient function doesn't quite work because (I speculate) of the resolution. Does anyone know of a way to correct this...?

## Elixir42

*SOLVED*****
anytime there is an access violation, in this context, it means that I was trying to access resources that device->reset had, well, reset! The simple solution was to find and track down which object I had not called OnLostDevice and OnResetDevice for. This includes all ID3DXSprite and D3DXFont and D3DXLine interfaces/objects.

God bless you in Jesus name

## Elixir42

Hi,

Im using DX9c and learning from Frank Luna's book to try and handle OnLostDevice and OnResetDevice, when switching to fullscreen and back (and alt+tabbing).
If I dont draw anything I am able to go from windowed to fullscreen, and back, with no trouble. But adding a draw and flush then pressing the fullscreen key causes the following msgbox error: (at the m_pSprite->flush();)

Unhandled exception at 0x56E5B1FC (D3DX9_43.dll) in DXTB 14.exe: 0xC0000005: Access violation writing location 0xCCD020CC.

Although I do enjoy getting stuck on problems I have been rearranging my code and typing like a monkey for 1 week now (on this issue). Please can you correct where I am going wrong?

Resolution is sweeter the longer you wait. (please dont qoute it back at me though! hehe)