|
Tnank you very much for your reply, but please take a look at this text whick I took from Jeffrey Richter's "Windows via C++"
VOID EXEFunc() {
PVOID pv = DLLFunc();
// Access the storage pointed to by pv...
// Assumes that pv is in EXE's C/C++ run-time heap
free(pv);
}
PVOID DLLFunc() {
// Allocate block from DLL's C/C++ run-time heap
return(malloc(100));
}
So, what do you think? Does the preceding code work correctly? Is the block allocated by the DLL's function freed by the EXE's function? The answer is: maybe. The code shown does not give you enough information. If both the EXE and the DLL link to the DLL C/C++ run-time library, the code works just fine. However, if one or both of the modules link to the static C/C++ run-time library, the call to free fails. I have seen developers write code similar to this too many times, and it has burned them all...
|
|
|
|
|
the code i posted above is the code that you are calling. the object you are deleting is allocated by your app's CRT.
the DLL/EXE CRT allocation issue is not relevant here.
|
|
|
|
|
Thank you for your reply, please take a look at my reply to Richard in the next thread.
|
|
|
|
|
naro24 wrote: so the delete operator should look for pConn in it's CRT's run time heap
Library functions do not have their own heap. The heap is allocated at run time and shared by the exe file and all library functions.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Tnank you very much for your reply, but please take a look at this text whick I took from Jeffrey Richter's "Windows via C++"
VOID EXEFunc() {
PVOID pv = DLLFunc();
// Access the storage pointed to by pv...
// Assumes that pv is in EXE's C/C++ run-time heap
free(pv);
}
PVOID DLLFunc() {
// Allocate block from DLL's C/C++ run-time heap
return(malloc(100));
}
So, what do you think? Does the preceding code work correctly? Is the block allocated by the DLL's function freed by the EXE's function? The answer is: maybe. The code shown does not give you enough information. If both the EXE and the DLL link to the DLL C/C++ run-time library, the code works just fine. However, if one or both of the modules link to the static C/C++ run-time library, the call to free fails. I have seen developers write code similar to this too many times, and it has burned them all...
|
|
|
|
|
naro24 wrote: Is the block allocated by the DLL's function freed by the EXE's function? The answer is: maybe.
Actually the answer is "Yes". As I said earlier there is only one heap within a running application. Whether the actual code is part of the EXE or part of the DLL is irrelevant, the OS maps both parts into the same address space and they all share the same data area within that address space. If this was not so then 99% of commercial applications would not work correctly.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Thanks for your reply, but let me to disagree with you.
Richard MacCutchan wrote: As I said earlier there is only one heap within a running application.
An application can actually create and use as many heaps as needed using HeapCreate,HeapAlloc,HeapFree and other APIs.
Richard MacCutchan wrote: Actually the answer is "Yes"
The answer is not always "Yes". I tested the following code in vs2005
int main()
{
int* a = fnHeapTestLib();
std::cout<<*a<<std::endl;
delete="" a;
="" std::cout<<*a<<std::endl;
="" return="" 0;=""
}
heaptestlib_api="" int*="" fnheaptestlib(void)
{
="" p="new" int;
="" *p="42;
" p;
}
i="" built="" in="" release="" version="" using="" 4="" different="" configurations,="" and="" here="" are="" the="" results
1)both="" exe="" dll="" linked="" to="" crt="" dynamically
="" works="" fine
2)exe="" is="" statically,="" fine(="" very="" strange="" fact="" )
3)exe="" dynamically,="" statically
="" fails(shows="" same="" value="" after="" before="" delete,="" debug="" raises="" assertion)
4)both="" assertion)
i="" can't="" explain="" this="" behavior,="" but="" makes="" obvious="" that="" allocation="" issue="" relevant="" here.
<blockquote="" class="FQ">Richard MacCutchan wrote: If this was not so then 99% of commercial applications would not work correctly.
May be 99% of commercial applications and their DLLs link to CRT dynamically.
Regards
|
|
|
|
|
naro24 wrote: delete fails(shows the same value after and before delete, in debug version raises assertion)
The delete operation does not clear the contents of the memory, so testing the contents before and after is not a valid test. When a block is deleted its header is merely marked to show it is available for reallocation within the running program. As to your comments about HeapCreate() etc, if they work as you believe then I am certain that many commercial programs would be failing on a regular basis. Take a look at the documentation for these functions.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Could you please make this small test in vs2005 or vs2008
1)Make an exe and dll using the code in my previous post
2)Make both projects link to CRT statically
3)Build both in debug mode
As you claim everything must work properly, but you'll see an assertion on delete operator. Can you explain why?
|
|
|
|
|
Unfortunately I only have VC++ Express so I cannot reproduce completely. However, I think I finally understand what you are saying, and I would suggest it is wrong to link a system library to a dll statically, since this will cause the problems you are seeing. Your program now has two copies of the CRT attached to it and so all bets are off, you will get inconsistent results, as is to be expected. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
|
no answers for you here - but you should google "sms gateway"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>
|
|
|
|
|
Hi ALL,
I am using MS Visual Studio 2008 to develop a MFC application.When compiling i am getting the following errors.Please help me fix these.
Error 14 error LNK2005: __wfopen already defined in libcmt.lib(wfopen.obj) MSVCRT.lib USMIF
Error 15 error LNK2005: _fclose already defined in libcmt.lib(fclose.obj) MSVCRT.lib USMIF
Error 16 error LNK2005: _fread already defined in libcmt.lib(fread.obj) MSVCRT.lib USMIF
Error 17 error LNK2005: _fwrite already defined in libcmt.lib(fwrite.obj) MSVCRT.lib USMIF
Error 18 error LNK2005: _fseek already defined in libcmt.lib(fseek.obj) MSVCRT.lib USMIF
Error 19 error LNK2005: _ftell already defined in libcmt.lib(ftell.obj) MSVCRT.lib USMIF
Error 20 error LNK2005: _fflush already defined in libcmt.lib(fflush.obj) MSVCRT.lib USMIF
Error 21 error LNK2005: _feof already defined in libcmt.lib(feoferr.obj) MSVCRT.lib USMIF
Error 22 error LNK2005: _ferror already defined in libcmt.lib(feoferr.obj) MSVCRT.lib USMIF
Error 23 error LNK2005: _free already defined in libcmt.lib(free.obj) MSVCRT.lib USMIF
Error 24 error LNK2005: _calloc already defined in libcmt.lib(calloc.obj) MSVCRT.lib USMIF
Error 25 error LNK2005: __swprintf already defined in libcmt.lib(swprintf.obj) MSVCRT.lib USMIF
Thanking in advance ,
ashwath
|
|
|
|
|
This means that you have two different version of CRT linked. Are you using any static or dynamic libraries? They need to have same version of CRT.
-Saurabh
|
|
|
|
|
one or more of the static libraries you are linking to has been built using a different C-runtime version than your main application.
check the project Properties / C/++ / Code Generation, and look at the "Runtime Library" setting. they must all match.
-c
|
|
|
|
|
Both LIBC.LIB and msvcrt.lib are used, which may cause error.
Project Settings:
-> Configration Properties -> Linker -> Input -> Ignore Specific Library: libcmtd
modified 27-May-14 4:52am.
|
|
|
|
|
I mean separating Implementation file and Header file and then including them in our main prog??
|
|
|
|
|
I'm going to have to assume a few things that aren't clear to me from your post.
assumption 1 : You mean adding files to a prj and not just creating hdr and impl source.
assumption 2 : You're using the cmdline compiler and not the IDE.
It's been too long since I've used Turbo C to remember, but it sounds like it's just a matter of syntax. Google should help with that, or the Turbo C help docs which I do remember as being excellent.
|
|
|
|
|
yes...your first assumtion is absolutely right but not the second one. I am using the Turbo IDE. I tried hard to find help about this on Google but gould't find any. Turbo is just used to make our base in programming (like oop).
|
|
|
|
|
There should be an option to add source files under the Project menu.
|
|
|
|
|
BonshatS wrote: Turbo C help docs which I do remember as being excellent
Ah yes those were the days. I wonder how many of us learnt C and C++ in Turbo C++ for DOS? Kevin
|
|
|
|
|
Kevin McFarlane wrote: Ah yes those were the days. I wonder how many of us learnt C and C++ in Turbo C++ for DOS?
Yep, and a shelf full of books with every version.
|
|
|
|
|
I learned C before there was a Turbo anything but Turbo C++ was my first C++ compiler. You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Kevin McFarlane wrote: I wonder how many of us learnt C and C++ in Turbo C++ for DOS?
I resent resemble that remark."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Turbo C for DOS help files were excellent. The reincarnated Turbo C++ is not only complete crap, the help is junk as well. It's a shame since I'd like to see some legitimate competition for Visual Studio.
|
|
|
|