Hour 22

1: If you wanted to use MessageBox rather than the ANSI or Unicode functions, what changes need to be made to the DllImport attribute?
A1: Change the CharSet attribute for DllImport to either Auto or remove it completely.
2: In an unmanaged class, are you responsible for freeing any memory that is allocated, regardless of the variable type?
A2: No, managed types within the unmanaged class will still be garbage collected. You will, however, need to free any memory allocated for unmanaged member variables within that class.
3: If a DLL exports a C++ class that you wish to use within managed code, do you have to create definitions for each of the member functions within that class as well as the definition for the class?
A3: Yes.

Get Sams Teach Yourself Visual C++® .NET in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.