Call an COM Server dispinterface C++

Hi All,

I have a little tricky question for you all. Maybe (I hope so) someone can help me with my problem.

I work in Visual Studio 2005 with an C++ project. This project does not support ATL + MFC and it should not be changed, if it’s possible. Now I should call an function / get an information out of an COM (.exe) server that is still running.

Below you can see the code that was created by the MIDL Compiler / by the OLE/COM Object Viewer from my test_programm.exe(COM server).

In the code of the Test.idl file you can see the following:
dispinterface ICWOLEEvents {
properties:
methods:
[id(0x00000001)]
void OnConfigurationApply([in, out] VARIANT_BOOL* pAccept);
[id(0x00000002)]
void OnShowMessageDlg(
[in] IMsgDlg* pIMsg,
[out, retval] VARIANT_BOOL* Result);
};

The problem now I have is that I must call / work with the OnConfigurationApply and the OnShowMessageDlg functions in my C++ project. I’ve implemented the three (Test_h.h / Test_i.c / Test.idl) files in my project and I could recompile it without any error messages.

Now my questions are:
- How can I work with these two functions(OnConfigurationApply and the OnShowMessageDlg) in my C++ project?
- Is there anywhere an simple/complete c++ example project?
- Can someone explain me how I must start to work / get some information with these functions?

I’ve posted a few weeks a similar question. But now after my holiday I will post this question a little bit more detailed again.

Let me know if you need any more information about these files.

MANY MANY thanks for any hints.

Juergen

Test_h.h
1
2
3
4
5
6
7
8
9
10
.
.
.
MIDL_INTERFACE("6775FB91-B5BE-11D6-A996-0050BA24C7B9")
    ICWOLEEvents : public IDispatch
    {
    };
.
.
.


Test_i.c
//Created with the MIDL Compiler
1
2
3
4
5
6
7
8
9
.
.
.
MIDL_DEFINE_GUID(IID, IID_ICWOLE2,0xF560F761,0x2948,0x11D7,0xA9,0xBF,0x00,0x50,0xBA,0x24,0xC7,0xB9);
MIDL_DEFINE_GUID(CLSID, CLSID_CWOLEv2,0xF560F763,0x2948,0x11D7,0xA9,0xBF,0x00,0x50,0xBA,0x24,0xC7,0xB9);
.
.
.



Test.idl
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: test_programm.exe
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
[
  uuid(90B4344B-90CD-4527-BC00-4F4D45C793D6),
  version(2.13),
  helpstring("CW  CWOLE")
]
library CW_CWOLE
{
    // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("stdole2.tlb");

    // Forward declare all types defined in this typelib
    interface ICWOLE2;
    dispinterface ICWOLEEvents;
.
.
.
.
.

    [
      uuid(6775FB91-B5BE-11D6-A996-0050BA24C7B9),
      version(1.1),
      helpstring("Event dispatch interface for CW CWOLE")
    ]
    dispinterface ICWOLEEvents {
        properties:
        methods:
            [id(0x00000001)]
            void OnConfigurationApply([in, out] VARIANT_BOOL* pAccept);
            [id(0x00000002)]
            void OnShowMessageDlg(
                            [in] IMsgDlg* pIMsg, 
                            [out, retval] VARIANT_BOOL* Result);
    };

    typedef [uuid(5CBBA151-1C47-4D6C-B14C-C527E333F812), version(1.2)]
    enum {
        ECS_DEFAULT = 0,
        ECS_FRONT = 1,
        ECS_LEFT = 2,
        ECS_RIGHT = 3,
        ECS_LEFTUP = 4,
        ECS_RIGHTUP = 5,
        ECS_TOP = 6,
        ECS_BACK = 7,
        ECS_BACKLEFTUP = 8,
        ECS_BACKRIGHTUP = 9,
        ECS_BOTTOM = 10
    } ECamSetup;

    typedef [uuid(9545E3CA-6401-4418-A040-DA3A89E2C792), version(1.3)]
    enum {
        EPM_PERSP = 0,
        EPM_ORTHO = 1,
        EPM_2D = 2
    } EProjectionMode;

    [
      uuid(F560F763-2948-11D7-A9BF-0050BA24C7B9),
      version(2.13),
      helpstring("CWOLE2")
    ]
    coclass CWOLEv2 {
        [default] interface ICWOLE2;
        [default, source] dispinterface ICWOLEEvents;
    };
Is nobody out there who can help me? A link to a complete tutorial or anything else?
This should be posted in the Windows Programming section.

MFC and ATL COM support exist for a reason. It's a real dogs dinner trying to do COM without them.

I recomend you create a new ATL DLL project that interfaces between the COM object and the non-COM application that's using the service. It's a nice clean seperation that uses ATL where it's meant to be used and keeps the main application clean.

Remember, COM is just an interface technology.

Anyone who wants to start messing around with IDL and C COMM calls needs a holiday.
Last edited on
Topic archived. No new replies allowed.