none
Heap corruption issue.

    Domanda

  • HI all,

    say i have dll which is linked to app statically. Dll has a interface class to interact with the app. This interface class has a public vector.

    When i try to initiate and work with the Dll everything works fine but while deleting the dll class object heap gets corrupted. Why is it so? And as i mentioned about vector, if i keep vector unused after declaring it works fine.

    whats the problem? how could i solve this issue?

    Thanks


    martedì 6 marzo 2012 14:15

Risposte

  • Stay hungry_Stay Foolish wrote:

    say i have dll which is linked to app statically. Dll has a interface  class to interact with the app. This interface class has a
    public vector.

    This would only work if both EXE and DLL are built with the same version  of the same compiler, using compatible settings, and linked to the same  flavor of CRT DLL (static CRT won't work; can't mix debug and release  builds of the two modules).

    When i try to initiate and work with the Dll everything works fine but  while deleting the dll class object heap gets corrupted.

    This means that one or more of the conditions mentioned above do not  hold.


    Igor Tandetnik

    • Proposto come risposta Helen Zhao martedì 13 marzo 2012 07:12
    • Contrassegnato come risposta Helen Zhao martedì 13 marzo 2012 07:13
    martedì 6 marzo 2012 14:24
  • Stay hungry_Stay Foolish wrote:
    > Hi David,
    >
    > Thanks for reply. I tried dynamic linking too(/MD) but no luck. It works fine in
    > (/MDd) but my requirement is to make it work in (/MD)..
    >
    > any clue for sloving it?
     
    You must make sure that in your release build all modules are built with /MD.
     

    David Wilkinson | Visual C++ MVP
    • Proposto come risposta Helen Zhao martedì 13 marzo 2012 07:13
    • Contrassegnato come risposta Helen Zhao martedì 13 marzo 2012 07:13
    mercoledì 7 marzo 2012 14:54

Tutte le risposte

  • Stay hungry_Stay Foolish wrote:

    say i have dll which is linked to app statically. Dll has a interface  class to interact with the app. This interface class has a
    public vector.

    This would only work if both EXE and DLL are built with the same version  of the same compiler, using compatible settings, and linked to the same  flavor of CRT DLL (static CRT won't work; can't mix debug and release  builds of the two modules).

    When i try to initiate and work with the Dll everything works fine but  while deleting the dll class object heap gets corrupted.

    This means that one or more of the conditions mentioned above do not  hold.


    Igor Tandetnik

    • Proposto come risposta Helen Zhao martedì 13 marzo 2012 07:12
    • Contrassegnato come risposta Helen Zhao martedì 13 marzo 2012 07:13
    martedì 6 marzo 2012 14:24
  • HI all,
     
    say i have dll which is linked to app statically.
    DLL's are not linked statically. As their name implies, they are linked dynamically.
     
    If you mean that your DLL is linked statically to the CRT, then read Igor's answer.
     

    David Wilkinson | Visual C++ MVP
    martedì 6 marzo 2012 14:37
  • Hi,

    Thanks for the response. I mentioned it wrongly its implicitly linking.

    And i have build both exe and dll in the same version of compiler and same flavour of CRT.

    Whats wrong with it? The public variable is troubling. how to overcome this?

    mercoledì 7 marzo 2012 05:47
  • And i have build both exe and dll in the same version of compiler and same flavour of CRT.

    And the same compiler switches? You cannot mix a RELEASE verion of the DLL with a DEBUG version of the EXE, for example.
    mercoledì 7 marzo 2012 06:05
  • Hi Brian,

    Thanks for reply, Both exe and dll are in same switches. checked every possible way. Thing i need is to get a vector filled with values out of dll without heap corruption. Is there way for it?

    mercoledì 7 marzo 2012 08:40
  • Hi Brian,
     
    Thanks for reply, Both exe and dll are in same switches. checked every possible way. Thing i need is to get a vector filled with values out of dll without heap corruption. Is there way for it?
    Are you using static linking of CRT (/MT or /MTd)? Many DLL usages do not work with static linking because memory is allocated and freed in different modules.
     
    Have you tried dynamic linking (/MD or /MDd) of both modules?
     

    David Wilkinson | Visual C++ MVP
    mercoledì 7 marzo 2012 12:42
  • Hi David,

    Thanks for reply. I tried dynamic linking too(/MTd) but no luck. It works fine in (/MDd) but my requirement is to make it work in (/MTd)..

    any clue for sloving it?



    memory is allocated and freed in different modules.

    Can you suggest a method to get vector out of dll to the calling application
    mercoledì 7 marzo 2012 14:20
  • Stay hungry_Stay Foolish wrote:
    > Hi David,
    >
    > Thanks for reply. I tried dynamic linking too(/MD) but no luck. It works fine in
    > (/MDd) but my requirement is to make it work in (/MD)..
    >
    > any clue for sloving it?
     
    You must make sure that in your release build all modules are built with /MD.
     

    David Wilkinson | Visual C++ MVP
    • Proposto come risposta Helen Zhao martedì 13 marzo 2012 07:13
    • Contrassegnato come risposta Helen Zhao martedì 13 marzo 2012 07:13
    mercoledì 7 marzo 2012 14:54