Click here to Skip to main content
15,907,329 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: Using a DLL containing MFC functions in a Managed C++ app (Help please) Pin
James19764-Jun-09 5:21
James19764-Jun-09 5:21 
QuestionDRMInitEnvironment function fails............... :( Pin
deadlyabbas1-Jun-09 21:31
deadlyabbas1-Jun-09 21:31 
QuestionHow to return a multidimensional array with a pointer function in Visual C++? Pin
emira671-Jun-09 4:40
emira671-Jun-09 4:40 
QuestionReturning a multidimensional array from pointer function in Visual C++ Pin
emira671-Jun-09 4:00
emira671-Jun-09 4:00 
QuestionLNK2005 Redefinition Error on using CLI --already defined LNK2005 error Pin
jobin00700730-May-09 21:15
jobin00700730-May-09 21:15 
AnswerRe: LNK2005 Redefinition Error on using CLI --already defined LNK2005 error Pin
Mark Salsbery31-May-09 9:37
Mark Salsbery31-May-09 9:37 
GeneralRe: LNK2005 Redefinition Error on using CLI --already defined LNK2005 error Pin
jobin00700731-May-09 10:18
jobin00700731-May-09 10:18 
GeneralRe: LNK2005 Redefinition Error on using CLI --already defined LNK2005 error [modified] Pin
Mark Salsbery31-May-09 10:40
Mark Salsbery31-May-09 10:40 
jobin007007 wrote:
I actually made all the object variable definitions in the header file to another class I already had in the header file and declared them static.Is there any disadvantage in moving them to the class versus declaring them as global??????


That's fine and ends up being pretty much the same thing, except as
static objects of a class, only one instance will exist. You still need to
define the static instances in ONE cpp file, or you'll get a linker unresolved
external error.


jobin007007 wrote:
QUESTION 1)So as seen above I am creating an pointer object of type UNMANAGEDNAMESPACE.Data So i guess the larger the size of UNMANAGEDNAMESPACE.Data class, the larger the memory used will be when i define pObj = new UNMANAGEDNAMESPACE.Data().


I suppose it's true, but not an issue. No matter what heap an object is created on,
it's still going to take some memory.

jobin007007 wrote:
QUESTION 2)Is there any problems in the above approach. Is there a better approach for reducing memory of the program?


The approach is fine, and a good way to make use of C++/CLI - to interoperate
between managed and unmanaged code. Again, memory is not an issue here...use the
memory you need and free it when you're done with it, just like any programming Smile | :)

Since you're ManagedCLR class holds unmanaged resources (an UNMANAGEDNAMESPACE.Data
object), you may want to implement the ManagedCLR as disposable, so you can free
the unmanaged resource(s) deterministically. (See Destructors and Finalizers in Visual C++[^])
It would look something like this:
public ref class ManagedCLR
{
private:
    UNMANAGEDNAMESPACE.Data *pObj; //Here my Unmanaged Class is referenced through a pointer.

public:
    ManagedCLR()
    {
        pObj = new UNMANAGEDNAMESPACE.Data(); 
    }

    ~ManagedCLR()
    {
        // clean up managed resources here

        // call the finalizer to release unmanaged resources!
        this->!ManagedCLR();
    }

    !ManagedCLR()
    {
        // clean up unmanaged resources here
        delete pObj;
        pObj = 0;
    }

    void EntryPoint(void)
    {
        //pass through to the unmanaged object
        pObj->EntryPointUnmanged(); //Here the managed program accesses my unmanaged program.
    }
};

When used from C# code, you can call Dsipose() to deterministically free unmanaged resources of
a ManagedCLR object. Whwn used from C++/CLI code, just use "delete".


Mark

Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

modified on Sunday, May 31, 2009 4:48 PM

GeneralRe: LNK2005 Redefinition Error on using CLI --already defined LNK2005 error Pin
jobin00700731-May-09 10:48
jobin00700731-May-09 10:48 
GeneralRe: LNK2005 Redefinition Error on using CLI --already defined LNK2005 error Pin
Mark Salsbery31-May-09 10:53
Mark Salsbery31-May-09 10:53 
GeneralRe: LNK2005 Redefinition Error on using CLI --already defined LNK2005 error Pin
jobin00700731-May-09 11:00
jobin00700731-May-09 11:00 
GeneralRe: LNK2005 Redefinition Error on using CLI --already defined LNK2005 error Pin
Mark Salsbery31-May-09 11:08
Mark Salsbery31-May-09 11:08 
GeneralRe: LNK2005 Redefinition Error on using CLI --already defined LNK2005 error Pin
jobin00700731-May-09 12:07
jobin00700731-May-09 12:07 
GeneralRe: LNK2005 Redefinition Error on using CLI --already defined LNK2005 error Pin
Mark Salsbery1-Jun-09 7:09
Mark Salsbery1-Jun-09 7:09 
AnswerAttempt to load an unverifiable executable with fixups (IAT with more than 2 sections or a TLS section.) (Exception from HRESULT: 0x80131019) Help! Pin
jobin0070071-Jun-09 12:37
jobin0070071-Jun-09 12:37 
GeneralRe: Attempt to load an unverifiable executable with fixups (IAT with more than 2 sections or a TLS section.) (Exception from HRESULT: 0x80131019) Help! Pin
Mark Salsbery1-Jun-09 12:42
Mark Salsbery1-Jun-09 12:42 
GeneralRe: Attempt to load an unverifiable executable with fixups (IAT with more than 2 sections or a TLS section.) (Exception from HRESULT: 0x80131019) Help! Pin
jobin0070071-Jun-09 13:15
jobin0070071-Jun-09 13:15 
AnswerUnable to access variables. Pin
jobin0070071-Jun-09 13:18
jobin0070071-Jun-09 13:18 
GeneralRe: Unable to access variables. Pin
jobin0070071-Jun-09 13:21
jobin0070071-Jun-09 13:21 
GeneralRe: Unable to access variables. Pin
jobin0070071-Jun-09 13:27
jobin0070071-Jun-09 13:27 
GeneralRe: Unable to access variables. Pin
jobin0070071-Jun-09 13:54
jobin0070071-Jun-09 13:54 
GeneralRe: Unable to access variables. Pin
Mark Salsbery1-Jun-09 17:25
Mark Salsbery1-Jun-09 17:25 
NewsNo Intellisense support in VC10 for C++/CLI!!! Pin
small_mountain28-May-09 7:05
small_mountain28-May-09 7:05 
GeneralRe: No Intellisense support in VC10 for C++/CLI!!! Pin
teejayem28-May-09 7:27
teejayem28-May-09 7:27 
GeneralRe: No Intellisense support in VC10 for C++/CLI!!! [modified] Pin
Mark Salsbery28-May-09 7:31
Mark Salsbery28-May-09 7:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.