none
How to make COM Wrapper RRS feed

  • Question

  • I want to make COM Wrapper for other unmanaged language(VC++/VB6) to call

    Can anybody give me any information?


    • Edited by Jeff0803 Thursday, January 3, 2019 8:35 PM
    Thursday, January 3, 2019 8:35 PM

All replies

    • Proposed as answer by Castorix31 Friday, January 4, 2019 9:09 AM
    Thursday, January 3, 2019 8:51 PM
  • Hi Jeff0803,

    In Visual Studio, if the COM is registered in your machine, please refer to the follow steps to add related reference.

    right-click your project name in the Solution Explorer, and select "Add Reference." Any registered COM objects will be listed in the COM tab.

    For more information.

    https://stackoverflow.com/questions/2120690/tool-for-creating-net-wrappers-for-a-com-dll

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, January 4, 2019 7:49 AM
    Moderator
  • <style type="text/css">@page { margin: 2cm } p { margin-bottom: 0.25cm; line-height: 120% } a:link { so-language: zxx } </style>

    Creating a Basic Wrapper.

    These three patterns, proxy, decorator, and adapter are all implemented identically. They are all wrappers at the basic level. The functionality they provide is how we can make the distinction between them. Let's first look at a template for a basic wrapper and then at how to use a wrapper to implement each of these patterns can help us in our quest for the bizarre.

    Before we begin to understand how to perform super-feats, we need to understand the basic super-power all C# developers are born with - our secret ability to wrap (not to be confused with rap). Here is how a wrapper works:

    Let's say we have a Thing with a ThingString property and a method PrintThingString() as below:

    class Thing

    {

              private string m_string;

              public string ThingString

              {

                        get { return m_string; }

                        set { m_string = value; }

              }

              public void PrintThingString()

              {

                        Console.WriteLine(m_string);

              }

    }

    Here is how we create a basic ThingWrapper to wrap the Thing. It contains a reference to the Thing being wrapped and has the same signature. The ThingWrapper just passes requests into the wrapped Thing.

    class ThingWrapper

    {      

              private Thing m_thing;

              public ThingWrapper(Thing pThing)

              {

                        m_thing = pThing;

              }

              public string ThingString

              {

                        get { return m_thing.ThingString; }

                        set { m_thing.ThingString = value; }

              }

              public void PrintThingString()

              {

                        m_thing.PrintThingString();

              }

    }

    Because the ThingWrapper has the same signature as the Thing, it is really no different dealing with the Thing or the ThingWrapper. We can work with either the Thing or the ThingWrapper access our internal string m_string, or perform the base functionality which is to print a line to the console.

    Thing t = new Thing();

    t.ThingString = "This is the ThingString";

    t.PrintThingString();

     

    ThingWrapper tWrap = new ThingWrapper(t);

    tWrap.PrintThingString();

    tWrap.ThingString = "This is still the ThingString";
    tWrap.PrintThingString();

    We can wrap any class this way. Now that we understand this "wrapping power", we should only use it for good (or to do some cool stuff). Just remember, things can get pretty complicated if we have wrappers that are really not needed. Sometimes, however, we just can't live without them. Starting in the next article, let's next look at some of the super powers we can manifest using wrappers.

    Friday, January 4, 2019 9:00 AM