understanding COM

Discussion in 'Microsoft Dot NET' started by Julie, Apr 3, 2012.

  1. Julie

    Julie Guest

    Hi there,

    I have a C# application which uses the COM interface provided by
    Matlab. (It instantiates a Matlab object, which appears to run the
    Matlab interpreter.) Matlab has a method in its IDL called
    PutWorkspaceData() which takes a BSTR parameter.

    The main thing I'm trying to figure out is: a BSTR is a pointer: does
    this mean that all that's happening when I make this call is that a
    pointer (an address in memory) is being passed? Sometimes I have this
    set to a very large string. Is a nice little pointer being copied, or
    is a big long string being copied?

    I guess I'm really trying to figure out how memory works when I've got
    the CLR interpreting my C# code, and a Matlab interpreter running, the
    two exchanging data with eachother. Are they using the same areas of
    memory?

    Julie
     
    Julie, Apr 3, 2012
    #1
    1. Advertisements

  2. Julie

    ralph Guest

    On Tue, 3 Apr 2012 13:59:34 -0700 (PDT), Julie
    <> wrote:

    >Hi there,
    >
    >I have a C# application which uses the COM interface provided by
    >Matlab. (It instantiates a Matlab object, which appears to run the
    >Matlab interpreter.) Matlab has a method in its IDL called
    >PutWorkspaceData() which takes a BSTR parameter.
    >
    >The main thing I'm trying to figure out is: a BSTR is a pointer: does
    >this mean that all that's happening when I make this call is that a
    >pointer (an address in memory) is being passed? Sometimes I have this
    >set to a very large string. Is a nice little pointer being copied, or
    >is a big long string being copied?


    "a BSTR is a pointer:"
    One's sees that a lot, including MS's documentation ...
    "BSTR"
    http://msdn.microsoft.com/en-us/library/1b2d7d2c-47af-4389-a6b6-b01b7e915228(VS.85)

    They quite clearly and unequivocally state:
    "A BSTR is a pointer. The pointer points to the first character of the
    data string, not to the length prefix."
    This is technically true... however they then go on to demonstrate if
    you treat it like a simple pointer ... there is trouble brewing. <bg>

    [In fact the BSTR is an OLE Variant of type BSTR (a struct) that can
    be treated as an LPSTR to the internal string in some contexts.]

    You didn't say if you were sending or fetching, but it doesn't matter
    that much and reading that article should answer your immediate
    questions.

    >
    >I guess I'm really trying to figure out how memory works when I've got
    >the CLR interpreting my C# code, and a Matlab interpreter running, the
    >two exchanging data with eachother. Are they using the same areas of
    >memory?
    >


    Nope. Different space.

    COM is very straight-forward (unlike how it is popularily portrayed
    <g>) as long as you follow the rules, but the rules are often subtle
    and there are a few gotcha's for the unaware - you will probably have
    more questions.

    MS has stopped all support for these newsgroups. Some developers still
    visit occasionally, but for best results (reaching a larger audience
    and having any replies reviewed by a larger audience) I advise that
    you post additional questions to the Microsoft Developers Forum.

    http://www.microsoft.com/interop/Forum/default.aspx

    Pick one. (And perhaps visit all three to learn about COM and
    Interopt.)

    hth
    -ralph
     
    ralph, Apr 3, 2012
    #2
    1. Advertisements

  3. Julie

    Julie Guest

    On Apr 3, 2:59 pm, ralph <> wrote:
    > On Tue, 3 Apr 2012 13:59:34 -0700 (PDT), Julie
    >
    > <> wrote:
    > >Hi there,

    >
    > >I have a C# application which uses the COM interface provided by
    > >Matlab. (It instantiates a Matlab object, which appears to run the
    > >Matlab interpreter.) Matlab has a method in its IDL called
    > >PutWorkspaceData() which takes a BSTR parameter.

    >
    > >The main thing I'm trying to figure out is: a BSTR is a pointer: does
    > >this mean that all that's happening when I make this call is that a
    > >pointer (an address in memory) is being passed? Sometimes I have this
    > >set to a very large string. Is a nice little pointer being copied, or
    > >is a big long string being copied?

    >
    > "a BSTR is a pointer:"
    > One's sees that a lot, including MS's documentation ...
    > "BSTR"http://msdn.microsoft.com/en-us/library/1b2d7d2c-47af-4389-a6b6-b01b7...)
    >
    > They quite clearly and unequivocally state:
    > "A BSTR is a pointer. The pointer points to the first character of the
    > data string, not to the length prefix."
    > This is technically true... however they then go on to demonstrate if
    > you treat it like a simple pointer ... there is trouble brewing. <bg>
    >
    > [In fact the BSTR is an OLE Variant of type BSTR (a struct) that can
    > be treated as an LPSTR to the internal string in some contexts.]
    >
    > You didn't say if you were sending or fetching, but it doesn't matter
    > that much and reading that article should answer your immediate
    > questions.
    >
    >
    >
    > >I guess I'm really trying to figure out how memory works when I've got
    > >the CLR interpreting my C# code, and a Matlab interpreter running, the
    > >two exchanging data with eachother. Are they using the same areas of
    > >memory?

    >
    > Nope. Different space.
    >
    > COM is very straight-forward (unlike how it is popularily portrayed
    > <g>) as long as you follow the rules, but the rules are often subtle
    > and there are a few gotcha's for the unaware - you will probably have
    > more questions.
    >
    > MS has stopped all support for these newsgroups. Some developers still
    > visit occasionally, but for best results (reaching a larger audience
    > and having any replies reviewed by a larger audience) I advise that
    > you post additional questions to the Microsoft Developers Forum.
    >
    > http://www.microsoft.com/interop/Forum/default.aspx
    >
    > Pick one. (And perhaps visit all three to learn about COM and
    > Interopt.)
    >
    > hth
    > -ralph


    Thanks so much! Unfortunately, the first link you posted doesn't work.
    Did it get cut off there at the end?
     
    Julie, Apr 3, 2012
    #3
  4. Julie

    ralph Guest

    On Tue, 03 Apr 2012 17:11:00 -0500, ralph <>
    wrote:

    Oops! MS moved their stuff around again. Grabbed the wrong link ....


    Can't seem to find the "interopt" forum. Gone?
    Take a look at this...

    http://social.msdn.microsoft.com/Search/en-US/vstudio?query=interopt%
    20bstr&rq=meta:Search.MSForums.ForumID(24becc9b-b984-47b2-a748-
    a62e38c0066f)+site:microsoft.com&rn=Visual+C%23+General+Forum

    my apologizes.
    -ralph
     
    ralph, Apr 3, 2012
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Hester
    Replies:
    3
    Views:
    167
    Carl Prothman [MVP]
    Aug 11, 2003
  2. Marty McDonald

    Confirm understanding - web service exceptions

    Marty McDonald, Sep 8, 2003, in forum: Microsoft Dot NET
    Replies:
    9
    Views:
    653
    Yan-Hong Huang[MSFT]
    Sep 15, 2003
  3. Guest

    understanding .NET security

    Guest, Oct 2, 2003, in forum: Microsoft Dot NET
    Replies:
    1
    Views:
    167
    Guest
    Oct 3, 2003
  4. Magic1812
    Replies:
    0
    Views:
    152
    Magic1812
    Nov 30, 2003
  5. Guest

    Understanding the Object Browser

    Guest, Sep 16, 2004, in forum: Microsoft Dot NET
    Replies:
    0
    Views:
    130
    Guest
    Sep 16, 2004
Loading...

Share This Page