.NET/COM Interaction

S

Sam Whited

So I have a managed DLL written in Visual C++ which exports functions to be
used in an external application with generic DLL linking functions.

If I simply return some data my (non .NET) application can call the
functions fine but as soon as I try to allocate memory of of the managed
heap the application crashes without giving me any information. For
instance, I have an initialization function which creates an instance of an
object for other functions to reference (the class contains a static pointer
to an instance of itself so that functions can reference it... it also makes
sure there is only one instance of itself in existence at any one time).

Any ideas how I could create an instance of this class (here called iClass)
on the heap in a COM safe manner (or is that not even the problem)?

namespace iClassSpace
{
public ref class iClass
{
public:
static iClass^ iClass icInstance;
iClass()
{
iClass::icInstance = this;
}
// Other stuff
}
}

extern "C" __declspec( dllexport ) double init()
{
// Crashes right here without ever entering the iClass constructor
gcnew iClass();
return ( 1 );
}
 
S

SG

namespace iClassSpace
{
     public ref class iClass
     {
        public:
          static iClass^ iClass icInstance;
          iClass()
          {
               iClass::icInstance = this;
          }
          // Other stuff
     }
}

In addition I'd like to mention that this is not C++ code. It looks
more like "C++/CLI".

Cheers!
SG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top