CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 33
  1. #16
    Join Date
    Sep 2011
    Posts
    75

    Re: COM and .NET vs WinAPI

    If a Client is writing a plugin, then the client needs to be able to make an exectuable that can both call functions of the server and exchange data back and forth. Same goes if he is using the application as a stand alone extension. So really there shouldn't be any UI exposure on my part

  2. #17
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: COM and .NET vs WinAPI

    Exposing server functions cannot be a problem. And two-way exchanging data cannot be either. Of course, if your server exposes a predefined set of functions and data types (this is what they call 'interface'). But then what that plugin would be for? Plugins usually extend server functionality. So, the new functionality should be exposed from the server as well, along with data types it uses. Is this the intention? Or the plugins are just for special file format processing, like open/update data source? Or adding new communication channels? Something else? All of that?
    Best regards,
    Igor

  3. #18
    Join Date
    Sep 2011
    Posts
    75

    Re: COM and .NET vs WinAPI

    Igor: I beleive the goal is all of that eventually, but I am going to start out very simple haha.

    I think I got ahead of myself. So, I'm just going to start a new project and make it as easy as I can.

    I want to create an application using C, have it store a string. Then I will create another application (as simple as a console application), run both at the same time, and be able to setString() and getString() from the latter application.

    What kind of architecture should I implement? I know this could be simple as writing to a text file and reading it from the second application, but my employer wants something more sophisticated, I suppose. So Imagine these are the only requirements for this application.

    The software is very complex, but basically the use cases can be simplified to this just as proof of concept.

    EDIT: ALSO, I appreciate the ongoing conversation and your responses, it's been great just narrowing down the focus and all the design tips.
    Last edited by kingting; January 19th, 2012 at 11:03 AM.

  4. #19
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: COM and .NET vs WinAPI

    I want to create an application using C, have it store a string. Then I will create another application (as simple as a console application), run both at the same time, and be able to setString() and getString() from the latter application.

      • Socket or named pipe as a data transport, hosted by server side
      • dll implementing custom data exchange protocol (or XML exchange maybe) loaded on client side
    1. COM out-of-proc server, singletone
    Best regards,
    Igor

  5. #20
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: COM and .NET vs WinAPI

    Since you are only dealing with data, I would use a WCF web service (.Net C#).

    I would wrap your exisiting C code as Managed C++ assemblies and expose them with the above C# WCF service.

    That way, any client capable of consuming web service code can connect to the service.

  6. #21
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: COM and .NET vs WinAPI

    Yeah, I actually thought of web service. But frankly, as per my experience of dealing with WCF, it looks painless only for native .NET clients. It would be a pain to immerse its service part to existent C app (as a plugin I guess) as well as implement a proxy WCF client library for non .NET clients (API transponder dll). Knowledge of cross language techniques is mandatory. Though, really nothing impossible in that.
    Best regards,
    Igor

  7. #22
    Join Date
    Sep 2011
    Posts
    75

    Re: COM and .NET vs WinAPI

    So does this C executable have to be compiled a s a COM object or can I have this C application and a .idl resource file and compile them together to create a separate exe for the application and the interface. Also would it be wiser to use the dispInterface of the normal vtable interfaces? I'm about 150 pages into this book and am still somewhat confused about this... maybe I am just dumb.

    EDIT: Didnt see the past 2 posts made by u guys

    I hadn't even considered WCF. Should I read more into it? I'm also not very sure how to wrap my code...
    Last edited by kingting; January 19th, 2012 at 05:45 PM.

  8. #23
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: COM and .NET vs WinAPI

    All this "progressive" and "fresh" stuff is quite tricky, and typically requiring for quite a long learning curve. Why don't you consider oldie-goldie socket solution with XML exchange?
    Best regards,
    Igor

  9. #24
    Join Date
    Sep 2011
    Posts
    75

    Re: COM and .NET vs WinAPI

    So it seems...I'm thinking about just going with the COM out of process server. I will try to draft up a simple project ASAP and see what happens.

    Regardless thanks for the input so far!

  10. #25
    Join Date
    Sep 2011
    Posts
    75

    Re: COM and .NET vs WinAPI

    Hi All,

    I am currently following this tutorial
    http://www.codeproject.com/KB/COM/com_in_c1.aspx

    but this teaches you how to build a .dll. If i already have an existing application, how do incorporate this into the build?

    There is also no mention of .idl files does this mean I can bypass all this somehow if i just compile my own .idl?

  11. #26
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: COM and .NET vs WinAPI

    Now you got caught. COM is extremely complicated in its details, so all the contemporary COM coding is wizard aided. Which means, it's quite easy to start from scratch end evolve, as wizards do that for you. But it's a real pain to modify something existent. Should I mention that I warned you before?
    Best regards,
    Igor

  12. #27
    Join Date
    Sep 2011
    Posts
    75

    Re: COM and .NET vs WinAPI

    http://www.codeproject.com/Articles/...-skeleton-code
    I am actually using this now, and plan on adapting the code for the out of process automatation enabled server. Is this executable supposed to be running while my simple app is running? Am i meant to have the implementation of my application within the compilation of this code or will I essentially have 3 executables: client, server, and the COM interface?

    I already regret my decision haha

  13. #28
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: COM and .NET vs WinAPI

    If you are planning on going the COM route, then I suggest you look at the various ATL projects. The ATL related project templates allow you to create in process or out of process COM servers as well as a Windows service project that hosts COM servers.

  14. #29
    Join Date
    Sep 2011
    Posts
    75

    Re: COM and .NET vs WinAPI

    So all these books and tutorials help me understand the concepts within COM, such as implementing IUnknown, IClassFactory, etc, etc. but what I don't understand how I can piece this together with a currently existing application. It seems like the application has to be designed from the ground up using COM. If I'm not mistaken, there are several ways to approach this.

    a) out of process .exe server
    b) create a COM dll with the object and function implementation... and load it into a project?

    in both of these cases do i essentially have to rewrite the entire existing application?

    The thing is the application is meant to be operated on its own, with these interfaces and communication protocols just as added functionality but in no way the main use of the application, so rewriting the code seems excessive...

    I am also looking at WCF and am wondering how to convert this legacy C app into managed .NET code. would you have to rewrite all functionality into a .dll and start a new project, loading this dll using calls with CLR compliant languages?

    Honestly, I am so torn on this issue. I realize that there is a steep learning code to all these things, but I feel hesitant in wasting time on something that will not work or seems to be obsolete (everyone tells me not to use COM because of this) or not be at least semi-easily attainable (e.g can be accomplished within the span of a couple of months), as I would imagine rewriting the source in .NET is the best way to go, new development and features of the app would be completely stalled for at least 6 months I'd imagine.

    I also feel really dumb that I've spent a week and a half researching what to do and Feel more lost than I was when I started

    The main point of this small rant is that I have no idea how to deploy COM within the current configuration of my application
    Last edited by kingting; January 25th, 2012 at 06:22 PM.

  15. #30
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: COM and .NET vs WinAPI

    Quote Originally Posted by kingting View Post
    So all these books and tutorials help me understand the concepts within COM, such as implementing IUnknown, IClassFactory, etc, etc. but what I don't understand how I can piece this together with a currently existing application. It seems like the application has to be designed from the ground up using COM. If I'm not mistaken, there are several ways to approach this.

    a) out of process .exe server
    b) create a COM dll with the object and function implementation... and load it into a project?

    in both of these cases do i essentially have to rewrite the entire existing application?

    The thing is the application is meant to be operated on its own, with these interfaces and communication protocols just as added functionality but in no way the main use of the application, so rewriting the code seems excessive...
    COM allows you to expose functionality that allows external processes to manipulate data. If your app isn't designed with this in mind from the get go, then it's usually very difficult to tack this on afterwards.

    Quote Originally Posted by kingting View Post
    I am also looking at WCF and am wondering how to convert this legacy C app into managed .NET code. would you have to rewrite all functionality into a .dll and start a new project, loading this dll using calls with CLR compliant languages?
    If you write this in WCF, then the main WCF service would be written in C#, and you would have to either rewrite your existing functionality in C#, or write assemblies in Managed C++ that calls your C code. If the existing C code is in dll form, then you might be able to directly pinvoke to it in C#.

    Quote Originally Posted by kingting View Post
    Honestly, I am so torn on this issue. I realize that there is a steep learning code to all these things, but I feel hesitant in wasting time on something that will not work or seems to be obsolete (everyone tells me not to use COM because of this) or not be at least semi-easily attainable (e.g can be accomplished within the span of a couple of months), as I would imagine rewriting the source in .NET is the best way to go, new development and features of the app would be completely stalled for at least 6 months I'd imagine.

    I also feel really dumb that I've spent a week and a half researching what to do and Feel more lost than I was when I started

    The main point of this small rant is that I have no idea how to deploy COM within the current configuration of my application
    As I said, tacking on COM to an existing app isn't trivial.

    If it were me, I would probably avoid the COM route (and I am quite proficient at writing COM apps with ATL).

    I would look into going the WCF route (as COM is a bit of dated technology and WCF has several hosting options).

    I have a Tray Notify article series that might help you get your feet wet with WCF. It shows how to host a WCF service inside a Windows service app.

    See my signature line for the links.

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured