cannot convert from 'ref object' to 'tagVARIANT*'

user3738273

I have a method in C++/CLI that uses VARIANT* as a parameter. Whenever I invoke the method in C#, passing a null object as the VARIANT* parameter, I get compile errors.

ERROR:

Argument #: cannot convert from 'ref object' to 'tagVARIANT*'

Here's the C++/CLI method:

int foo::fooMethod( VARIANT* varFoo)
{
...
return 1
}

C# code(which references the C++ DLL):

foo test = new foo();
object objFoo;
int iRet = foo.fooMethod( ref objFoo );
Hans Passant

Conversion from System::Object^ to a COM Automation VARIANT is only ever automatic when you let the CLR call a COM interface method. Seeing it appear in native code is fairly unusual, do make sure that you are not bypassing the normal COM interop option. Readily usable from C# or VB.NET code, just add a reference to the type library.

Simply declare the argument as Object^ instead. If you really need a VARIANT then you can get one from Marshal::GetNativeVariantForObject().

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error: Argument 1: cannot convert from 'int?[]' to 'object[]'

From Dev

Assert.IsInstanceOfType cannot convert from object to System.Type

From Dev

Cannot convert generic object

From Dev

type mismatch cannot convert from element type object to string

From Dev

Member Expression cannot convert to object from nullable decimal

From Dev

Type mismatch: cannot convert from element type Object to Cookie

From Dev

Java - Type mismatch: cannot convert from element type Object to String

From Dev

Type mismatch: cannot convert from Object to Class object

From Dev

Compiler Error: Cannot convert from 'List<string>' to 'IList<object>'

From Dev

Java generics. Type mismatch: cannot convert from object to

From Dev

cannot convert from list<object> to list<callable<type>> java

From Dev

Type mismatch: cannot convert from Optional<Object> to BasketDTO

From Dev

spark Type mismatch: cannot convert from JavaRDD<Object> to JavaRDD<String>

From Dev

error : Type mismatch: cannot convert from Object to JSONObject

From Dev

Assert.IsInstanceOfType cannot convert from object to System.Type

From Dev

type mismatch cannot convert from element type object to string

From Dev

Type mismatch: cannot convert from element type Object to Cookie

From Dev

Java - Type mismatch: cannot convert from element type Object to String

From Dev

Type mismatch: cannot convert from Object to Class object

From Dev

Java generics. Type mismatch: cannot convert from object to

From Dev

Cannot convert from Object to Int

From Dev

cannot convert from 'object' to 'string'

From Dev

C# Cannot convert from 'ref xxx' to 'ref object'

From Dev

Type mismatch: cannot convert from Set<Object> to Set<Long>

From Dev

Cannot convert from object to string

From Dev

Cannot convert from `Expression<Func<T1, T2>>` to `Expression<Func<object, object>>`

From Dev

Cannot convert from object to System.ValueType

From Dev

Cannot recurse over object[] because cannot convert object to object[]

From Dev

Type mismatch: cannot convert from element type Object to List

Related Related

  1. 1

    Error: Argument 1: cannot convert from 'int?[]' to 'object[]'

  2. 2

    Assert.IsInstanceOfType cannot convert from object to System.Type

  3. 3

    Cannot convert generic object

  4. 4

    type mismatch cannot convert from element type object to string

  5. 5

    Member Expression cannot convert to object from nullable decimal

  6. 6

    Type mismatch: cannot convert from element type Object to Cookie

  7. 7

    Java - Type mismatch: cannot convert from element type Object to String

  8. 8

    Type mismatch: cannot convert from Object to Class object

  9. 9

    Compiler Error: Cannot convert from 'List<string>' to 'IList<object>'

  10. 10

    Java generics. Type mismatch: cannot convert from object to

  11. 11

    cannot convert from list<object> to list<callable<type>> java

  12. 12

    Type mismatch: cannot convert from Optional<Object> to BasketDTO

  13. 13

    spark Type mismatch: cannot convert from JavaRDD<Object> to JavaRDD<String>

  14. 14

    error : Type mismatch: cannot convert from Object to JSONObject

  15. 15

    Assert.IsInstanceOfType cannot convert from object to System.Type

  16. 16

    type mismatch cannot convert from element type object to string

  17. 17

    Type mismatch: cannot convert from element type Object to Cookie

  18. 18

    Java - Type mismatch: cannot convert from element type Object to String

  19. 19

    Type mismatch: cannot convert from Object to Class object

  20. 20

    Java generics. Type mismatch: cannot convert from object to

  21. 21

    Cannot convert from Object to Int

  22. 22

    cannot convert from 'object' to 'string'

  23. 23

    C# Cannot convert from 'ref xxx' to 'ref object'

  24. 24

    Type mismatch: cannot convert from Set<Object> to Set<Long>

  25. 25

    Cannot convert from object to string

  26. 26

    Cannot convert from `Expression<Func<T1, T2>>` to `Expression<Func<object, object>>`

  27. 27

    Cannot convert from object to System.ValueType

  28. 28

    Cannot recurse over object[] because cannot convert object to object[]

  29. 29

    Type mismatch: cannot convert from element type Object to List

HotTag

Archive