469,898 Members | 1,581 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

VC++.NET 2002 and VC++.NET 2003 Co-Exist Side-by-Side Probblems

SHC
Hi all,
1) I have used VC++.NET 2002 (v7.0) for a while. Recently I just installed
VC++.NET 2003 (v7.1) - I saw the message "Settings were not migrated from
Visual Studio.NET 2002 to Visual Studio,NET 2003" during the installation.
Do I have to do the migration of the "Settings" if I want to use the both
versions of VC++.NET in the Side-by-Side fashion?
2) I ran the "Build" of the example 'Chapter5_Example1' of 'Beginning
DirectX 9' by W. Jones and I got the fatal error C1083: Cannot open include
file: 'd3d9.hc\BeginningDirectX9\Chapter5\example1\winma in.cpp.'
But the #include <d3d9.h> is in the library - see the attached file. What
causes this prblem? Did I launch the program in the wrong path/folder? How
can I execute the program right?
Please help and advise.
Thanks in advance,
shc
/////--Chapter5_Example1\winmain.cpp---/////
#include <windows.h>
#include <mmsystem.h>
#include <d3d9.h>
#include <d3dx9tex.h>
#include <string>
using namespace std;

HINSTANCE hInst; // holds the instance for this app
HWND wndHandle; // global window handle

LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; // Buffer to hold vertices

// A structure for our custom vertex type
struct CUSTOMVERTEX
{
FLOAT x, y, z, rhw; // The untransformed, 3D position for the vertex
DWORD color; // The vertex color
};

// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)

LPDIRECT3D9 pD3D;
LPDIRECT3DDEVICE9 pd3dDevice;

////////////////////////////////////////////// forward declarations
bool initWindow(HINSTANCE hInstance);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

// direct3D functions
HRESULT SetupVB();
bool initDirect3D(HWND hwnd);
void shutdown(void);
LPDIRECT3DVERTEXBUFFER9 createVertexBuffer(int size, DWORD usage);
void drawVB(LPDIRECT3DVERTEXBUFFER9 buffer);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR
lpCmdLine, int nCmdShow)
{
// call our function to init and create our window
if (!initWindow(hInstance))
{
MessageBox(NULL, "Unable to create window", "ERROR", MB_OK);
return false;
}

// init direct3d
initDirect3D(wndHandle);

// setup the vertex buffer and add the triangle to it.
SetupVB();

// Main message loop:
// Enter the message loop
MSG msg;
ZeroMemory( &msg, sizeof(msg) );
while( msg.message!=WM_QUIT )
{
// check for messages
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
// this is called when no messages are pending
else
{
// call our render function
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f,
0 );

pd3dDevice->BeginScene();

// draw the contents of the vertex buffer
drawVB(g_pVB);

pd3dDevice->EndScene();

pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
}

// shutdown the directx manager
shutdown();

return (int) msg.wParam;
}

HRESULT SetupVB()
{
HRESULT hr;

// Initialize three vertices for rendering a triangle
CUSTOMVERTEX g_Vertices[] =
{
{ 320.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_ARGB(0,255,0,0), }, // x, y,
z, rhw, color
{ 250.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_ARGB(0,0,255,0), },
{ 50.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_ARGB(0,0,0,255), },
};

// Create the vertex buffer
g_pVB = createVertexBuffer(3*sizeof(CUSTOMVERTEX), D3DFVF_CUSTOMVERTEX);

// Fill the vertex buffer.
VOID* pVertices;

hr = g_pVB->Lock( 0, sizeof(g_Vertices), (void**)&pVertices, 0 );
if FAILED (hr)
return E_FAIL;

// copy the vertices into the buffer
memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );

// unlock the vertex buffer
g_pVB->Unlock();

return S_OK;
}

bool initDirect3D(HWND hwnd)
{
HRESULT hr;

if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
return false;
}

D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferHeight = 480;
d3dpp.BackBufferWidth = 640;
d3dpp.hDeviceWindow = hwnd;

hr = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &pd3dDevice );
if FAILED (hr)
{
return false;
}

return true;
}

LPDIRECT3DVERTEXBUFFER9 createVertexBuffer(int size, DWORD usage)
{
HRESULT hr;
LPDIRECT3DVERTEXBUFFER9 buffer;

// Create the vertex buffer.
hr = pd3dDevice->CreateVertexBuffer( size,
0,
usage,
D3DPOOL_DEFAULT,
&buffer,
NULL );
if FAILED ( hr)
return NULL;

return buffer;
}

