|
I have a pretty difficult DLL problem to solve and I a little bit in the air right now.
I am developing a game engine with a "Resource Manager" which is in essence a linked list storing pointers to "Resource" classes. This setup deals with data that needs to be loaded/shared/released. All classes that load data are derived from "Resource" and on loading are registered with the global resource manager.
So that when the game requests e.g a texture a second time it gets the pointer to the already loaded texture object... Hope that is understandable..
This setup works quite well with the built in resource classes (Texture,Movie,Sound etc)
But now i allow extension DLLs which allow to add functionality to the game engine through plugin classes which are derived from "Object" and sent back to the game engine through a DLL exported function like extern "C" __declspec(dllexport) Object * CreateEngineObject( const char * classname )
This works ok too... But now i want to allow different Resource classes too in the extension DLL and here i get a crash when the resource manager tries to delete such a class (the destructor is never reached) There is one global resource manager in the engine dll ...
The engine is setup like this.
Game.exe // Small executable
Engine.DLL // All the engine classes, including ResourceManager,and Resource, those classes are also Exported via __declspec (dllexport)
Plugin1.dll the basic plugin for my tests. here i define a XMESH class derived from Resource which is alos __declspec(dllexport) exported....
The Runtime lib for all configs is of course "Multihreaded DLL"...
I don't have a clue what that could be anymore...
If anyone wants to see the code i can send a 18 MB Setup file which contains the whole project which is compilable via VC6 SP4 without anything additional ... out of the box..
Thanks in advance
Bernhard Glueck
|
|
|
|
|
Try
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
at beginning of every member function exported or every DLL function explicit exported.
Oscar L.
|
|
|
|
|
Hm this AFX_MANAGE_STATE.. isn't that a MFC Specifc Macro/Function ?
I am only using the native WIN32 API and DirectX 8.0 no MFC whatsoever...
Till next time.
|
|
|
|
|
Some new facts after long debugging sessions
After Removing the virtual in "virtual ~Resource"
the first bug is gone. the destructor is called, but only from the base class, however no crash occurs anymore
The problem itselt persists since now all the other virtual methods of the class fail...
Any ideas ?
|
|
|
|
|
Can you post the declaration, constructor & destructor for the Resource and XMESH classes?
|
|
|
|
|
Just a hunch, but apparently your resources involve GDI objects? Bitmaps? Are you sure your cleanup is not doing a DeleteObject call on something still selected into the DC? When you remove the virtual from the destructor, that chain is broken and the gdi object is not deleted, hence, no crash, just a leak. You wouldn't be the first person to be bit by that.
|
|
|
|
|
I have a TreeView that I would like to have popup menus appear in when people rightclick. How does one go about making popup menus like this?
-Jack Mott
jackm@scalablesoftware.com
|
|
|
|
|
Handle WM_CONTEXTMENU in the tree and call TrackPopupMenu or TrackPopupMenuEx.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
thanks, got it working!
-Jack Mott
jackm@scalablesoftware.com
|
|
|
|
|
Greetings,
I was wondering how I can convert a LOGFONT's lfHeight into a CHARFORMAT's yHeight?
I don't have access to the DC or a handle to the HDC.
Is there a conversion formula that I can use?
I know that you take 20*pointsize to get the height of the yHeight, but
I am not sure how to go from a logfont height to a yHeight.
ie: -48 is what in yHeight?
Thanks in advance!!!!
|
|
|
|
|
Howdy folks,
Please help me understand the concept of memory allocation in win32 dll's written in c++. I have found that when I use 'new' and 'delete' I often get access violations. I've done some reading, but am still confused. Blaszczak is silent on this issue. Brain ("Win32 System Services") says to use 'GlobalAlloc' in dlls, but doesn't really say why.
Here is an example that confuses me:
<br />
#include <windows.h><br />
#define _COMPILING_DCC237C0_6FEE_11d5_A91C_0050DAC6D85C_<br />
#include "JunkDll.h"<br />
<br />
HGLOBAL secret;
<br />
BOOL WINAPI main(HINSTANCE dllhandle, DWORD reason, LPVOID situation)<br />
{<br />
switch(reason)<br />
{<br />
case DLL_PROCESS_ATTACH :<br />
OutputDebugString("DLL_PROCESS_ATTACH\n");<br />
secret = GlobalAlloc(GPTR,100*sizeof(char));
strcpy((char*)secret,"The meaning of life is 42.\n");<br />
break;<br />
case DLL_PROCESS_DETACH:<br />
OutputDebugString("DLL_PROCESS_DETACH\n");
if(secret)<br />
GlobalFree(secret);<br />
break;<br />
}<br />
<br />
return TRUE;<br />
}<br />
<br />
char* getMeaningOfLife(char* buffer)<br />
{<br />
if(buffer != 0)<br />
strcpy(buffer,(char*)secret);<br />
return buffer;<br />
}<br />
<code> <br />
<br />
In the above example, if I define 'secret' as char* secret, and then use new and delete to allocate a buffer for it I get an acess violation. When I use GlobalAlloc as shown, it works. The help files say to use the heap function instead of GlobalAlloc, but I've never used them.<br />
<br />
I'm clearly missing the big picture on memory allocation for dlls. Brain talks about four different dll memory models, but I'm not grocking the concept.<br />
<br />
thanks<br />
<br />
Jim <br />
:confused:
|
|
|
|
|
It should be possible to call new in DllMain called with DLL_PROCESS_ATTACH parameter. Each MFC extension DLL has a call to new in its initialization code:
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("CORE.DLL Initializing!\n");
if (!AfxInitExtensionModule(CoreDLL, hInstance))
return 0;
new CDynLinkLibrary(CoreDLL);
}
Is DllMain the 'raw' entrypoint to your DLL, or is it called from _DllMainCRTStartup? Put the breakpoint in the DllMain and check the stack.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks Thomas. The example that I gave is a pure 'C' dll, not using MFC or C++ classes. I call the function from an exe program by either late binding (loadlibrary) or early binding (linking in the lib file). In both cases 'secret = new char[100]' throws an access violation.
I'm sure that 'new' works in dll's under some circumstances. Looking through the MFC source, they are doing all kinds of fancy stuff in AfxInitExtensionModule with both memory and threading. Something the MFC programmer did lets new work, but I don't percieve how they did it.
I'm just trying to understand why my new's don't work in this simple case. If I can understand that, then perhaps I can understand what MFC is doing in that deceptively simple call to AfxInitExtensionModule.
Jim
|
|
|
|
|
AfxInitExtensionModule has nothing to do with the problem. I can call new without any errors before AfxInitExtensionModule.
Anyway, I think your DllMain is called directly by Windows (usually the raw entrypoint is _DllMainCRTStartup), C/C++ runtime is not initialized yet and new/malloc fail. Check the KB article Q94248 for more info.
BTW, if your DLL is pure 'C', how could you compile 'new char[100]'?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thank Tomasz, that clears it up. My problem was indeed that the C runtime was not being intialized because I inadvertantly had "main" instead of DllMain as my entry point. The KB article was very helpful, and my example now works with new and delete. I think I understand that the price of using new and delete is that I have to load the C runtime. If for some reason I didn't want the C runtime, then I take it that I could use GlobalAlloc instead of new and delete.
Sorry the ambiguity about pure 'C'. My interface is straight 'C', but my implementation uses C++ features.
thanks
Jim
|
|
|
|
|
When I initialize the C runtime the release version of my example program is 44K. When I don't use the C runtime and use GlobalAlloc/GlobalFree instead, my program is only 20K.
For routine desktop apps that 24K delta is nothing, for space critical programs it could make a difference.
Jim
|
|
|
|
|
When running my program on a 98 box, everything seems to go through smoothly. When running on a Win2000 box, it crashes. I have isolated a commonality between this issue and few other issues in that somewhere along the line it has to display the MSFLEXGRID OCX control. Does there happen to be an extra step in getting the MSFLEXGRID control registered for Win2000? Or perhaps it is registered and it's just something else. It seems 98 recognizes the control.
Thanks!
Chris
Customer: "It seems you have bugs that are inconsistant!"
Support: "We have a patch that makes them consistant."
|
|
|
|
|
I'm writing an SDI application that requires the user to drag a file folder and drop it on to the program in order to start processing the files in that folder. I have no idea where to begin. Can anyone help me?
|
|
|
|
|
1) Call CWnd::DragAcceptFiles for each window that's going to be the drop target (in SDI app it would be main frame and/or view).
2) handle WM_DROPFILES message in windows acting as drop targets.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I am trying to use binary search but it is failing every time even when the item is in the deque:
std::deque<int>::iterator i1 = d.begin();
std::deque<int>::iterator i2 = d.end();
bool success = std::binary_search(i1, i2, 999);
// number 999 is an item in the queue
success is always = to 0, am i doing something wrong?!
Or in general does anyone have any advice on making use of the STL algorithms?
thanks
|
|
|
|
|
what do your comparison operators look like (less than, equal) ?
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Are you sure that the deque d is sorted before calling binary_search ?
|
|
|
|
|
Hello,
I would to know if there is a funtion that allow me to Unzip a file through VC++.
Thanks for help.
R.G
|
|
|
|
|
try searching the site...
http://www.codeproject.com/cpp/zip.asp
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Thanks !
But I would like to know if there are a simple MFC function to uncompress a file zip.
|
|
|
|