PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

understanding COM

 
 
Julie
Guest
Posts: n/a
 
      3rd Apr 2012
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
 
Reply With Quote
 
 
 
 
ralph
Guest
Posts: n/a
 
      3rd Apr 2012
On Tue, 3 Apr 2012 13:59:34 -0700 (PDT), Julie
<(E-Mail Removed)> 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/libr...7e915228(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
 
Reply With Quote
 
 
 
 
Julie
Guest
Posts: n/a
 
      3rd Apr 2012
On Apr 3, 2:59*pm, ralph <(E-Mail Removed)> wrote:
> On Tue, 3 Apr 2012 13:59:34 -0700 (PDT), Julie
>
> <(E-Mail Removed)> 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?
 
Reply With Quote
 
ralph
Guest
Posts: n/a
 
      3rd Apr 2012
On Tue, 03 Apr 2012 17:11:00 -0500, ralph <(E-Mail Removed)>
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/Sea...uery=interopt%
20bstr&rq=meta:Search.MSForums.ForumID(24becc9b-b984-47b2-a748-
a62e38c0066f)+site:microsoft.com&rn=Visual+C%23+General+Forum

my apologizes.
-ralph
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Understanding XP's licence: my scenario Roach Windows XP Help 3 12th Sep 2004 10:07 PM
Help Understanding DCOM Error JD Windows XP Help 1 3rd Sep 2004 01:39 AM
Can't reach one of my Win-XP systems help with understanding boot.ini tjdarth Windows XP Help 0 20th Jul 2004 01:56 AM
Understanding Windows Internals - recommended books? Carl Farrington Windows XP Help 1 8th Jun 2004 01:27 AM
understanding files and folders Oxy Windows XP Help 2 23rd Feb 2004 04:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:49 AM.