void drawVB(LPDIRECT3DVERTEXBUFFER9 buffer)
{
pd3dDevice->SetStreamSource( 0, buffer, 0, sizeof(CUSTOMVERTEX) );
pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );
}

void shutdown(void)
{
if( pd3dDevice != NULL)
{
pd3dDevice->Release();
pd3dDevice = NULL;
}
if( pD3D != NULL)
{
pD3D->Release();
pD3D = NULL;
}
}

bool initWindow(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "DirectXExample";
wcex.hIconSm = 0;
RegisterClassEx(&wcex);

wndHandle = CreateWindow("DirectXExample",
"DirectXExample",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL);
if (!wndHandle)
return false;

ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);

return true;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
SHC
Nov 17 '05 #1
3 1441
SHC wrote:
Hi all,
1) I have used VC++.NET 2002 (v7.0) for a while. Recently I just
installed VC++.NET 2003 (v7.1) - I saw the message "Settings were not
migrated from Visual Studio.NET 2002 to Visual Studio,NET 2003"
during the installation. Do I have to do the migration of the
"Settings" if I want to use the both versions of VC++.NET in the
Side-by-Side fashion? 2) I ran the "Build" of the example
'Chapter5_Example1' of 'Beginning DirectX 9' by W. Jones and I got
the fatal error C1083: Cannot open include file:
'd3d9.hc\BeginningDirectX9\Chapter5\example1\winma in.cpp.'
But the #include <d3d9.h> is in the library - see the attached file.
What causes this prblem? Did I launch the program in the wrong
path/folder? How can I execute the program right?


What do you mean by "<d3d9.h> is in the library"?

Make sure that the Direct-X SDK include directory is in the list of include
directories for Visual Studio 2003. Go to Tools|Options|Projects|C++
Directories|Include files from the menu. If the include directory isn't
there (which it apparently isn't), you probably also need to add the
corresponding d3d LIB directory to the libraries path (located nearby).

-cd
Nov 17 '05 #2
SHC
Hi Carl, Thank you very much for your valuable response and tips.
I did what you said and added C:\DX90SDK\Include, C:\DX90SDK\lib and
C:\DX90SDK\Utilities to the Tools|Options|Projects|C++ Directory.
If I clicked on the examples of the Jones' book on my C:\Drive, the VC++
..NET 2003, the "Build" and "Start Without Debugging" worked fine and I got
the right results.
If I created a new project called "WJCh4Ex1" from the scratch, and clicked
on "Build", I got the following errors:

WJCh4Ex1 error LNK2001: unresolved external symbol "struct IDirect3D9 *
__stdcall Direct3DCreate9(unsigned int)"
(?Direct3DCreate9@@$$J14YGPAUIDirect3D9@@I@Z)
WJCh4Ex1 fatal error LNK1120: 1 unresolved externals

I have no ideas what the errors are and how to correct them.
Please help again and tell me what I should do to get my created "WJCh4Ex1"
project working right.

Thanks,
SHC

//////--WJCh4Ex1____WinMain,cpp----/////
#include <windows.h>
#include <mmsystem.h>
#include <d3d9.h>
#include <d3dx9tex.h>
#include <string>
using namespace std;

HINSTANCE hInst; // holds the instance for this app
HWND wndHandle; // global window handle

LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; // Buffer to hold vertices

// A structure for our custom vertex type
struct CUSTOMVERTEX
{
FLOAT x, y, z, rhw; // The untransformed, 3D position for the vertex
DWORD color; // The vertex color
};

// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)

LPDIRECT3D9 pD3D;
LPDIRECT3DDEVICE9 pd3dDevice;

////////////////////////////////////////////// forward declarations
bool initWindow(HINSTANCE hInstance);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

// direct3D functions
HRESULT SetupVB();
bool initDirect3D(HWND hwnd);
void shutdown(void);
LPDIRECT3DVERTEXBUFFER9 createVertexBuffer(int size, DWORD usage);
void drawVB(LPDIRECT3DVERTEXBUFFER9 buffer);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR
lpCmdLine, int nCmdShow)
{
// call our function to init and create our window
if (!initWindow(hInstance))
{
MessageBox(NULL, "Unable to create window", "ERROR", MB_OK);
return false;
}

// init direct3d
initDirect3D(wndHandle);

// setup the vertex buffer and add the triangle to it.
SetupVB();

// Main message loop:
// Enter the message loop
MSG msg;
ZeroMemory( &msg, sizeof(msg) );
while( msg.message!=WM_QUIT )
{
// check for messages
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
// this is called when no messages are pending
else
{
// call our render function
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f,
0 );

pd3dDevice->BeginScene();

// draw the contents of the vertex buffer
drawVB(g_pVB);

pd3dDevice->EndScene();

pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
}

// shutdown the directx manager
shutdown();

return (int) msg.wParam;
}

