|
Hi Andy
I cannot provide you a proper answer but sometimes people create their own heap from their DLLs. Thus those DLLs must delete their private heaps.
Look up HeapDestroy,HeapCreate
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
As far as I know, .DEFs do not provide any means to export a whole C++ class in one fell swoop. The closest you can get is exporting all of the member functions and variables, but this is pretty complicated due to name mangling. This article discusses the issue in greater detail and proposes alternative approaches.
As for the DLL heap manager, I'm afraid what you've heard is true: best way to avoid problems is ensuring that all that is allocated in the DLL is freed by the DLL itself (this post of mine explains what the issues with DLL private heaps are). The most usual technique to deal with this problem is to have exported factory methods like create() and their corresponding destroy() s, as you pointed out. An implication of this is that crossed DLL objects should not be created on the stack (i.e. their ctors should be declared protected ).
If you still want to have classes that work safely across DLL boundaries but yet do not resort to create() methods, there's a solution: define and export new , delete and all ctors (including the copy constructor), and put the corresponding definitions in the .cpp file (so that they are not inlined). This way, all the allocation/deallocation works is ensured to be made inside the DLL.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
As for the DLL heap manager, I'm afraid what you've heard is true: best way to avoid problems is ensuring that all that is allocated in the DLL is freed by the DLL itself
Not at all. If you use the same version of CRT for the exe and the dll, you are safe. I do this all the time, and it works fine.
I vote pro drink
|
|
|
|
|
Well, my undersading of the situation (I explain it with much more detail here) is that the you're only safe if the CRT used is dynamically linked. Otherwise you end up with two (or more) CRT "instances", and two or more _crtheap private heaps. If I'm not wrong, it should be easy to prove this with a little test program/DLL combination producing a crash with statically linked CRTs.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Oh, I didn't look at your link. Sorry.
It is true that I always use dynamically linked CRT. That's why I never had any trouble.
I vote pro drink
|
|
|
|
|
If you want your code to be portable take a look at how COM works. Define a creator function for your objects, and each object should manage his own life. So you don't care about heap managers, name mangling , etc, and as long as you stick with the C++ standard, your code will be portable.
|
|
|
|
|
Well, providing destroy() works well. And this is true that memory allocated in DLL must be freed in DLL. But when you created a new VC++ project, you can look in its properties, C/C++ tab, Code genertion and you will see "Debug multithreaded DLL" option selected which is by default. With this option you can use your memory as you wish (I mean in case of DLLs).
Exporting classes throw .def file is not allowed as I know.
How people making plugins? Simple. There are many different ways. Fisrt to have only raw global functions. But if you want to use class, write an abstract class (which is need only header file) and derive your plugin's class from it. Now provide global function in your DLL like "GetPlugin()", returning the pointer to the abstract class and call it from your application. This way you "exported" a class from DLL And this way I did some time ago
But of course, not so simple. My suggestion is to open MSDN and read about DLLs, there are many information about it
Philip Patrick
|
|
|
|
|
How do I disable a pushbutton in a dialog?? I've been round-and-round through MSDN. It can't really be that hard, can it??
~Cam Desautels (BinaryUprising.com)
|
|
|
|
|
EnableWindow ( hwndControl, FALSE );
--Mike--
http://home.inreach.com/mdunn/
"Not our fault we are intellectually superior to the rest of the office." -- Paul Watson in the Lounge, 12/12/2001
Sonork - 100.10414 AcidHelm
|
|
|
|
|
or from MFC:-
CWnd::EnableWindow (false/true)
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
|
Can someone tell me if there is a function to get a pointer to the view object? For example, you can get one to the document object like so:
CMyAppDoc *pDoc = GetDocument();
Why can't there be a bloody 'GetView()' function??
~Cam Desautels (BinaryUprising.com)
|
|
|
|
|
There are several ways to do this. From what level do you want to get it (app, doc, mainframe, etc.) ?
|
|
|
|
|
|
See CDocument::GetFirstViewPosition() and CDocument::GetNextView().
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hello,
This question is in detail considered in article Q108587 HOWTO: Get Current CDocument or CView from Anywhere Microsoft Knowledge Base!
Best regards,
Eugene Pustovoyt
Sonork ID 100.10002:Yaumen
|
|
|
|
|
Hi,
I have developed a TDI filter driver(build in *.sys) in Win2000,but i haven't got the .inf file,so it is no use and it's urgent to use it for me...
please help me!!!
Thanks a lot for all replies
|
|
|
|
|
If you wrote a device driver, I guess you should write your inf for it too huh?
Nish
p.s. You are asking like, "I can multiply 34567835 with 358454, but can someone tell me how to multiply 5 with 8"
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
HI,
I am using DataGrid control in my MFC app. One of the requirements is to loop through each selected record, pick the third column value and update the database if any item has changed.
Surprisingly most of the samples listed in MSDN show the VB examples. I am interested in a C++ sample that manipulates the selected rows, gets count of # of selected rows, etc. Can anyone point me to an in-depth usage of DataGrid Sample code. Also there are lot of LPDISPATCH routines like "LPDISPATCH GetSelBookmarks()" that can further call more functions. However I have no clue of what interface they support.
Nagendra
|
|
|
|
|
see sample (using ADO)
http://www.codeproject.com/useritems/msdatagrid.asp
or (OLE DB)
http://www.codeproject.com/useritems/msdatagridoledb.asp
|
|
|
|
|
File this one under stupid compiler tricks:
(there's apparently no html allowed...)
http://www.BinaryUprising.com/images/StupidError.JPG
rriiiiight.....
~Cam Desautels
|
|
|
|
|
And I thought "I" had frustrating error messages! Why did that happen, do ya know?
|
|
|
|
|
Well, (keep in mind I'm pretty new to C++), I was screwing around in Visual Studio trying to learn something (anything). So, I decided to use AppWizard to make a new App, base-ing the view on CTreeView.
This is all good and well...so then I decided I'd add something to my fancy new tree. But I needed a pointer to it. So, I did the following:
GetTreeCtrl()->InsertItem("Hello world")
And that worked just fine. I did that few times for different items, making some items below others, I changed the background color - I was just learning how the CTreeCtrl works. Anyway, at some point I thought, "Hey, if just stored the address of the Tree in a pointer, I'd save system resources (not to mention typing), by not having to call the GetTreeCtrl() function everytime." So, I wrote the following:
CTreeCtrl *pOurTree = GetTreeCtrl();
and it said the following to me:
cannot convert from 'class CTreeCtrl' to 'class CTreeCtrl *'
Confused and curious, I said "ok, what the hell, lets see what happens". Removed the asterisk, and compiled again, simply to see what it would say. And that's how I got the error . Anyway, I would be curious how to do it correctly.
~Cam Desautels (BinaryUprising.com)
|
|
|
|
|
What's weirder is that "GetTreeCtrl()->InsertItem("Hello world");" even worked. GetTreeCtrl() returns a CTreeCtrl& not a CTreeCtrl*.
--Mike--
http://home.inreach.com/mdunn/
"Not our fault we are intellectually superior to the rest of the office." -- Paul Watson in the Lounge, 12/12/2001
Sonork - 100.10414 AcidHelm
|
|
|
|
|
He, he, he...it's the magic touch of stupidity. You'd be surprized how many ridiculous programming stunts I pull . It's been a long time since I've programmed in anything that wasn't for the web...I'm very rusty....
~Cam Desautels (BinaryUprising.com)
|
|
|
|