I have an unmanaged library which I want to use from a managed class. The interface of the function is:
GetProgress(short* value);
So I wrote in my managed class:
short val = 0;
GetProgress(&val);
I got the following error:
Error C2664: ‘GetProgress’ : cannot convert parameter 1 from ‘cli::interior_ptr’ in ‘short *’ with [ Type=short ]
I read this topic, so I changed my code into:
short val = 0;
pin_ptr<short*> pVal = &val;
GetProgress(pVal);
And in addition to the previous error I get
Error C2440: ‘initialisation’ : cannot convert from ‘short *’ to ‘cli::pin_ptr’ with [ Type=short * ]
How can I fix this?
That’s an interesting one.
The following code produces C2664 because
valcan only be a managed type:but if you declare a local variable first, it all works fine…
Not exactly the answer you were looking for, but I thought I’d include it since it’s a simple fix.