Re: [ADVANCED-DOTNET] Redeclaring COM interface return type - ??

2002-10-09 Thread Andrew Hopper

Correct. Simply remove the PreserveSigAttribute, and the HRESULT will
automatically be checked. An exception will be thrown when a failure HRESULT
is returned. This is incredibly convenient, but there are occasionally
methods that return S_FALSE instead of S_OK to indicate a safe failure, in
which case you'll have to dust off good old PreserveSigAttribute in order to
be able to inspect the result.

When there is an [out] parameter, you can simply use the out keyword.
However, I'm guessing you really meant an [out, retval] parameter, in which
case the retval parameter is treated as the return value of the method and
is removed from the list of arguments. As an example, an IDL interface
containing a method with a retval parameter translates from
[
...
uuid(...)
...
]
interface IXXX : IUnknown
{
  HRESULT DoSomething([in] BSTR Input1, [out, retval] BSTR* pVal);
  // This method can return S_FALSE, so we'll want to preserve the method
  // signature and inspect the return value.
  HRESULT DoSomethingElse([in] BSTR Input1, [out, retval] BSTR* pVal);
}

to

[ComImport, Guid(...),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IXXX
{
  String DoSomething(String Input1);
  [PreserveSig]
  Int32 DoSomethingElse(String Input1, out String returnValue);
}

For more detail, see COM Interop Part 1: C# Client Tutorial in the MSDN
library.

Hope this helps.
-Andy Hopper


- Original Message -
From: Thomas Tomiczek [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, October 09, 2002 8:52 AM
Subject: [ADVANCED-DOTNET] Redeclaring COM interface return type - ??


Hello,

Small problem I just run into. Having done my own share of COM interop,
I still dont know how to change the signature from PreserveSig to
something more convenient :-)

Like:
public interface IFileSinkFilter
{
[PreserveSig]
int SetFileName(
[In, MarshalAs(UnmanagedType.LPWStr)]
string  pszFileName,
[In, MarshalAs(UnmanagedType.LPStruct)]
AMMediaType pmt );

}

How can I change this that I just have void SetFileName (a, b)? Just
skipping the PreserveSig, surely :-)

But what when there is an out parameter?

Thanks in advance.

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.



Re: [ADVANCED-DOTNET] Redeclaring COM interface return type - ??

2002-10-09 Thread Thomas Tomiczek

Inline...

-Original Message-
From: Andrew Hopper [mailto:[EMAIL PROTECTED]] 
Sent: Mittwoch, 9. Oktober 2002 17:03
To: [EMAIL PROTECTED]
Subject: Re: [ADVANCED-DOTNET] Redeclaring COM interface return type -
??


Correct. Simply remove the PreserveSigAttribute, and the HRESULT will
automatically be checked. An exception will be thrown when a failure
HRESULT is returned. This is incredibly convenient, but there are
occasionally methods that return S_FALSE instead of S_OK to indicate a
safe failure, in which case you'll have to dust off good old
PreserveSigAttribute in order to be able to inspect the result.


*** SHIT. Sorry :-) There are components like this? GOD BEWARE :-)

When there is an [out] parameter, you can simply use the out keyword.
However, I'm guessing you really meant an [out, retval] parameter, in
which case the retval parameter is treated as the return value of the
method and is removed from the list of arguments. As an example, an IDL
interface containing a method with a retval parameter translates from [
...
uuid(...)
...

*** OK, so the trick is that was used to compile this has already the
retval point. I just basically move one parameter (which? Any way to
find this out without access to the ID`?) to the return type.

*** Thanks.

...

For more detail, see COM Interop Part 1: C# Client Tutorial in the
MSDN library.

*** Yes, thanks :-) tel me I am a  beginner here :-) No, really -
thanks.

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.



Re: [ADVANCED-DOTNET] Redeclaring COM interface return type - ??

2002-10-09 Thread Axel Heitland

 *** OK, so the trick is that was used to compile this 
 has already the retval point. I just basically move 
 one parameter (which? Any way to find this out without 
 access to the ID`?) to the return type.

[out,retval] is always the last (=rightmost) parameter.

HTH
Axel

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.



Re: [ADVANCED-DOTNET] Redeclaring COM interface return type - ??

2002-10-09 Thread Andrew Hopper

- Original Message -
From: Thomas Tomiczek [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, October 09, 2002 12:56 PM
Subject: Re: [ADVANCED-DOTNET] Redeclaring COM interface return type - ??

snip

*** OK, so the trick is that was used to compile this has already the
retval point. I just basically move one parameter (which? Any way to
find this out without access to the ID`?) to the return type.


snip

Well, if there is a retval, it's always going to be the last parameter. With
respect to getting the IDL, there are a couple of ways to get the IDL for a
given COM interface: one is to see if it's documented in the MSDN library,
another is to use the OleView tool from VS6 (you can directly load it from
the executable if the type library was embedded as a resource, or you can
choose it from the list of registered type libraries), and yet another is to
see if the IDL file containing the declaration is in the platform SDK. If
you can't find it using one of those, someone must not want you to use that
interface ;). By the way, I usually end up combining the MSDN library's
documentation as XML documentation with the declaration from the IDL files
so I can get pretty IntelliSense tooltips with descriptions.

-Andy

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.