Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2005

Tip: Looking for answers? Try searching our database.

Question about default parameters in COM type lib and use in C# after using tlbimp.exe

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mac Dyer - 20 Sep 2005 02:13 GMT
Hi there.  I have a COM DLL that I have converted into an interop assembly
via the tlbimp.exe tool.  One function that I am trying to use now in C# has
a default parameter defined in my IDL file:

HRESULT Convert( [in, defaultvalue( "" )] BSTR file, [out, retval] long
*count  );

When I try to make use of the function in C# I get a compiler error saying
that this function does not take 0 parameters.
using the ildasm.exe to take a look at the assembly code I get:

.method public hidebysig newslot virtual
       instance int32  Convert([in][opt] string  marshal( bstr) file)
runtime managed internalcall
{
 .custom instance void
[mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = (
01 00 09 00 00 00 00 00 )
 .param [1] = ""
 .override MYINTEROP:Convert
}

It looks to me like the parameter is optional and that it is indeed setting
a default value of "".  Do I have to do something else for C# to recognize
this?  It is not that big of a deal to pass a value to the function( I would
prefer not to ), but it seems like there should be all that is needed for C#
to fill in the value if it isn't there.  Any help is appreciated.  Thank you
for your time.

-Mac
Mattias Sjögren - 20 Sep 2005 06:41 GMT
>It looks to me like the parameter is optional and that it is indeed setting
>a default value of "".  Do I have to do something else for C# to recognize
>this?

There's no way, C# simply doesn't support optional parameters.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Rag - 30 Sep 2005 09:26 GMT
try using System.Reflection.Missing.Value;
Mattias Sjögren - 07 Oct 2005 23:12 GMT
>try using System.Reflection.Missing.Value;

That works for object/VARIANT, not for string/BSTR.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.