CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Need some help converting Delphi interface definitions into C++ for VS 2008

    I'm curious if there're any Delphi developers here, and also people who know COM better than I do? Yeah, I know, quite a mix hah

    Anyway, my goal is to call a Shell interface described here, which unfortunately is written in Delphi. I need to convert it to run in my Visual Studio 2008 C++/MFC project.

    I did my best at rewriting it for VS 2008, but I'm obviously missing something because the code crashes (and I know that the Delphi equivalent works.)

    I'm attaching my small demo project. Can someone take a look?
    Attached Files Attached Files

  2. #2
    Join Date
    May 2013
    Posts
    26

    Re: Need some help converting Delphi interface definitions into C++ for VS 2008

    Since it is a COM object, can't you already use and call it from any C++ program? Or are you rewritting it because you need to modify its behaviour? You could always do the mods in Delphi, it's nice and easy to learn.

  3. #3
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: Need some help converting Delphi interface definitions into C++ for VS 2008

    Quote Originally Posted by moffy View Post
    Since it is a COM object, can't you already use and call it from any C++ program?
    How do I do that?

  4. #4
    Join Date
    May 2013
    Posts
    26

    Re: Need some help converting Delphi interface definitions into C++ for VS 2008

    I can't remember the details offhand but if you read up about COM in windows/Visual Studio it will have the details. As long as the COM object is registered on the PC you can access it through its interfaces. Perhaps someone else more familiar can provide the details?

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Need some help converting Delphi interface definitions into C++ for VS 2008

    Quote Originally Posted by moffy View Post
    I can't remember the details offhand but if you read up about COM in windows/Visual Studio it will have the details. As long as the COM object is registered on the PC you can access it through its interfaces. Perhaps someone else more familiar can provide the details?
    if it's in C++, it doesn't have to be registered, you can access/use non-registered COM objects in C++ easily, other languages typically don't support this at all.

    Possible ways to access COM in C++ (from easier to harder):
    - For Vc++, the easy way out is to use #import to "load" the COM dll/exe and (hidden) create the appropriate include files for the compiler.
    - Creating the class wrappers explicitely with ATL or MFC (or one of the many support libraries that do this as well)
    - A bit harder is using the raw COM interfaces for which you'll need a c++ header.
    - And of course, if the COM object supports IDispatch, use the "scripting approach" to access the COM interfaces.

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

    Re: Need some help converting Delphi interface definitions into C++ for VS 2008

    You can easily create COM wrapper with ATL. Read up on it in these books:

    http://www.amazon.com/Beginning-ATL-.../dp/1861001207
    http://www.amazon.com/Professional-A.../dp/1861001401

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Need some help converting Delphi interface definitions into C++ for VS 2008

    Quote Originally Posted by Arjay View Post
    You can easily create COM wrapper with ATL.
    I guess our definition of 'easy' differs somewhat!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

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

    Re: Need some help converting Delphi interface definitions into C++ for VS 2008

    Quote Originally Posted by 2kaud View Post
    I guess our definition of 'easy' differs somewhat!
    Compared to trying to create a wrapper with MFC, ATL is easy.

  9. #9
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Need some help converting Delphi interface definitions into C++ for VS 2008

    creating an explicit wrapper is just as easy with ATL as it is with MFC (and just as easy as FlexCOM)
    USING the wrappers, dpends on the situation
    if you already have an MFC project, the MFC wrapper will integrate easier. If you're not already using MFC, then going the MFC route is not advised.
    setting up the ATL wrappers takes a bit of pushing and prodding in the project properties.

    But it's still easier to do it this way than doign COM with the raw interfaces.

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

    Re: Need some help converting Delphi interface definitions into C++ for VS 2008

    Quote Originally Posted by OReubens View Post
    If you're not already using MFC, then going the MFC route is not advised.
    setting up the ATL wrappers takes a bit of pushing and prodding in the project properties.
    It's even easier than that. Just open the new class dialog, select ATL under Visual C++ and choose "Add ATL Support To MFC". That sets up the MFC project for using ATL, then you can import and or create object.s

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