understanding COM

  • Thread starter Thread starter Julie
  • Start date Start date
J

Julie

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
 
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
 
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?
 
Back
Top