2 // System.Runtime.InteropServices.Marshal Test Cases
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2004-2007 Novell, Inc (http://www.novell.com)
10 using NUnit.Framework;
13 using System.Reflection;
15 using System.Reflection.Emit;
17 using System.Runtime.InteropServices;
18 using System.Security;
21 namespace MonoTests.System.Runtime.InteropServices
24 public class MarshalTest
26 [StructLayout (LayoutKind.Sequential)]
31 public class ClsNoLayout {
35 [StructLayout (LayoutKind.Explicit)]
37 [FieldOffset (0)] public int field;
40 [StructLayout (LayoutKind.Sequential)]
41 struct StrSequential {
49 [StructLayout (LayoutKind.Explicit)]
51 [FieldOffset (0)] public int field;
55 public void SizeOf_Class_LayoutSequential ()
57 Marshal.SizeOf (typeof (ClsSequential));
61 public void SizeOf_Class_LayoutNotSet ()
64 Marshal.SizeOf (typeof (ClsNoLayout));
66 } catch (ArgumentException ex) {
67 // Type '...MarshalTest+ClsNoLayout' cannot be
68 // marshaled as an unmanaged structure; no
69 // meaningful size or offset can be computed
70 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
71 Assert.IsNull (ex.InnerException, "#3");
72 Assert.IsNotNull (ex.Message, "#4");
77 public void SizeOf_Class_LayoutExplicit ()
79 Marshal.SizeOf (typeof (ClsExplicit));
83 public void SizeOf_Struct_LayoutSequential ()
85 Marshal.SizeOf (typeof (StrSequential));
89 public void SizeOf_Struct_LayoutNotSet ()
91 Marshal.SizeOf (typeof (StrNoLayout));
95 public void SizeOf_Struct_LayoutExplicit ()
97 Marshal.SizeOf (typeof (StrExplicit));
101 public void SizeOf_Array ()
104 Marshal.SizeOf (typeof (string []));
106 } catch (ArgumentException ex) {
107 // Type 'System.String[]' cannot be marshaled
108 // as an unmanaged structure; no meaningful
109 // size or offset can be computed
110 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
111 Assert.IsNull (ex.InnerException, "#3");
112 Assert.IsNotNull (ex.Message, "#4");
117 public unsafe void Sizeof_Pointer ()
119 int size = Marshal.SizeOf (typeof (char*));
120 Assert.IsTrue (size == 4 || size == 8);
124 public void PtrToStringWithNull ()
126 Assert.IsNull (Marshal.PtrToStringAnsi (IntPtr.Zero), "A");
127 Assert.IsNull (Marshal.PtrToStringUni (IntPtr.Zero), "C");
131 public void PtrToStringAnsi_Ptr_Zero ()
134 Marshal.PtrToStringAnsi (IntPtr.Zero, 0);
136 } catch (ArgumentNullException ex) {
137 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
138 Assert.IsNull (ex.InnerException, "#3");
139 Assert.IsNotNull (ex.Message, "#4");
140 Assert.AreEqual ("ptr", ex.ParamName, "#5");
145 public void PtrToStringWithUni_Ptr_Zero ()
148 Marshal.PtrToStringUni (IntPtr.Zero, 0);
150 } catch (ArgumentNullException ex) {
151 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
152 Assert.IsNull (ex.InnerException, "#3");
153 Assert.IsNotNull (ex.Message, "#4");
154 Assert.AreEqual ("ptr", ex.ParamName, "#5");
159 public unsafe void UnsafeAddrOfPinnedArrayElement ()
161 short[] sarr = new short [5];
164 IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement (sarr, 2);
165 Assert.AreEqual (3, *(short*) ptr.ToPointer ());
169 public void AllocHGlobalZeroSize ()
171 IntPtr ptr = Marshal.AllocHGlobal (0);
172 Assert.IsTrue (ptr != IntPtr.Zero);
173 Marshal.FreeHGlobal (ptr);
177 public void AllocCoTaskMemZeroSize ()
179 IntPtr ptr = Marshal.AllocCoTaskMem (0);
180 Assert.IsTrue (ptr != IntPtr.Zero);
181 Marshal.FreeCoTaskMem (ptr);
188 public static char d;
193 public void OffsetOf_FieldName_Static ()
196 Marshal.OffsetOf (typeof (Foo), "b");
198 } catch (ArgumentException ex) {
199 // Field passed in is not a marshaled member of
200 // the type '...MarshalTest+Foo'
201 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
202 Assert.IsNull (ex.InnerException, "#3");
203 Assert.IsNotNull (ex.Message, "#4");
204 Assert.AreEqual ("fieldName", ex.ParamName, "#5");
209 public void GetHINSTANCE ()
212 Assert.Ignore ("GetHINSTANCE only applies to Windows.");
216 StringBuilder fileName;
218 fileName = new StringBuilder (255);
219 a = Assembly.GetExecutingAssembly ();
220 hinstance = Marshal.GetHINSTANCE (a.GetModules () [0]);
221 Assert.IsTrue (GetModuleFileName (hinstance, fileName,
222 fileName.Capacity) > 0, "#A1");
223 Assert.AreEqual (a.Location, fileName.ToString (), "#A2");
226 a = typeof (int).Assembly;
227 hinstance = Marshal.GetHINSTANCE (a.GetModules () [0]);
228 Assert.IsTrue (GetModuleFileName (hinstance, fileName,
229 fileName.Capacity) > 0, "#B1");
230 Assert.IsTrue (File.Exists (fileName.ToString ()), "#B3");
231 Assert.AreEqual ("mscorlib.dll", Path.GetFileName (fileName.ToString ()), "#B4");
235 public void GetHINSTANCE_Module_Dynamic ()
237 AssemblyName aname = new AssemblyName ();
240 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
241 aname, AssemblyBuilderAccess.Save,
242 Path.GetTempPath ());
243 ModuleBuilder mb = ab.DefineDynamicModule ("foo.dll", false);
245 IntPtr hinstance = Marshal.GetHINSTANCE (mb);
246 Assert.AreEqual (-1, hinstance.ToInt32 ());
250 public void GetHINSTANCE_Module_Null ()
253 Marshal.GetHINSTANCE ((Module) null);
255 } catch (ArgumentNullException ex) {
256 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
257 Assert.IsNull (ex.InnerException, "#3");
258 Assert.IsNotNull (ex.Message, "#4");
259 Assert.AreEqual ("m", ex.ParamName, "#5");
263 [Test] // bug #319009
264 public void StringToHGlobalUni ()
266 IntPtr handle = Marshal.StringToHGlobalUni ("unicode data");
267 string s = Marshal.PtrToStringUni (handle);
268 Assert.AreEqual (12, s.Length, "#1");
270 handle = Marshal.StringToHGlobalUni ("unicode data string");
271 s = Marshal.PtrToStringUni (handle);
272 Assert.AreEqual (19, s.Length, "#2");
276 public void ReadIntByte ()
278 IntPtr ptr = Marshal.AllocHGlobal (4);
280 Marshal.WriteByte (ptr, 0, 0x1);
281 Marshal.WriteByte (ptr, 1, 0x2);
282 Assert.AreEqual (0x1, Marshal.ReadByte (ptr));
283 Assert.AreEqual (0x1, Marshal.ReadByte (ptr, 0));
284 Assert.AreEqual (0x2, Marshal.ReadByte (ptr, 1));
286 Marshal.FreeHGlobal (ptr);
291 public void ReadInt16 ()
293 IntPtr ptr = Marshal.AllocHGlobal (64);
295 Marshal.WriteInt16 (ptr, 0, 0x1234);
296 Marshal.WriteInt16 (ptr, 2, 0x4567);
297 Marshal.WriteInt16 (ptr, 5, 0x4567);
298 Assert.AreEqual (0x1234, Marshal.ReadInt16 (ptr));
299 Assert.AreEqual (0x1234, Marshal.ReadInt16 (ptr, 0));
300 Assert.AreEqual (0x4567, Marshal.ReadInt16 (ptr, 2));
302 Assert.AreEqual (0x4567, Marshal.ReadInt16 ((ptr + 5)));
304 Assert.AreEqual (0x4567, Marshal.ReadInt16 (ptr, 5));
306 Marshal.FreeHGlobal (ptr);
311 public void ReadInt32 ()
313 IntPtr ptr = Marshal.AllocHGlobal (64);
315 Marshal.WriteInt32 (ptr, 0, 0x12345678);
316 Marshal.WriteInt32 (ptr, 4, 0x77654321);
317 Marshal.WriteInt32 (ptr, 10, 0x77654321);
318 Assert.AreEqual (0x12345678, Marshal.ReadInt32 (ptr));
319 Assert.AreEqual (0x12345678, Marshal.ReadInt32 (ptr, 0));
320 Assert.AreEqual (0x77654321, Marshal.ReadInt32 (ptr, 4));
322 Assert.AreEqual (0x77654321, Marshal.ReadInt32 ((ptr + 10)));
324 Assert.AreEqual (0x77654321, Marshal.ReadInt32 (ptr, 10));
326 Marshal.FreeHGlobal (ptr);
331 public void ReadInt32_Endian ()
333 IntPtr ptr = Marshal.AllocHGlobal (4);
335 Marshal.WriteByte (ptr, 0, 0x01);
336 Marshal.WriteByte (ptr, 1, 0x02);
337 Marshal.WriteByte (ptr, 2, 0x03);
338 Marshal.WriteByte (ptr, 3, 0x04);
339 // Marshal MUST use the native CPU data
340 if (BitConverter.IsLittleEndian){
341 Assert.AreEqual (0x04030201, Marshal.ReadInt32 (ptr), "ReadInt32");
343 Assert.AreEqual (0x01020304, Marshal.ReadInt32 (ptr), "ReadInt32");
346 Marshal.FreeHGlobal (ptr);
351 public void ReadInt64 ()
353 IntPtr ptr = Marshal.AllocHGlobal (16);
355 Marshal.WriteInt64 (ptr, 0, 0x12345678ABCDEFL);
356 Marshal.WriteInt64 (ptr, 8, 0x87654321ABCDEFL);
357 Assert.AreEqual (0x12345678ABCDEFL, Marshal.ReadInt64 (ptr));
358 Assert.AreEqual (0x12345678ABCDEFL, Marshal.ReadInt64 (ptr, 0));
359 Assert.AreEqual (0x87654321ABCDEFL, Marshal.ReadInt64 (ptr, 8));
361 Marshal.FreeHGlobal (ptr);
366 [Category ("MobileNotWorking")]
367 public void BSTR_Roundtrip ()
370 IntPtr ptr = Marshal.StringToBSTR (s);
371 string s2 = Marshal.PtrToStringBSTR (ptr);
372 Assert.AreEqual (s, s2, "string");
376 [Category ("MobileNotWorking")]
377 public void StringToBSTRWithNullValues ()
380 string s = String.Empty.PadLeft (size, '\0');
381 Assert.AreEqual (size, s.Length, "Length-1");
383 IntPtr ptr = Marshal.StringToBSTR (s);
385 for (int i = 0; i < size; i += 4)
386 Marshal.WriteInt32 (ptr, i, 0);
388 string s2 = Marshal.PtrToStringBSTR (ptr);
389 Assert.AreEqual (128, s2.Length, "Length-2");
391 Marshal.FreeBSTR (ptr);
396 public void StringToHGlobalAnsiWithNullValues ()
399 string s = String.Empty.PadLeft (size, '\0');
400 Assert.AreEqual (size, s.Length, "Length-1");
402 IntPtr ptr = Marshal.StringToHGlobalAnsi (s);
404 for (int i = 0; i < size; i += 4)
405 Marshal.WriteInt32 (ptr, i, 0);
407 string s2 = Marshal.PtrToStringAnsi (ptr);
408 Assert.AreEqual (0, s2.Length, "Length-2");
410 Marshal.FreeHGlobal (ptr);
415 public void StringToHGlobalAutoWithNullValues ()
418 string s = String.Empty.PadLeft (size, '\0');
419 Assert.AreEqual (size, s.Length, "Length-1");
421 IntPtr ptr = Marshal.StringToHGlobalAuto (s);
423 for (int i = 0; i < size; i += 4)
424 Marshal.WriteInt32 (ptr, i, 0);
426 string s2 = Marshal.PtrToStringAuto (ptr);
427 Assert.AreEqual (0, s2.Length, "Length-2");
429 Marshal.FreeHGlobal (ptr);
434 public void StringToHGlobalUniWithNullValues ()
437 string s = String.Empty.PadLeft (size, '\0');
438 Assert.AreEqual (size, s.Length, "Length-1");
440 IntPtr ptr = Marshal.StringToHGlobalUni (s);
442 for (int i = 0; i < size; i += 4)
443 Marshal.WriteInt32 (ptr, i, 0);
445 string s2 = Marshal.PtrToStringUni (ptr);
446 Assert.AreEqual (0, s2.Length, "Length-2");
448 Marshal.FreeHGlobal (ptr);
453 public void StringToCoTaskMemAnsiWithNullValues ()
456 string s = String.Empty.PadLeft (size, '\0');
457 Assert.AreEqual (size, s.Length, "Length-1");
459 IntPtr ptr = Marshal.StringToCoTaskMemAnsi (s);
461 for (int i = 0; i < size; i += 4)
462 Marshal.WriteInt32 (ptr, i, 0);
464 string s2 = Marshal.PtrToStringAnsi (ptr);
465 Assert.AreEqual (0, s2.Length, "Length-2");
467 Marshal.FreeCoTaskMem (ptr);
472 public void StringToCoTaskMemAutoWithNullValues ()
475 string s = String.Empty.PadLeft (size, '\0');
476 Assert.AreEqual (size, s.Length, "Length-1");
478 IntPtr ptr = Marshal.StringToCoTaskMemAuto (s);
480 for (int i = 0; i < size; i += 4)
481 Marshal.WriteInt32 (ptr, i, 0);
483 string s2 = Marshal.PtrToStringAuto (ptr);
484 Assert.AreEqual (0, s2.Length, "Length-2");
486 Marshal.FreeCoTaskMem (ptr);
491 public void StringToCoTaskMemUniWithNullValues ()
494 string s = String.Empty.PadLeft (size, '\0');
495 Assert.AreEqual (size, s.Length, "Length-1");
497 IntPtr ptr = Marshal.StringToCoTaskMemUni (s);
499 for (int i = 0; i < size; i += 4)
500 Marshal.WriteInt32 (ptr, i, 0);
502 string s2 = Marshal.PtrToStringUni (ptr);
503 Assert.AreEqual (0, s2.Length, "Length-2");
505 Marshal.FreeCoTaskMem (ptr);
508 private const string NotSupported = "Not supported before Windows 2000 Service Pack 3";
509 private static char[] PlainText = new char[] { 'a', 'b', 'c' };
510 private static byte[] AsciiPlainText = new byte[] { (byte) 'a', (byte) 'b', (byte) 'c' };
512 private unsafe SecureString GetSecureString ()
514 fixed (char* p = &PlainText[0]) {
515 return new SecureString (p, PlainText.Length);
520 public void SecureStringToBSTR_Null ()
523 Marshal.SecureStringToBSTR (null);
525 } catch (ArgumentNullException ex) {
526 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
527 Assert.IsNull (ex.InnerException, "#3");
528 Assert.IsNotNull (ex.Message, "#4");
529 Assert.AreEqual ("s", ex.ParamName, "#5");
534 public void SecureStringToBSTR ()
537 SecureString ss = GetSecureString ();
538 IntPtr p = Marshal.SecureStringToBSTR (ss);
540 char[] decrypted = new char[ss.Length];
541 Marshal.Copy (p, decrypted, 0, decrypted.Length);
542 Assert.AreEqual (PlainText, decrypted, "Decrypted");
544 Marshal.ZeroFreeBSTR (p);
545 } catch (NotSupportedException) {
546 Assert.Ignore (NotSupported);
551 public void SecureStringToCoTaskMemAnsi_Null ()
554 Marshal.SecureStringToCoTaskMemAnsi (null);
556 } catch (ArgumentNullException ex) {
557 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
558 Assert.IsNull (ex.InnerException, "#3");
559 Assert.IsNotNull (ex.Message, "#4");
560 Assert.AreEqual ("s", ex.ParamName, "#5");
565 public void SecureStringToCoTaskMemAnsi ()
568 SecureString ss = GetSecureString ();
569 IntPtr p = Marshal.SecureStringToCoTaskMemAnsi (ss);
571 byte[] decrypted = new byte[ss.Length];
572 Marshal.Copy (p, decrypted, 0, decrypted.Length);
573 Assert.AreEqual (AsciiPlainText, decrypted, "Decrypted");
575 Marshal.ZeroFreeCoTaskMemAnsi (p);
576 } catch (NotSupportedException) {
577 Assert.Ignore (NotSupported);
582 public void SecureStringToCoTaskMemUnicode_Null ()
585 Marshal.SecureStringToCoTaskMemUnicode (null);
587 } catch (ArgumentNullException ex) {
588 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
589 Assert.IsNull (ex.InnerException, "#3");
590 Assert.IsNotNull (ex.Message, "#4");
591 Assert.AreEqual ("s", ex.ParamName, "#5");
596 public void SecureStringToCoTaskMemUnicode ()
599 SecureString ss = GetSecureString ();
600 IntPtr p = Marshal.SecureStringToCoTaskMemUnicode (ss);
602 char[] decrypted = new char[ss.Length];
603 Marshal.Copy (p, decrypted, 0, decrypted.Length);
604 Assert.AreEqual (PlainText, decrypted, "Decrypted");
606 Marshal.ZeroFreeCoTaskMemUnicode (p);
607 } catch (NotSupportedException) {
608 Assert.Ignore (NotSupported);
613 public void SecureStringToGlobalAllocAnsi_Null ()
616 Marshal.SecureStringToGlobalAllocAnsi (null);
618 } catch (ArgumentNullException ex) {
619 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
620 Assert.IsNull (ex.InnerException, "#3");
621 Assert.IsNotNull (ex.Message, "#4");
622 Assert.AreEqual ("s", ex.ParamName, "#5");
627 public void SecureStringToGlobalAllocAnsi ()
630 SecureString ss = GetSecureString ();
631 IntPtr p = Marshal.SecureStringToGlobalAllocAnsi (ss);
633 byte[] decrypted = new byte[ss.Length];
634 Marshal.Copy (p, decrypted, 0, decrypted.Length);
635 Assert.AreEqual (AsciiPlainText, decrypted, "Decrypted");
637 Marshal.ZeroFreeGlobalAllocAnsi (p);
638 } catch (NotSupportedException) {
639 Assert.Ignore (NotSupported);
644 public void SecureStringToGlobalAllocUnicode_Null ()
647 Marshal.SecureStringToGlobalAllocUnicode (null);
649 } catch (ArgumentNullException ex) {
650 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
651 Assert.IsNull (ex.InnerException, "#3");
652 Assert.IsNotNull (ex.Message, "#4");
653 Assert.AreEqual ("s", ex.ParamName, "#5");
658 public void SecureStringToGlobalAllocUnicode ()
661 SecureString ss = GetSecureString ();
662 IntPtr p = Marshal.SecureStringToGlobalAllocUnicode (ss);
664 char[] decrypted = new char[ss.Length];
665 Marshal.Copy (p, decrypted, 0, decrypted.Length);
666 Assert.AreEqual (PlainText, decrypted, "Decrypted");
668 Marshal.ZeroFreeGlobalAllocUnicode (p);
669 } catch (NotSupportedException) {
670 Assert.Ignore (NotSupported);
676 public void TestGetComSlotForMethodInfo ()
678 Assert.AreEqual (7, Marshal.GetComSlotForMethodInfo(typeof(ITestDefault).GetMethod("DoNothing")));
679 Assert.AreEqual (7, Marshal.GetComSlotForMethodInfo(typeof(ITestDual).GetMethod("DoNothing")));
680 Assert.AreEqual (7, Marshal.GetComSlotForMethodInfo (typeof(ITestDefault).GetMethod ("DoNothing")));
681 Assert.AreEqual (3, Marshal.GetComSlotForMethodInfo (typeof(ITestUnknown).GetMethod ("DoNothing")));
683 for (int i = 0; i < 10; i++)
684 Assert.AreEqual (7+i, Marshal.GetComSlotForMethodInfo(typeof(ITestInterface).GetMethod ("Method"+i.ToString())));
688 public void TestGetComSlotForMethod_Method_Null ()
691 Marshal.GetComSlotForMethodInfo (null);
693 } catch (ArgumentNullException ex) {
694 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
695 Assert.IsNull (ex.InnerException, "#3");
696 Assert.IsNotNull (ex.Message, "#4");
697 Assert.AreEqual ("m", ex.ParamName, "#5");
702 public void TestGetComSlotForMethodInfo_Method_NotOnInterface ()
704 MethodInfo m = typeof(TestCoClass).GetMethod ("DoNothing");
706 Marshal.GetComSlotForMethodInfo (m);
708 } catch (ArgumentException ex) {
709 // The MemberInfo must be an interface method
710 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
711 Assert.IsNull (ex.InnerException, "#3");
712 Assert.IsNotNull (ex.Message, "#4");
713 Assert.AreEqual ("m", ex.ParamName, "#5");
718 public void TestPtrToStringAuto ()
720 string input = Guid.NewGuid ().ToString ();
726 if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
728 ptr = Marshal.StringToHGlobalAuto (input);
729 output = Marshal.PtrToStringUni (ptr);
730 output2 = Marshal.PtrToStringUni (ptr, len);
733 ptr = Marshal.StringToHGlobalAuto (input);
734 output = Marshal.PtrToStringAnsi (ptr);
735 output2 = Marshal.PtrToStringAnsi (ptr, len);
739 Assert.AreEqual (input, output, "#1");
740 Assert.AreEqual (input.Substring (0, len), output2, "#2");
742 Marshal.FreeHGlobal (ptr);
747 public void TestGenerateProgIdForType()
751 output = Marshal.GenerateProgIdForType(typeof(TestCoClass));
752 Assert.AreEqual ("MonoTests.System.Runtime.InteropServices.TestCoClass", output, "#1");
754 output = Marshal.GenerateProgIdForType(typeof(TestCoClassWithProgId));
755 Assert.AreEqual ("CoClassWithProgId", output, "#2");
759 public void TestGlobalAlloc ()
761 IntPtr mem = Marshal.AllocHGlobal (100);
762 mem = Marshal.ReAllocHGlobal (mem, (IntPtr) 1000000);
763 Marshal.FreeHGlobal (mem);
767 public void FreeHGlobal ()
769 // clear user doubts on assistly #6749
770 for (int i = 0; i < 1024; i++) {
771 IntPtr p = Marshal.AllocHGlobal (1024 * 1024);
772 Assert.AreNotEqual (IntPtr.Zero, p, i.ToString ());
773 Marshal.FreeHGlobal (p);
777 [StructLayout (LayoutKind.Sequential)]
778 public struct SimpleStruct2 {
784 public void PtrToStructureNull ()
786 Assert.IsNull (Marshal.PtrToStructure (IntPtr.Zero, typeof (SimpleStruct2)));
790 public void TestGetExceptionForHR ()
792 const int E_OUTOFMEMORY = unchecked ((int) 0x8007000E);
793 const int E_INVALIDARG = unchecked ((int) 0X80070057);
795 Exception ex = Marshal.GetExceptionForHR (E_OUTOFMEMORY);
796 Assert.AreEqual (typeof (OutOfMemoryException), ex.GetType (), "E_OUTOFMEMORY");
798 ex = Marshal.GetExceptionForHR (E_INVALIDARG);
799 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "E_INVALIDARG");
803 int p = (int) Environment.OSVersion.Platform;
804 return ((p == 4) || (p == 128) || (p == 6));
808 [DllImport ("kernel32.dll", SetLastError = true)]
810 static extern uint GetModuleFileName (
814 StringBuilder lpFilename,
816 [MarshalAs (UnmanagedType.U4)]
822 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
823 interface ITestDefault
829 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
830 [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
831 interface ITestDispatch
837 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
838 [InterfaceType(ComInterfaceType.InterfaceIsDual)]
845 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
846 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
847 interface ITestUnknown
853 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
854 interface ITestInterface
868 public class TestCoClass : ITestDispatch
870 public void DoNothing ()
875 [ProgId("CoClassWithProgId")]
876 public class TestCoClassWithProgId : ITestDispatch
878 public void DoNothing ()