HRESULT SetupVB()
{
HRESULT hr;

// Initialize three vertices for rendering a triangle
CUSTOMVERTEX g_Vertices[] =
{
{ 320.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_ARGB(0,255,0,0), }, // x, y,
z, rhw, color
{ 250.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_ARGB(0,0,255,0), },
{ 50.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_ARGB(0,0,0,255), },
};

// Create the vertex buffer
g_pVB = createVertexBuffer(3*sizeof(CUSTOMVERTEX), D3DFVF_CUSTOMVERTEX);

// Fill the vertex buffer.
VOID* pVertices;

hr = g_pVB->Lock( 0, sizeof(g_Vertices), (void**)&pVertices, 0 );
if FAILED (hr)
return E_FAIL;

// copy the vertices into the buffer
memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );

// unlock the vertex buffer
g_pVB->Unlock();

return S_OK;
}

bool initDirect3D(HWND hwnd)
{
HRESULT hr;

if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
return false;
}

D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferHeight = 480;
d3dpp.BackBufferWidth = 640;
d3dpp.hDeviceWindow = hwnd;

hr = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &pd3dDevice );
if FAILED (hr)
{
return false;
}

return true;
}

LPDIRECT3DVERTEXBUFFER9 createVertexBuffer(int size, DWORD usage)
{
HRESULT hr;
LPDIRECT3DVERTEXBUFFER9 buffer;

// Create the vertex buffer.
hr = pd3dDevice->CreateVertexBuffer( size,
0,
usage,
D3DPOOL_DEFAULT,
&buffer,
NULL );
if FAILED ( hr)
return NULL;

return buffer;
}

void drawVB(LPDIRECT3DVERTEXBUFFER9 buffer)
{
pd3dDevice->SetStreamSource( 0, buffer, 0, sizeof(CUSTOMVERTEX) );
pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );
}

void shutdown(void)
{
if( pd3dDevice != NULL)
{
pd3dDevice->Release();
pd3dDevice = NULL;
}
if( pD3D != NULL)
{
pD3D->Release();
pD3D = NULL;
}
}

bool initWindow(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "DirectXExample";
wcex.hIconSm = 0;
RegisterClassEx(&wcex);

wndHandle = CreateWindow("DirectXExample",
"DirectXExample",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL);
if (!wndHandle)
return false;

ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);

return true;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}


Nov 17 '05 #3
SHC wrote:
Hi Carl, Thank you very much for your valuable response and tips.
I did what you said and added C:\DX90SDK\Include, C:\DX90SDK\lib and
C:\DX90SDK\Utilities to the Tools|Options|Projects|C++ Directory.
If I clicked on the examples of the Jones' book on my C:\Drive, the
VC++ .NET 2003, the "Build" and "Start Without Debugging" worked fine
and I got the right results.
If I created a new project called "WJCh4Ex1" from the scratch, and
clicked on "Build", I got the following errors:

WJCh4Ex1 error LNK2001: unresolved external symbol "struct IDirect3D9
* __stdcall Direct3DCreate9(unsigned int)"
(?Direct3DCreate9@@$$J14YGPAUIDirect3D9@@I@Z)
WJCh4Ex1 fatal error LNK1120: 1 unresolved externals

I have no ideas what the errors are and how to correct them.
Please help again and tell me what I should do to get my created
"WJCh4Ex1" project working right.


You need to add d3d9.lib to the "additional dependencies" section of the
Linker properties for your new project. (Project|Properties|Linker|Input
from the menu).

-cd
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John Harrison | last post: by
36 posts views Thread by Tim | last post: by
10 posts views Thread by msnews.microsoft.com | last post: by
1 post views Thread by Johan Nilsson | last post: by
4 posts views Thread by Hyo-Han Kim | last post: by
7 posts views Thread by Mihajlo Cvetanović | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.