|
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.
|
|
|
|
|
no.
-Jack Mott
jackm@scalablesoftware.com
|
|
|
|
|
I prefer the SawZip ATL Control by Franky Bream. It is easier to use, IMHO, and does not require a license.
---
Multitasking: Screwing up several things at once.
|
|
|
|
|
No, but there is a free library called ZLIB that will help you.
There is also free ActiveX controls around, even one on codeproject called SawZip that will do it. And finally I have a few c++ classes on my web site
that could do help you.
www.codeproject.com/atl/sawzip.asp
www.gzip.org/zlib/
www.viksoe.dk/code (last item in c++ section)
Bjarke Viksoe
My code at: www.viksoe.dk/code
|
|
|
|
|
Thanks
|
|
|
|
|
Hi,
I have a linked_list class, and item class.
class item : public CObject
{
DECLARE_SERIAL(item)
public:
virtual void Serialize(CArchive& ar);
int Angle_D;
CPoint Coord;
int value;
item* next;
}
class linked_list : public CObject
{
DECLARE_SERIAL(linked_list)
public:
virtual void Serialize(CArchive& ar);
void add(int Intensity, CPoint coord, double angle_D);
CPoint m_PCenter;
int HowBig();
void Del ();
linked_list();
virtual ~linked_list();
private:
item* start;
};
i added class item in the header file of my linked_list class.
In my application(MDI) i have a linked_list vairable ( mylist).
so when i want to serialize it, i just:
void CTurboMechDoc::Serialize(CArchive& ar)
{
mylist.Serialize(ar);
}
then in linked_list class:
void linked_list::Serialize(CArchive &ar)
{
item* ptr= start;
CObject ::Serialize(ar);
while(ptr->next != NULL)
{
ptr->Serialize(ar);
ptr=ptr->next;
}
}
and finally in class item:
void item::Serialize(CArchive &ar)
{
CObject::Serialize(ar);
if(ar.IsStoring())
{
ar << Coord;
}
else
ar >> Coord;
}
and i did write IMPLEMENT_SERIAL(classname, CObject,1) for linked_list and item class.
ofcourse the file linked_list.cpp contains the implimentations of both item class and linked)list.
i do have a bitmap displayed as well, but i didn't serialize that.
the problem is that it doesn't work.
can anyone help me?
Ehsan
Ehsan Behboudi
|
|
|
|
|
1) why are you wasting your time on implementing your own linked list? Use std::list or CTypedPtrList
2) i do have a bitmap displayed as well, but i didn't serialize that. the problem is that it doesn't work
What exactly doesn't work? You can't compile this code? It crashes? It makes your monitor explode?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
i can't do anything about the linked_list class. i have 7 weeks to finish my project at work(summer job) and the program is written using my own linked_list.
about the bitmaps, the program works fine, the problem is with serializing it.
1- i have to figure out how to serialize my linked_list correctly.
2- I have to serialize bitmap object as well, which i don't know.
can you help me please?
Thanks
Ehsan Behboudi
|
|
|
|
|
1) Your linked_list::Serialize should write more information - when reading list contents, you have to know when to stop. You can do one of the following:
(a) write number of items before item contents
(b) write boolean flag before each item. true means that there's more data, false means 'no more list items available'
All this stuff comes for free when you use CTypedPtrList - you have only to implement Serialize for the item class.
2) Before serializing convert your bitmaps to dib sections (search for MFC wrapper at CodeProject), then use CArchive::Read/CArchive::Write.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|