|
|
exp is the wrong function. exp(x) is e^x. pow is the correct function to use.
Steve
|
|
|
|
|
You're right. My mind isn't currently working.
|
|
|
|
|
There is no exponentiation operator in C - ^ does a bitwise XOR. Use pow() instead.
|
|
|
|
|
This one has confused the hell out of me.
I have a class which has a std::vector static member. From the c'tor I initialize this vector. The initialization is quite lengthy but can be shared amongst all instances hence the static.
When I later come to use the vector ( from the same instance ), it's empty! How could this be happening?
|
|
|
|
|
Can you post some code?
Steve
|
|
|
|
|
There's not really any code to post.
The instance is created in global scope, yet when I call one of the methods the vector is empty. If I create the instance within the same function as the call to the method, it's fine. So I'm guessing the problem relates to initializing a static member from the global scope.
|
|
|
|
|
Put breakpoints on the vector initialisation code and method in question. Which one is hit first? I'd guess you're relying on the order of static initialisation.
Steve
|
|
|
|
|
The class is created in global scope, the c'tor is called before main(), which initializes the static vector. Within main() I call a method which uses the initialized vector, only to find it empty. Breakpoints confirm that the vector is indeed initialized. So somewhere between the global scope c'tor and main() the vector is being set back to empty.
|
|
|
|
|
The next thing to test is if the vector is ever filled. Perhaps there is a bug in the initialisation code. Put a call to std::vector::empty after the initialisation code and verify it actually gets filled. i.e.
assert(!s_MyVector.empty());
Steve
|
|
|
|
|
Steven, forgive me for being blunt, but I would not post on the forum without first checking trivial things such as that. The vector is initialized. But when I come to use it it is not initialized.
|
|
|
|
|
Even the best of us make stupid mistakes. I've done worse, and I'd wager so have you. Can you put together some minimal code which shows the problem? There's only so far you can go when the problems so abstract.
Steve
|
|
|
|
|
hi,
I'm working with VS2005, and my project is in C++.
I want to do a treeview where root nodes are pictures and child nodes are normal (icon + texte)
I will be something like that :
<br />
[----root1picture----]<br />
...[ico] root1child1text<br />
...[ico] root1child2text<br />
[----root2picture----]<br />
...[ico] root2child1text<br />
my problem is when I put my root1picture in the root1 icon and no text for the root1, I have a huge indent value(because my root picture is long) for all the childs, and i'm not allowed to change it. I bet that is not a good solution to put my root's pictures in the root node icon with no text.
somebody know how could I do ?
thanks,
|
|
|
|
|
I have a very simple DLL
dll header
__declspec(dllexport) int StartUp();
dll cpp
__declspec(dllexport) int StartUp()
{
return 42;
}
my console app
typedef int (*MYPROC)();
int _tmain(int argc, _TCHAR* argv[])
{
HMODULE c1 = LoadLibrary(L"client1.dll");
MYPROC ProcAdd = (MYPROC) GetProcAddress(c1, "StartUp");
int i = (ProcAdd)();
return 0;
}
GetProcAddress fails, returning NULL. (LoadLibrary suceed)
ANy ideas why?
|
|
|
|
|
I would guess name mangling. Try making your code look like this:
extern "C" __declspec(dllexport) int StartUp();
Steve
|
|
|
|
|
Thanks
|
|
|
|
|
To complement what Stephen said: in C++ you have the ability to overload a function (that is, provide the same name but different arguments type or a different number of argument). Thus, in that case, a function is identified not only by its name but also by its parameters.
In C, function overloading doesn't exist thus functions are identified only by their name.
This mechanism is used by the linker to identify the different functions, in C he will use only the function name and in C++ he will use the function name plus a 'description' of the parameter list.
So, if you declare that the function has a C linkage (by using the keyword extern "C"), you specify that the function use the C linkage, meaning that only its name is used to identify it. But that also mean that you won't be able to overload the function.
|
|
|
|
|
For future reference, you can run dumpbin /exports or depends on the DLL to see exactly what the exported name is. In your case, your original code wasn't working because the function was exported as a C++ function and was given a decorated name by the compiler.
|
|
|
|
|
Hey,
I've created an SDI MFC app that needs to switch between several standard view classes and a Direct3D surface. I've managed to do this by preserving the HDC, destroying the CView, creating a new one, attaching the HDC then creating a new directx surface within the view class.
The Texture for each triangle set is loaded from a file when the vertex buffer is created. This means the textures are reloaded everytime the view is changed, which is taking too long.
I've tried not releasing the texture buffers between view switches, but the textures then get mixed up and some are missing.
My question is, what is the best way cache / store textures that need to be reloaded alot ?
Also do i need to destroy the DirectX Render Surface at all or can it be hidden behind a CView class?
Thanks
|
|
|
|
|
This is how I have done things:
1. Create a class for loading and unloading textures.
2. Track the filename of each texture loaded.
3. Keep a reference count for each texture.
4. If the texture is already loaded, return the same pointer.
When more than one method requests the same texture they get the same pointer. You can lock the texture by increasing the ref count and release it when the ref count reaches 0. If you keep this class in global scope, you will never need to reload the same texture more than once.
spacecadet10 wrote: Also do i need to destroy the DirectX Render Surface at all or can it be hidden behind a CView class?
You need to release everything you create. Usualy D3D will attempt this on exit, but it's better for you to do it.
|
|
|
|
|
Thanks for the response chap.
I've tried to do that but i'm using the D3DXCreateTextureFromFile() method to load a mixture of bmp and dds files.
when the LPDIRECT3DDEVICE8 i used to load the file gets released, everytime the user switches to a different view class, the textures get all screwed up.
Is it possible to temporarily hide the Direct 3D device, while looking at another view ?
Cheers
|
|
|
|
|
I'm am currently writing an application where a user tries to find his way in a maze. I want the user to be able to control his movements either by clicking on 3 buttons in the main window, or by using these 3 arrow keys: up, left, right. The 3 buttons are linked to the three functions: OnBgofront(), OnBturnleft() and OnBturnright() - those three functions manage the maze navigation. When the user wants to start the maze, he clicks the button labeled GO which is linked to the OnBgo() function.
My problem is that, after the GO button is clicked, if the user start by pressing one of the arrow keys instead of using one of the three buttons, nothing happens: no movement in the maze. On the other hand, if one of the 3 buttons is clicked, there is a movement in the maze, and then after that the arrow keys behave normally (ie the functions OnBgofront(), OnBturnleft() and OnBturnright() are called). Could you tell me how I could modify my code so that the user can use the arrow keys whithout having to press one of the 3 buttons first?
A BIG thank you in advance
Marc
oh! here is the OnBgo function code:
void MyAppDlg::OnBgo( )
{
MSG tMsg;
m_bRunning = true;
:
:
while ( m_bRunning )
{
:
MyGrid.display (m_maze);
:
while ( ::PeekMessage(&tMsg, NULL, 0, 0, PM_REMOVE))
{
if (tMsg.message == WM_KEYUP)
{
switch ( tMsg.wParam )
{
case VK_UP:
OnBgofront();
break;
case VK_LEFT:
OnBturnleft();
break;
case VK_RIGHT:
OnBturnright();
break;
case VK_ESCAPE:
m_bRunning = false;
}
}
else
{
::TranslateMessage(&tMsg);
::DispatchMessage(&tMsg);
}
}
}
}
Marc Melillo
biomedical engineer
Universite de Montreal
marc.melillo@umontreal.ca
|
|
|
|
|
I used the CSplitterWnd::GetActivePane(int&, int&) function and it worked fine with VC++ 6.0.
Recently I started the process of moving the code to the new VC++ 2005.
Under VC++ 2005, the code compiled OK but it does not run because the GetActivePane function
is somehow made obsolete (see afxext.inl). Any idea why?
So how do I get this function back or any ways to get around of this problem?
Thanks
Ted
|
|
|
|
|
I'm still on 2003 but I see nothing in the 2005 docs online that says the method is obsolete.
That would break alot of MFC apps.
They do move stuff around between MFC versions though (from cpp files to inline, etc.) which
can potentially cause problems (shouldn't affect runtime though).
Are you sure you aren't mixing MFC versions anywhere?
Mark
|
|
|
|
|
I'm pretty sure I'm not mixing the versions.
I checked MSDN and nothing was said about GetActivePane being obsolete. Might be
a bug/mistake on MS side?
Also, VC++ 2005 changed the scope of variables defined for a loop and generates
errors in cases like this:
for(int i = 0; i < 10; i++)
A = i*2;
for(i = 11; i < 50; i++) // this will generate an error, as i is not declared.
B = i*3;
Have to edit a lot of source code to remove the compiler errors.
Ted
|
|
|
|