1

I need to implement a c# GUI for my unmanaged code. So i have designed a wrapper to deal with my native code, but this does not work porperly.

I have a method which requires to make an instance to an abstract class and i'm not sure how to deal with it.

First for my C++ classes i used an abstract class:

 class Interface abstract
    {
       public:      Interface (void);
       public:      ~Interface (void);

       public:      virtual double Get() = 0;   
    };

And i used a ClassSpecific1 and a ClassSpecific2 depending on my current application, and i inherited the functions from the abstract class for each one.

    class ClassSpecific1 : public Interface
    {
       public:      ClassSpecific1 (void);
       public:      ~ClassSpecific1 (void);

       private:     double Get();//based on the abstract class

    };


    class ClassSpecific2 : public Interface
    {
       public:      ClassSpecific2 (void);
       public:      ~ClassSpecific2 (void);

       private:     double Get();//based on the abstract class

    };

Later i used another class, it works as a general class and uses the ClassSpecific1 or the ClassSpecific2 with an instance of the abstract class.

    class ClassAPI
    {
       public:      ClassLaserAPI(void);
       public:      ~ClassLaserAPI(void);

       public:      double Get(Interface *objToInterface);//This Get() calls the Get() in ClassSpecific1 or ClassSpecific2 
    };

Until here everything seems all right. I have tested everything and works as expected. My big problem is that i don't know how to make my method Get(Interface *objToInterface) from ClassAPI into my wrapper. Do i need to make a wrapper for my abstract class first in order to be able to create the instance**(Interface *objToInterface)** on the wrapper?

This is what i have so far, i hope someone can give me some help, i'm getting lost in how to proceed.


    namespace API
    {

            public __gc class APIManaged
            {
                    public: APIManaged(void);
                    public: ~APIManaged(void);

        /** Unmanaged pointer to ClassAPI 
         *  
         */
                    private:    ClassAPI __nogc* cAPI;

                    public:     double Get(Interface __nogc* objInterface);
            };
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Carolina M
  • 19
  • 3
  • 2
    Core problem is that your interface is an unmanaged one, you can't call managed code through it. Use the `interface class` keywords (for C++/CLI anyway, avoid Managed C++ if you want help around here). – Hans Passant Sep 21 '11 at 15:45
  • There's no C++/CLI here. What version of Visual C++? – Ben Voigt Sep 22 '11 at 14:36

1 Answers1

0

I'm also having the same problem and got it resolved using this topic: C++/CLI Inheriting from a native C++ class with abstract methods and exposing it to C#

I too am using an unmanaged abstract class and got things working by following the tips outlined in the link. I ended up with a few errors to fix and fixed them by changing my linker options in my unmanaged projects to not compile with /clr and only the wrapper project compiles using /clr.

Posting your output errors may help clarify some of the troubles you are having...

Community
  • 1
  • 1
Chef Pharaoh
  • 2,387
  • 3
  • 27
  • 38