.NET Forum / .NET Framework / Interop / April 2004
Marshalling error with System.Drawing.Color <==> OLE_COLOR parameter
|
|
Thread rating:  |
Peter Bromley - 14 Apr 2004 00:01 GMT Hi,
There appears to be a problem with marshalling a specific usage of a System.Drawing.Color reference parameter from an unmanaged caller.
I have a .NET control exposing an interface as (managed C++):
public __gc __interface IManagedUIElement { void ElemBackColor([Out] System::Drawing::Color color) ... }
__sealed __gc class MyControl public System::Windows::Forms::UserControl, public IManagedUIElement { ... }
My control is calling a native dll (passing a pointer to it's CCW). The native code then requests the IManagedUIElement interface and calls the method ElemBackColor.
The COM equivalent interface is (IDL):
interface IManagedUIElement : IUnknown { HRESULT ElemBackColor([out] OLE_COLOR* color); ... }
and the native code calls with:
OLE_COLOR color; mp->ElemBackColor(&color);
This doesn't work (in fact Visual Studio hangs when stepping in within the debugger and has to be killed with the Task Manager) as it appears that the CCW marshaller isn't correctly handling the method parameter.
According to MSDN, the marshaller marshals System.Drawing.Color to OLE_COLOR as one of a number of special cases. I have verified that this marshalling happens correctly for all managed to unmanaged calls and for [in] parameters of unmanaged to managed calls. The case that appears to be broken is [out] parameters (and by extension [out,retval] parameters and property gets).
It is also possible that the Type Library Exporter doesn't know about this special case as the exported type library doesn't mention OLE_COLOR at all - I had to roll my own IDL.
Here's hoping anyone can help me out with a workaround or confirmation.
Thanks,
 Signature If you wish to reply to me directly, my addres is spam proofed as:
pbromley at adi dot co dot nz
Or if you prefer - nospam@nowhere.com :-)
"Ying-Shen Yu[MSFT]" - 14 Apr 2004 08:27 GMT Hi Peter,
You may change the MC++ method like below: <code> void IManagedUIElement::ElemBackColor([In,Out] System::Drawing::Color __gc * c) { System::Diagnostics::Debug::WriteLine (c->ToString()); *c = Color::Orange; System::Diagnostics::Debug::WriteLine (c->ToString()); } </code>
Please feel free to reply this thread if you still have problem on this issue.
Best regards,
Ying-Shen Yu [MSFT] Microsoft Community Support Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights. This mail should not be replied directly, please remove the word "online" before sending mail.
Peter Bromley - 15 Apr 2004 03:54 GMT Ying-Shen Yu[MSFT] wrote:
> Hi Peter, > [quoted text clipped - 11 lines] > Please feel free to reply this thread if you still have problem on this > issue. Yes, this works for an out parameter. I see that the __gc* is the important difference here. This doesn't appears to be explicit mentioned on MSDN.
Can you help me work out the correct declaration for a __property member (ie [out,retval] on the COM side).
__property System::Drawing::Color ?? ElemBackColor(void)
Thanks,
 Signature If you wish to reply to me directly, my addres is spam proofed as:
pbromley at adi dot co dot nz
Or if you prefer - nospam@nowhere.com :-)
"Ying-Shen Yu[MSFT]" - 17 Apr 2004 03:40 GMT Hi Peter,
marshal the Color type to OLE_COLOR in return value is much harder than I thought, I need a little more time to look into it, please stay tuned. Thanks!
Best regards,
Ying-Shen Yu [MSFT] Microsoft Community Support Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights. This mail should not be replied directly, please remove the word "online" before sending mail.
"Ying-Shen Yu[MSFT]" - 21 Apr 2004 10:44 GMT Hi Peter,
I apologize for the long delay, I had fowarded this question to our developer team, one member said he will give me a reply, however it might take another few days. Is this an urgent issue? I think we already have a way to get the value in parameter. I'll update this issue as soon as I got the reply, thanks for your patience!
Best regards,
Ying-Shen Yu [MSFT] Microsoft Community Support Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights. This mail should not be replied directly, please remove the word "online" before sending mail.
Peter Bromley - 21 Apr 2004 23:06 GMT Thanks for your persistence.
No the issue is not urgent, as you say, there is a out parameter solution. I look forward, though, to the return value solution.
> I apologize for the long delay, > I had fowarded this question to our developer team, one member said he will > give me a reply, however it might take another few days. Is this an urgent > issue? I think we already have a way to get the value in parameter. > I'll update this issue as soon as I got the reply, thanks for your patience! "Ying-Shen Yu[MSFT]" - 23 Apr 2004 09:36 GMT Hi Peter,
I got the reply from the dev team, ideally the following MC++ code should work:
System::Drawing::Color __gc IManagedUIElement::get_Color() { return Color::Orange; }
however this is a bug in .NET v1.1 CLR that [out, retval] Colors is not marshalled correctly, Hopefully, this bug would be fixed in Whidbey release, for now the [out] parameter works ok you may use it as a workaround.
Thanks for your patience!
Best regards,
Ying-Shen Yu [MSFT] Microsoft Community Support Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights. This mail should not be replied directly, please remove the word "online" before sending mail.
Peter Bromley - 25 Apr 2004 22:37 GMT Well, you can't work around a bug in what is supposed to work :-(
No, I will work with the "out" solution for now.
Thanks again.
> I got the reply from the dev team, ideally the following MC++ code should > work: [quoted text clipped - 8 lines] > release, for now the [out] parameter works ok you may use it as a > workaround.
 Signature If you wish to reply to me directly, my addres is spam proofed as:
pbromley at adi dot co dot nz
Or if you prefer - nospam@nowhere.com :-)
Free MagazinesGet 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 ...
|
|
|