zoukankan      html  css  js  c++  java
  • COM简单应用示例

    使用com技术开发模式进行的示例。

    com技术关键部分源码:主要将所有接口都写入到这个文件中

    testinterface.h

    #ifndef TESTINTERFACE_H
    #define TESTINTERFACE_H
    
    #include <ComDef.h>
    //using namespace std;
    
    interface __declspec(uuid("d7a00288-18c9-4af2-bf95-c9755a4b587b")) TestInterface
    {
        STDMETHOD_ (int, Add)(int a, int b) PURE;
        STDMETHOD (PrintfValue)(int v) PURE;
    };
    
    #endif //TESTINTERFACE_H

    test.h

    #ifndef TEST_H
    #define TEST_H
    
    #include "TestInterface.h"
    
    class TestClassImpl : public TestInterface
    {
    public:
        STDMETHOD_ (int, Add)(int a, int b);
        STDMETHOD (PrintfValue)(int v);
    };
    
    #endif //TEST_H

    test.cpp

    #include "Test.h"
    
    #include <iostream>
    
    using namespace std;
    
    STDMETHODIMP_(int) TestClassImpl::Add(int a, int b)
    {
        return a+b;
    }
    
    STDMETHODIMP TestClassImpl::PrintfValue(int v)
    {
        cout << "result = " << v << endl;
        return S_OK;
    }

    main.cpp(主要进行以上接口实现测试)

    #include <iostream>
    #include "TestInterface.h"
    #include "Test.h"
    
    using namespace std;
    
    void main()
    {
        TestClassImpl obj;
        int result = obj.Add(34, 56);
        obj.PrintfValue(result);
        cout << endl;
    }
    煮酒论英雄
  • 相关阅读:
    MyBatis代码自动生成
    英语单词--程序员专属
    动态规划小例子
    Dijkstra 算法
    矩阵变换
    (转)贝塞尔曲线
    山寨了@上位者的怜悯的样式= =
    HDU 1115 (计算多边形重心)
    HDU 1147(线段相交+链表)
    HDU 1276 (直接链表模拟)
  • 原文地址:https://www.cnblogs.com/superstargg/p/3709730.html
Copyright © 2011-2022 走看看