Question

What is the Difference between METHOD and FUNCTION ?

Asked by: khalilhenoud

I am building an ATL COM DLL.
Can somebody tell me what is the difference between the methods and the functions in ATL.
I am not able to add an overloaded constructor with add methods but using add function i am.
Thanks in advance.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-09-01 at 01:22:18ID23693103
Tags

C++

Topic

Windows ATL / WTL / COM Programming

Participating Experts
2
Points
500
Comments
17

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. atl & com
    Hi! I am a atl & com beginner and have the following question: I have got an inproc server dll containing a simple object. I have also got a client programm which calls methods of the simple object. If i execute two instances of the client program, how can i exchange...
  2. Function Overloading in an ATL server
    I'd like to expose a set of overloaded methods in an ATL object, but can't seem to get the compiler to read the IDL file correctly. here is the IDL definition: ... [id(1), helpstring("method MyMethod")] HRESULT MyMethod([in] BSTR bstrIn1, [in] BSTR bstrIn2, [out, r...
  3. Function overloading in a COM component using ATL
    When I tried creating a COM dll using ATL (VC 5.0) I failed to overload a function which is a feature of C++. Can't I overload a function in a COM Component. For creating the dll i used ATL wizard and I had inserted a simple object into the workspace and then I tried adding...
  4. CSocket in ATL COM DLL!
    I created a full control object in the ATL project with MFC supported, and a MFC's CSocket was inserted as a listening socket. I had trouble creating the CSocket object in ATL COM STDMETHODIMP method,and no error occurred. m_pSocket->Create(<PORT NUMBER>) would r...
  5. constructors
    What is the use of having a constructor in a private section.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: khalilhenoudPosted on 2008-09-01 at 01:56:39ID: 22358452

Adding to the last information, i want to mention that i am not able to add a property without a put or get function.So what if i want to add a simple variable, how to do it?
With the add variable i am able to do that but with add property i am not.
So please help me understanding very well the difference between add method and add function, and the difference between add property and add variable.
Thank you.

 

by: rionrocPosted on 2008-09-01 at 02:37:16ID: 22358668

The difference between the two choices to be made.
First the FUNCTION which describes the difference between the observations and the predictions of the model.
Second is the choice of the METHOD by which this FUNCTION will be minimized.

A "method" is a "member function" - a function that is embedded in a class. In some languages, such as C++, you can also have standalone functions -functions that don't belong to any class.

I could not say they are really the same, but for sure method is use to minimize a function.

If you use function, you should return a value ether null or not.
sample:
//calling the function
private void abc() {
int xsample;
int zyx;
zyx=xyz(xsample);
if (zyx==1) {
printf("the result is %d",xsample); }
else {
printf("nothing change in %d",xsample); }
}

//this returns a value
private int xyz(int sample){
sample = 1;
if (sample!=1) xzy=1;
return xyz;
}


Good Luck!
:)

 

by: khalilhenoudPosted on 2008-09-01 at 04:32:18ID: 22359307

what i want is to know why i can add a default constructor with the Add functions and while i can not with the add method. What is the difference between them just in ATL COM.

 

by: khalilhenoudPosted on 2008-09-01 at 06:42:04ID: 22360118

Lets take as example this class Object:

class Object
{
      ///*friend classes*/
      //friend class GraphicsEngine;
      ///*friend functions*/
      //friend void SaveToFile(Object *, ofstream *);
      //friend bool LoadFromFile(Object *, ifstream *);
      /**/
      public:
            /*Object Constructor*/
            Object();
            /*Copy Constructor*/
            Object(Object & object);
            Object(const WCHAR * _Name, D3DXVECTOR3 _Position, D3DXMATRIX _Orientation,
                D3DXVECTOR3 _Scale);
            /*The Equal operator*/
            Object & operator=(Object & object);
            /*Object  destructor*/
            virtual ~Object();
            /*The Update method, delta is the time elapsed relative to the previous Update*/
            virtual void Update(float delta);
            /*Returns the position*/
            D3DXVECTOR3 GetPosition(void){return Position;}
            /*Returns the scale*/
            D3DXVECTOR3 GetScale(void){return Scale;}
            /*Returns the orientation*/
            D3DXMATRIX GetOrientation(void){return Orientation;}
            /*Sets the name*/
            void SetName(const WCHAR *);
            /*Gets the name*/
            const WCHAR * GetName(void);
            /*Path-Management*/
            /*Return the path manager*/
            //PathManager * GetPathManager(void){return & pathmanager;}
            bool FollowPath(void);
            /*Stop following the path*/
            void StopFollowPath(void){FollowingPath = false;}
            /*Is Following path?*/
            bool IsFollowingPath(void){return FollowingPath;}
            /*Get the parent*/
            Object * GetParent(void){return Parent;}
            /*Set the parent*/
            void SetParent(Object * parent){Parent = parent;}
            /*Set registered*/
            void SetRegistered(bool registered){Registered = registered;}
            /*Get registered*/
            bool GetRegistered(void){return Registered;}
      protected:
            /*The object's name, statically allocated*/
            WCHAR * Name;
            /*Pointer to the parent object which could be a virtual set*/
            Object * Parent;
            /*Object position in the world space*/
            D3DXVECTOR3 Position;
            /*Object Size Scale*/
            D3DXVECTOR3 Scale;
            /*Object orientation matrix*/
            D3DXMATRIX Orientation;
            /*The path manager*/
            //PathManager pathmanager;
            /*Following path or not*/
            bool FollowingPath;
            bool Registered;

};


Am i able to just derive this class from IUnknown and give it a GUID?
Do i have to transform all those member functions into METHOD?
How can i derive two classes using add ATL simple Object (class)?

Thanks for helping.

 

by: JohnGabyPosted on 2008-09-01 at 07:15:30ID: 22360543

When you are using ATL, methods are functions that define your interface, and they will be declared as pure virtual functions.  You cannot have constructors defined in your interface.  You never create an interface by using 'new'.  To create a whole new interface, you would use CoCreateInstance function.  Additionally, once you have an interface, you can create additional interfaces by calling member methods (functions) of the existing one.

ATL does not allow you to overload methods.  All method names must be unique.  (One reason for this is that you can use the created interfaces from both C and C++)

A Function is a member function of the class which implements a particular interface.  There are no restrictions on these, since they are normal class members.

When you right click on the interface item (e.g IMyInterface) in the class view, you are offered only the option of creating a Method or a Property (Note that when you choose Property, it actually creates two methods instead, a 'get' and a 'put').  When you choose to create a new Method, the a function is added to both your interface declaration (e.g. IMyInterface), and to your class implementation (e.g. CMyInterface).

When you right click on the implementation object (e.g. CMyInterface) in the class view, you are allowed to chose to add a function.  This function is added only to the implementation class, and not to the interface declaration, and hence will not be seen from the outside.

If you want to construct objects which have different constructors, you can create an outer 'management' interface which is the first one that you create.  You can then have methods on that interface which you can use to create your various objects.  You can have one method for each constructor in your original class.

Does any of this make sense?

 

by: khalilhenoudPosted on 2008-09-01 at 07:41:46ID: 22360771

Ok. Am i able to create a COM DLL without adding any new interface?
Just derive the classes from the IUnknown.
I don't want to create interfaces.
All what i need is to use my code in other projects.
Is it possible or not?
Thank you.

 

by: JohnGabyPosted on 2008-09-01 at 10:15:32ID: 22361581

Perhaps a concrete example would help.  Suppose that you had the following class which you wanted to make accessible through a COM interface.

class MyClass
{
public:
    MyClass(WCHAR * pArg);
    MyClass(int arg);

    int MyFunc1(int arg);
    int MyFunc2(int arg1, WCHAR * pArg2);
};

Create a new ATL project.

Now we want to create an object that will expose MyClass.  Right click on the project in your solution, and click choose 'Add / Add Class'. Choose the ATL Simple Object template, and click Add.

For the Short name, enter 'MyAtlClass'.  All the other fields should be filled in automatically.  Then click Finish.

This interface will be created using the CoCreateInstance function.  This will not allow for us to pass any initialization parameters, however.  So what I need to do is to create some initialization methods which will create the actual instances of MyClass.

In the class view for your project, right click on the 'IMyAtlClass' interface and choose the Add / Add Method option.  For the method name enter 'CreateFromString'.  Check the 'in' Parameter attribute and choose BSTR as the Parameter type.  Then enter 'pArg' for the Parameter name and click 'Add'.  Then click 'Finish'.

If you switch back to your source code, you will find that the following routine has been added:

STDMETHODIMP CMyAtlClass::CreateFromString(BSTR pArg)
{
    // TODO: Add your implementation code here

    return S_OK;
}

Now you need to create the actual instance of your class.  You will need to first create a variable to hold a pointer to that instance.  In the class view, right click 'CMyAtlClass' and choose Add / Add Variable.  For the Variable type, enter 'MyClass *'.  For the variable name enter 'm_pMyClass', and click Finish.

Now change the above function as follows:

STDMETHODIMP CMyAtlClass::CreateFromString(BSTR pArg)
{
    if (!(m_pMyClass = new MyClass(pArg)))
    {
        return(E_OUTOFMEMORY);
    }

    return S_OK;
}

Note that you will also need to include the declaration of your 'MyClass' in the header file for the object 'MyAtlClass.h'.

In a similar manner you can then create Method 'CreateFromInt' which will call the constructor which takes an integer.

You will, of course, want the instance of MyClass to be deleted when the object is destroyed.  If you look in the include file 'MyAtlClass.h', you will find two functions, 'FinalConstruct' and 'FinalRelease'.  Change them as follows:

HRESULT FinalConstruct()
{
    m_pMyClass  = 0;

    return S_OK;
}

void FinalRelease()
{
    if (m_pMyClass)
    {
        delete m_pMyClass;
        m_pMyClass = 0;
    }
}

Now it is time to add our function MyFunc1.  Once again, in the Class View, right click on your interface (IMvAtlClass) and select the Add / Add Method option.  For the name, enter MyFunc1.

Check the 'in' Parameter attribute and choose LONG for the type and 'arg' for the name and click 'Add'.  

Now you want to return an integer value.  You cannot use the return value of the method for this, since it will return the HRESULT of the call.  So you need to add a second parameter in which you can return your value.  For the parameter type, choose 'LONG *', and check the 'out' Parameter attribute option.  For the name enter 'pRet' and click 'Add'.  Finally click Finish.

The following function will be added to your source code:

STDMETHODIMP CMyAtlClass::MyFunc1(LONG arg, LONG* pRet)
{
    // TODO: Add your implementation code here

    return S_OK;
}

Now change this as follows:

STDMETHODIMP CMyAtlClass::MyFunc1(LONG arg, LONG* pRet)
{
    if (!m_pMyClass)
    {
        return(E_NOINTERFACE);
    }

    *pRet   = m_pMyClass->MyFunc1(arg);

    return S_OK;
}

In a similar manner, you should be able to create the MyFunc2 function.

Finally build your project, and you should be able to access your class from another program, via a CoCreateInstance call, specifying the class ID for your control (CLSID_MyAtlClass) and the interface id for your object (IID_IMyAtlClass).

Note that I have quickly thrown this together.  I have not actually built and tested this, so I might not have it exactly correct, but should be enough to show you the path.  I hope this is some help.

 

by: khalilhenoudPosted on 2008-09-01 at 23:42:14ID: 22364626

First of all thank you so much for this helpful example. This is awesome.
The last question for me is how to transform to derived class in C++ to ATL COM.
I couldn't find any information about the inheritance of two classes.
And you mentioned that i have to include the declaration of MyClass in the MyAtlClass.h, do you mean this one :

class MyClass
{
public:
    MyClass(WCHAR * pArg);
    MyClass(int arg);

    int MyFunc1(int arg);
    int MyFunc2(int arg1, WCHAR * pArg2);
};

Thanks a lot.

 

by: khalilhenoudPosted on 2008-09-02 at 05:19:37ID: 22366533

I want to explain more about my question about the inheritance.
Lets say i have the class MyClass you gave it as example.
Lets have another class called myChild.

class MyChild : public MyClass
{
public:
    MyChild();

    int Add(int arg1, int arg2);

private:
    int Total;
};

How to make this inheritance in COM ATL?
And lets say that "Total" is a static variable : static int Total.
We know that in C++ we have to redefine this variable at the beginning of the .cpp file.
I did this with ATL and i got the following a redefinition error.
By the way i found no way to have static variable or static function since they are virtual.

So how to do it?

 

by: JohnGabyPosted on 2008-09-02 at 11:42:47ID: 22370170

You can create an interface that inherits from an existing interface, but it is a bit more complicated.  Taking your example, suppose that we had the following class:

class MyChild : public MyClass
{
public:
    MyChild();

    int Add(int arg1, int arg2);

private:
    int Total;
};

Now we have an interface for MyClass (IMyAtlClass), and lets say we want to create an interface for MyChild, but we want that interface to inherit from IMyAtlClass.

First in the Class View, right click on your project and create a new class (lets call it MyChild), in the same manner that you created MyAtlClass.  When you do this, a new interface IMvChild, and it's implementation CMvChild will be created.  Now it would have been nice if the new class wizard allowed us to specify that we wanted the IMvChild to be based on IMvAtlClass, instead of IDispatch, but it does not.  So we must change this manually.

Open the .idl (MyTestAtl.idl) file in your text editor.  You will see that this is where both of your classes are actually defined.  Scroll down and you will see the line declaring your IMyChild interface:

interface IMyChild : IDispatch{

Change this line to read

interface IMyChild : IMyAtlClass{

Now open the header file for your child class (MyChild.h).  You will se a section which looks like:

BEGIN_COM_MAP(CMyChild)
   COM_INTERFACE_ENTRY(IMyChild)
   COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

Add a line for your dependence on IMyAtlClass.  It should now read:

BEGIN_COM_MAP(CMyChild)
   COM_INTERFACE_ENTRY(IMyChild)
   COM_INTERFACE_ENTRY(IMyAtlClass)
   COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

Now you have to implement the wrapper routines for all the functions of your IMyAtlClass. It would be nice if we could base CMyChild on CMyAtlClass, but I don't know of an easy way to do that.

When you have done this, your MyChild.cpp file should look something like this:

STDMETHODIMP CMyChild::CreateFromString(BSTR pArg)
{
    return(E_FAIL);     // MyChild does not have a constructor which takes a string
}

STDMETHODIMP CMyChild::MyFunc1(LONG arg, LONG* pRet)
{
    if (!m_pMyChild)
    {
        return(E_NOINTERFACE);
    }

    *pRet   = m_pMyChild->MyFunc1(arg);

    return S_OK;
}


STDMETHODIMP CMyChild::Add(LONG arg1, LONG arg2, LONG* pRet)
{
    if (!m_pMyChild)
    {
        return(E_NOINTERFACE);
    }

    *pRet   = m_pMyChild->Add(arg1, arg2);

    return S_OK;
}

At this point, IMyChild class has all the functionality of it's base class IMyAtlClass.  Now we need to add our new initializer (IMyAtlClass did not have a constructor which took no parameters), and our new function 'Add'.  These can be added to the IMyChild class using the Add Method function, as I described before.  You will also need to add the variable 'm_pMyChild', to hold a the pointer to the actuall class data. (And don't forget to delete the m_pMyChild in the FinalRelease)

You then need to add the implementation code for them to your MyChild.cpp file:

STDMETHODIMP CMyChild::Create(void)        // Create with no data
{
    if (!(m_pMyChild = new MyChild()))
    {
        return(E_OUTOFMEMORY);
    }

    return S_OK;
}

STDMETHODIMP CMyChild::Add(LONG arg1, LONG arg2, LONG* pRet)
{
    if (!m_pMyChild)
    {
        return(E_NOINTERFACE);
    }

    *pRet   = m_pMyChild->Add(arg1, arg2);

    return S_OK;
}

You should then be able to build and create objects of either type.  The attached code shows a command line program which would show you how these objects can be created and used in c++

// Test.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#include "..\MyTestAtl\MyTestAtl.h"
#include "..\MyTestAtl\MyTestAtl_i.c"
 
 
int _tmain(int argc, _TCHAR* argv[])
{
    if (CoInitialize(0) == S_OK)
    {
        IMyAtlClass * pMyClass;
        IMyChild    * pMyChild;
 
        if (CoCreateInstance(CLSID_MyAtlClass, 0, CLSCTX_ALL, IID_IMyAtlClass, (void **) &pMyClass) == S_OK)
        {
            if (pMyClass->CreateFromString(_T("String")) == S_OK)
            {
                LONG val;
 
                pMyClass->MyFunc1(10, &val);
            }
 
            pMyClass->Release();
        }
 
        if (CoCreateInstance(CLSID_MyChild, 0, CLSCTX_ALL, IID_IMyChild, (void **) &pMyChild) == S_OK)
        {
            if (pMyChild->Create() == S_OK)
            {
                LONG val;
 
                pMyChild->Add(1, 2, &val);
 
                if (pMyChild->QueryInterface(IID_IMyAtlClass, (void **) &pMyClass) == S_OK)
                {
                    pMyClass->MyFunc1(10, &val);
                    pMyClass->CreateFromString(_T("xxx"));
                    pMyClass->Release();
                }
            }
 
            pMyChild->Release();
        }
 
        CoUninitialize();
    }
 
    return 0;
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:

Select allOpen in new window

 

by: khalilhenoudPosted on 2008-09-02 at 13:32:23ID: 22371395

John, thank you so much for your help.
I appreciate that.
But i want to remember you that you forgot about the static functions.
How can i declare a static function member in a class in ATL COM.
Thanks a lot for you time.

 

by: khalilhenoudPosted on 2008-09-02 at 13:33:40ID: 22371404

John, thank you so much for your help.
I appreciate that.
But i want to remember you that you forgot about the static functions.
How can i declare a static function member in a class in ATL COM.
Thanks a lot for you time.

 

by: JohnGabyPosted on 2008-09-02 at 13:39:21ID: 22371453

You cannot have static functions.  All functions are declared as pure virtual.  You cannot have data members either.  If you need properties, you need to supply get and put functions to retrieve and set the values.

 

by: khalilhenoudPosted on 2008-09-03 at 01:21:58ID: 22375000

Ok. So what is the alternative in COM.
Lets say i have a static member function in a class.
I want to use this function without creating an instance of this class.
How to do it in COM.
Should i make this function as global? or is there any keyword or something?
Thank you.

 

by: khalilhenoudPosted on 2008-09-03 at 01:39:30ID: 22375087

What about coclass?
Am I not able to create all my classes as coclasses and derive them from IUnknown and IDispatch?
This is an example of what i am thinking about:

lets say i have a class called IDGenerator and another class called Tag.

library ComCoreTechLib
{
      importlib("stdole2.tlb");
      [
            uuid(69922CC5-EED3-418A-AA7B-7968A9873572),
            helpstring("IDGenerator Class")
      ]
      coclass IDGenerator
      {
            [default] interface IUnknown;
                interface IDispatch;
      };
      [
            uuid(8392B506-FF9E-47C7-B12C-07E1D984D4CB),
            helpstring("Tag Class")
      ]
      coclass Tag
      {
            [default] interface IUnknown;
                interface IDispatch;
      };
};

Am I able to do it in that way?
Since in this way i will have to normal C++ classes of IDGenerator and Tag and i will be able to have static functions and static members and all the normal C++ style.
Thank you.

 

by: khalilhenoudPosted on 2008-09-03 at 05:06:06ID: 22376256

John, I know that i am bothering you but i still have on question.
I figured out that there is an options to add function not method.
Right click on the class and Add Function.
In this case i am able to choose the function as static or anything i want just like normal C++.
But the question is it OK to add all the functions of the class in that way.
Will I be able to use them from another project normally like the METHOD?
Thank you for your help.

 

by: JohnGabyPosted on 2008-09-03 at 08:26:51ID: 22378294

Yes, Visual C will let you add functions and variables to your interface class.  However, if you do so, it will no longer be a COM interface, and will not work properly with COM.  In C++, a COM interface is a pure virtual base class.  All the functions must be pure virtual, and it can contain no data elements.  For a discussion of Interfaces and Interface Implementations look here:

http://msdn.microsoft.com/en-us/library/ms694356(VS.85).aspx

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...