Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to pass "missing" to an optional string argument in a VB6 COM DLL but it is giving me "cannot convert from 'object' to 'string'".

In simplified form, I'm calling from C# using:

object o = someFunction(System.Type.Missing)

In VB6, this function is declared as:

Public Function someFunction(Optional ByVal arg As String = "Default")
.
.
.
End Function

I can pass in the string "Default" to get the behaviour I want but I would prefer to pass missing so that I always use the default parameter value defined in the VB6 DLL.

Can I just cast "missing" to a string to fool the compiler or is there some more subtle way of doing this?
Posted

I doubt it. You'd be better not using VB6 at all, what with it being obsolete for a decade. You could try null, I guess, but if it can't handle you calling the method with no parameters, I can't imagine C# having any design given to running against VB6.
 
Share this answer
 
I never used a VB dll in .Net. But I guess a string type in .Net is not just a string type like in VB6. It is a object type, it holds other properties also. May thats the reasom why its showing such a error.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900