26.02.2015 Views

C#.Net Migration - A2Z Dotnet

C#.Net Migration - A2Z Dotnet

C#.Net Migration - A2Z Dotnet

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Using MarshalAs on parameters<br />

using System.Runtime.InteropServices;<br />

public class FooBarWrapper<br />

{<br />

// this routine wraps a native function declared as<br />

// void _stdcall DoIt(LPCWSTR s1, LPCSTR s2,<br />

// LPTSTR s3, BSTR s4);<br />

}<br />

[ DllImport("foobar.dll") ]<br />

public static extern void DoIt(<br />

[MarshalAs(UnmanagedType.LPWStr)] String s1,<br />

[MarshalAs(UnmanagedType.LPStr)] String s2,<br />

[MarshalAs(UnmanagedType.LPTStr)] String s3,<br />

[MarshalAs(UnmanagedType.BStr)] String s4<br />

);<br />

Controlling type<br />

transitions out of the<br />

runtime via MarshalAs<br />

attribute<br />

86

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!