I have a Managed C++ dll which dynamically links with an unmanaged C++ dll. The managed C++ derives several unmanaged classes from abstract interfaces in the unmanaged dll.
This works fine.
----------
// uses macro __declspec(dllexport)
class EXPORT_API ICustomer
{
public:
virtual void PlaceOrder() = 0;
//
};
-----< LocalCustomer.h in managed C++>-----
`#include "unmanagedlib/ICustomer.h"
//a unmanaged derived class defined in the managed dll
class LocalCustomer : public ICustomer
{
public:
void PlaceOrder();
//
};
LocalCustomer is used in the Managed dll. I can pass it to functions in the unmanaged dll and it all works fine.
Here is the problem. I get an STATUS_INVALID_IMAGE_FORMAT at startup when I try to implement an interface which exposes a template .
Does not run.
--------
stuct Order
{
double price;
//...
};
template<typename T
>
class EXPORT_API ICollection
{
//....
};
class EXPORT_API IFactory
{
public:
virtual ICollection<Order
>& GetOrders() = 0;
}
------< in the managed C++ dll>-------
class OrderCollection : public ICollection<Order
>
{
//
};
class LocalFactory : public IFactory
{
public:
virtual ICollection<Order
>& GetOrders() { return m_orders; }
private:
OrderCollection m_orders;
};
I have narrowed it down the template override GetOrders. Having the code in the managed dll causes a dialog to open "The application was unable to start correctly (0xc000007b) which is just the STATUS_INVALID_IMAGE_FORMAT HRESULT getting thrown by the managed loader. Removing the code allows it to run. So whats wrong with the template? Why can't I use it in the managed dll.
One other clue, not sure if this is a distraction of not.. I am compiling a 32 bit app and running on Win7 x64. Like I said with works just fine as long as the template does not cross the dll from unmanaged to managed.
What kills me is I Ihave several unamanaged C++ templates that live wholly within the managed dll and they work fine. It is just templates crossing between the dll that seems to give me bad image.