Unmanaged C++ in windows forms application

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
i dont work with wiwndows forms applications or managed c++ very often so im new to alot of the rules. i have a program which is supposed to render a directx window using a handle from one of the objects in the windows forms. i have created a class called
"Engine" to encapsulate all the needed functions and data. i have gotten the program to work but it only works if i put what would be the private data in the Engine Class in a namespace in global scope declared as static. This seems very crude and there has
to be a better way. i have gotten classes to access private variables before but in this case when i run the program i get a runtime error of "System.NullReferenceException" on any private variable even if i initiate it in the constructor. heres some sample
code from the header file:

<div style="color:black; background-color:white
<pre><span style="color:blue class Engine {
<span style="color:blue public:

Engine();
~Engine();

<span style="color:blue void InitD3D(HWND hWnd);
<span style="color:blue void Update();
<span style="color:blue int RenderStart();
<span style="color:blue int RenderStop();

<span style="color:blue void ClearScene(D3DCOLOR color);<br/><br/><span style="color:blue private:<br/> LPDIRECT3DDEVICE9 p_device;
LPDIRECT3D9 p_d3d;
HWND p_windowHandle;

<span style="color:blue long p_frameCount_core;
<span style="color:blue long p_frameRate_core;<br/>};

[/code]

<br/>
as you can see it is very simple at the moment. iv defined the Update funtion in the CPP file as so:


<pre>void Engine::Update()
{
static Timer timedUpdate;

//calculate core framerate
p_frameCount_core++;
if (p_coreTimer.stopwatch(999))
{
p_frameRate_core = p_frameCount_core;
p_frameCount_core = 0;
}
//update with 60fps timing
if (!timedUpdate.stopwatch(14))
Sleep(1);
else {
this->ClearScene(D3DCOLOR_XRGB(0, 40, 100));
//begin rendering
this->RenderStart();
//done rendering
this->RenderStop();
}
}[/code]
<br/>
but i get a runtime error of "System.NullReferenceException" at the line with "p_frameCount_core++;" iv set the variables = to zero in the constructor but not luck.

any help is greatly appreciated

-Ryan

<br/>

View the full article
 
Back
Top