Link to home
Start Free TrialLog in
Avatar of uniquepawan
uniquepawan

asked on

Please help in making an ActiveX control of a class (no GUI needed)

Hi All,

      I wanted to make a ActiveX control (no GUI support) which has all the methods defined in the class shown below including the operator== overloading and copy contructor.  Later on I have to use these methods in a VBA.

I got 3-4 replies but either the hint provided didn't worked out or I got syntax errors after compiling in MS VS C++ 6.
I have allready spent 3 days on this problem but could not able to solve it. Please help me in solving it.

Please reply as quick as possible in details. I will be very thankful,  if you could build the ActiveX control by taking my Test.cpp as an input and send the tar file of the complete project at the following address: pawan_kumar00@yahoo.com
 
Thanks in advance,

With Regards,
Pawan

//Test class
#include <iostream>
#include <string>
using namespace std;

class Test
{
private:
    unsigned int total;
public:
    Test();
    ~Test();
    Test(const Test& testObj);
    void addValue(unsigned int value);
    unsigned int getValue();
    bool operator== (const Test& testObj);
};

Test::Test()
{
     total = 0;
}

Test::~Test()
{
}

Test::Test(const Test& testObj)
{
    this->total = testObj.total;
}

void Test::addValue(unsigned int value)
{
    total = total + value;
}

unsigned int Test::getValue()
{
    return total;
}

bool Test::operator==(const Test& testObj)
{
    if (this->total == testObj.total)
        return true;
    else
        return false;
}
Avatar of lakshman_ce
lakshman_ce

Hi Pawan,
Please try to make an ActiveX control with the inputs that I gave you. You will learn when you do it else you will never learn.
It is very simple to write a control for this class. Create an MFC ActiveX control project and add the required methods and properties as I suggested..
The class members which you intend to send or receive to VBA or any other application can be made as properties. And you can achieve this easily by using the set property and get property.
Also the methods like AddValue can be added to the ActiveX interface methods.
Plz let me know if you have any difficulties in making the activex control.
Good luck,
Lakshman
Plz post the errors that you are getting. So that we can help you.

-Lakshman

COM [ActiveX] is supposed to be language independant. As such the ability to expose C++ esque methods is not available.

How many languages have operator== ? Specifically, does VBA ?!

As nonubik suggested (https://www.experts-exchange.com/questions/20943508/How-to-use-operator-overloading-and-copy-constructor-in-ActiveX-control.html) using isEqual( ) and clone( ) is a common implementaton for scenarios such as these.

Also, as lakshman_ce suggested, specific error codes/messages would aid your cause greatly.
Nobody has mentioned this yet, but if you want to use your object from VBA, you're going to have to implement an automation aware component. i.e. one that implements a dispinterface (IDispatch in COM parlance).
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial