none
COM/.NET client-server interop issue RRS feed

  • Question

  • Hello everyone,

    I work on an OPC client/server solution, the client being written in C# and the server in C++, I'm using VS 2010 Pro. I first wrote the client, and tested it successfully on various other OPC COM server (those available on the internet). From this point, I don't think the client is faulty, because I followed the rules of interoperability.

    On the other side, the server is implemented as an ATL Exe project that supports connection points. The standard specific interface definition, that OPC requires, is provided through two .idl files (opcda.idl and opccommn.idl). There are two COM objects, a server class and a group class, and they implement the mentioned interfaces. There are also a few non-COM classes for various purposes (not directly related to the issue).

    I compiled the project successfully and used the generated files (_i.c, _i.h and _p.c - for all of the 3 COM objects) to make the proxy/stub dll, which skeleton project was also generated by the ATL wizard.

    Then, I registered the server with /regserver and the proxy/stub with regsvr32 and checked afterwards in the registry, everything seems fine.

    The problem arises, when I try to connect from the client. I use:

     

     

    private IOPCServer myServer;
    ...
    
    public void connect() {
    ...
    try
    {
    Type srv = Type.GetTypeFromProgID(ProgID);
    myServer = (IOPCServer)Activator.CreateInstance(srv);
     ...
    }
    catch (Exception e) {
    System.Console.WriteLine(e.ToString());
    } 
    }
    

    it rises the Exception "Unable to cast COM object of type 'System.__ComObject' to interface type 'OPCDA.IOPCServer'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{39C13A4D-011E-11D0-9675-0020AFD8ADB3}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

    However, I found out, that the client isn't even calling the QueryInterface that I implemented in the server (i set different return values).

     

    So, did I miss something? Perhaps, the proxy/stub needs to be referenced in some way by the client? Or is there the possibility that I somehow failed to include the .idl files and their interfaces in the right way?

    Any suggestion will help. Thanks in advance

    Friday, July 22, 2011 12:31 PM

Answers

  • Hi,

    This might not help you because I am using object and not an interface, but I had an error with the Activator.CreateInstance, and when I used the overloaded function and passed in false (ie myServer = (IOPCServer)Activator.CreateInstance(srv,false);) it worked. 

    The false tells Activator to only look for public constructors.


    Christine Murphy Software Engineer
    • Marked as answer by Paul Zhou Tuesday, August 2, 2011 6:34 AM
    Friday, July 22, 2011 2:46 PM

All replies

  • Did you check what it is you actually get back? Maybe that can give some insight what happens.

    Friday, July 22, 2011 1:11 PM
    Moderator
  • Hi,

    This might not help you because I am using object and not an interface, but I had an error with the Activator.CreateInstance, and when I used the overloaded function and passed in false (ie myServer = (IOPCServer)Activator.CreateInstance(srv,false);) it worked. 

    The false tells Activator to only look for public constructors.


    Christine Murphy Software Engineer
    • Marked as answer by Paul Zhou Tuesday, August 2, 2011 6:34 AM
    Friday, July 22, 2011 2:46 PM
  • I just would like to point out that you seem to have tried to type a question where your display name is.

    You appear as "How to Get member values of structure pointer pass"

    Your signature is: Christine Murphy Software Engineer

    You may want to change the display name in your profile as in some lists it looks quite strange. :)

    Friday, July 22, 2011 3:01 PM
    Moderator
  • If you are sure the progid is correct and the object indeed expose the interfaces, check if the COM server supports the current thread apartment.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Saturday, July 23, 2011 12:57 AM
  • Thanks a lot, guys, especially Christine, I found the error: I didn't include the interface IOPCServer in the COM Map as COM_INTERFACE_ENTRY(IOPCServer). Don't know how I missed this interface only, but it puzzled me a lot.
    Monday, July 25, 2011 7:35 AM