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);
180 public static char d;
185 public void OffsetOf_FieldName_Static ()
188 Marshal.OffsetOf (typeof (Foo), "b");
190 } catch (ArgumentException ex) {
191 // Field passed in is not a marshaled member of
192 // the type '...MarshalTest+Foo'
193 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
194 Assert.IsNull (ex.InnerException, "#3");
195 Assert.IsNotNull (ex.Message, "#4");
196 Assert.AreEqual ("fieldName", ex.ParamName, "#5");
201 public void GetHINSTANCE ()
204 Assert.Ignore ("GetHINSTANCE only applies to Windows.");
208 StringBuilder fileName;
210 fileName = new StringBuilder (255);
211 a = Assembly.GetExecutingAssembly ();
212 hinstance = Marshal.GetHINSTANCE (a.GetModules () [0]);
213 Assert.IsTrue (GetModuleFileName (hinstance, fileName,
214 fileName.Capacity) > 0, "#A1");
215 Assert.AreEqual (a.Location, fileName.ToString (), "#A2");
218 a = typeof (int).Assembly;
219 hinstance = Marshal.GetHINSTANCE (a.GetModules () [0]);
220 Assert.IsTrue (GetModuleFileName (hinstance, fileName,
221 fileName.Capacity) > 0, "#B1");
222 Assert.IsTrue (File.Exists (fileName.ToString ()), "#B3");
223 Assert.AreEqual ("mscorlib.dll", Path.GetFileName (fileName.ToString ()), "#B4");
227 public void GetHINSTANCE_Module_Dynamic ()
229 AssemblyName aname = new AssemblyName ();
232 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
233 aname, AssemblyBuilderAccess.Save,
234 Path.GetTempPath ());
235 ModuleBuilder mb = ab.DefineDynamicModule ("foo.dll", false);
237 IntPtr hinstance = Marshal.GetHINSTANCE (mb);
238 Assert.AreEqual (-1, hinstance.ToInt32 ());
242 public void GetHINSTANCE_Module_Null ()
245 Marshal.GetHINSTANCE ((Module) null);
247 } catch (ArgumentNullException ex) {
248 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
249 Assert.IsNull (ex.InnerException, "#3");
250 Assert.IsNotNull (ex.Message, "#4");
251 Assert.AreEqual ("m", ex.ParamName, "#5");
255 [Test] // bug #319009
256 public void StringToHGlobalUni ()
258 IntPtr handle = Marshal.StringToHGlobalUni ("unicode data");
259 string s = Marshal.PtrToStringUni (handle);
260 Assert.AreEqual (12, s.Length, "#1");
262 handle = Marshal.StringToHGlobalUni ("unicode data string");
263 s = Marshal.PtrToStringUni (handle);
264 Assert.AreEqual (19, s.Length, "#2");
268 public void ReadIntByte ()
270 IntPtr ptr = Marshal.AllocHGlobal (4);
272 Marshal.WriteByte (ptr, 0, 0x1);
273 Marshal.WriteByte (ptr, 1, 0x2);
274 Assert.AreEqual (0x1, Marshal.ReadByte (ptr));
275 Assert.AreEqual (0x1, Marshal.ReadByte (ptr, 0));
276 Assert.AreEqual (0x2, Marshal.ReadByte (ptr, 1));
278 Marshal.FreeHGlobal (ptr);
283 public void ReadInt16 ()
285 IntPtr ptr = Marshal.AllocHGlobal (64);
287 Marshal.WriteInt16 (ptr, 0, 0x1234);
288 Marshal.WriteInt16 (ptr, 2, 0x4567);
289 Marshal.WriteInt16 (ptr, 5, 0x4567);
290 Assert.AreEqual (0x1234, Marshal.ReadInt16 (ptr));
291 Assert.AreEqual (0x1234, Marshal.ReadInt16 (ptr, 0));
292 Assert.AreEqual (0x4567, Marshal.ReadInt16 (ptr, 2));
294 Assert.AreEqual (0x4567, Marshal.ReadInt16 ((ptr + 5)));
296 Assert.AreEqual (0x4567, Marshal.ReadInt16 (ptr, 5));
298 Marshal.FreeHGlobal (ptr);
303 public void ReadInt32 ()
305 IntPtr ptr = Marshal.AllocHGlobal (64);
307 Marshal.WriteInt32 (ptr, 0, 0x12345678);
308 Marshal.WriteInt32 (ptr, 4, 0x77654321);
309 Marshal.WriteInt32 (ptr, 10, 0x77654321);
310 Assert.AreEqual (0x12345678, Marshal.ReadInt32 (ptr));
311 Assert.AreEqual (0x12345678, Marshal.ReadInt32 (ptr, 0));
312 Assert.AreEqual (0x77654321, Marshal.ReadInt32 (ptr, 4));
314 Assert.AreEqual (0x77654321, Marshal.ReadInt32 ((ptr + 10)));
316 Assert.AreEqual (0x77654321, Marshal.ReadInt32 (ptr, 10));
318 Marshal.FreeHGlobal (ptr);
323 public void ReadInt32_Endian ()
325 IntPtr ptr = Marshal.AllocHGlobal (4);
327 Marshal.WriteByte (ptr, 0, 0x01);
328 Marshal.WriteByte (ptr, 1, 0x02);
329 Marshal.WriteByte (ptr, 2, 0x03);
330 Marshal.WriteByte (ptr, 3, 0x04);
331 // Marshal MUST use the native CPU data
332 if (BitConverter.IsLittleEndian){
333 Assert.AreEqual (0x04030201, Marshal.ReadInt32 (ptr), "ReadInt32");
335 Assert.AreEqual (0x01020304, Marshal.ReadInt32 (ptr), "ReadInt32");
338 Marshal.FreeHGlobal (ptr);
343 public void ReadInt64 ()
345 IntPtr ptr = Marshal.AllocHGlobal (16);
347 Marshal.WriteInt64 (ptr, 0, 0x12345678ABCDEFL);
348 Marshal.WriteInt64 (ptr, 8, 0x87654321ABCDEFL);
349 Assert.AreEqual (0x12345678ABCDEFL, Marshal.ReadInt64 (ptr));
350 Assert.AreEqual (0x12345678ABCDEFL, Marshal.ReadInt64 (ptr, 0));
351 Assert.AreEqual (0x87654321ABCDEFL, Marshal.ReadInt64 (ptr, 8));
353 Marshal.FreeHGlobal (ptr);
358 [Category ("MobileNotWorking")]
359 public void BSTR_Roundtrip ()
362 IntPtr ptr = Marshal.StringToBSTR (s);
363 string s2 = Marshal.PtrToStringBSTR (ptr);
364 Assert.AreEqual (s, s2, "string");
368 [Category ("MobileNotWorking")]
369 public void StringToBSTRWithNullValues ()
372 string s = String.Empty.PadLeft (size, '\0');
373 Assert.AreEqual (size, s.Length, "Length-1");
375 IntPtr ptr = Marshal.StringToBSTR (s);
377 for (int i = 0; i < size; i += 4)
378 Marshal.WriteInt32 (ptr, i, 0);
380 string s2 = Marshal.PtrToStringBSTR (ptr);
381 Assert.AreEqual (128, s2.Length, "Length-2");
383 Marshal.FreeBSTR (ptr);
388 public void StringToHGlobalAnsiWithNullValues ()
391 string s = String.Empty.PadLeft (size, '\0');
392 Assert.AreEqual (size, s.Length, "Length-1");
394 IntPtr ptr = Marshal.StringToHGlobalAnsi (s);
396 for (int i = 0; i < size; i += 4)
397 Marshal.WriteInt32 (ptr, i, 0);
399 string s2 = Marshal.PtrToStringAnsi (ptr);
400 Assert.AreEqual (0, s2.Length, "Length-2");
402 Marshal.FreeHGlobal (ptr);
407 public void StringToHGlobalAutoWithNullValues ()
410 string s = String.Empty.PadLeft (size, '\0');
411 Assert.AreEqual (size, s.Length, "Length-1");
413 IntPtr ptr = Marshal.StringToHGlobalAuto (s);
415 for (int i = 0; i < size; i += 4)
416 Marshal.WriteInt32 (ptr, i, 0);
418 string s2 = Marshal.PtrToStringAuto (ptr);
419 Assert.AreEqual (0, s2.Length, "Length-2");
421 Marshal.FreeHGlobal (ptr);
426 public void StringToHGlobalUniWithNullValues ()
429 string s = String.Empty.PadLeft (size, '\0');
430 Assert.AreEqual (size, s.Length, "Length-1");
432 IntPtr ptr = Marshal.StringToHGlobalUni (s);
434 for (int i = 0; i < size; i += 4)
435 Marshal.WriteInt32 (ptr, i, 0);
437 string s2 = Marshal.PtrToStringUni (ptr);
438 Assert.AreEqual (0, s2.Length, "Length-2");
440 Marshal.FreeHGlobal (ptr);
445 public void StringToCoTaskMemAnsiWithNullValues ()
448 string s = String.Empty.PadLeft (size, '\0');
449 Assert.AreEqual (size, s.Length, "Length-1");
451 IntPtr ptr = Marshal.StringToCoTaskMemAnsi (s);
453 for (int i = 0; i < size; i += 4)
454 Marshal.WriteInt32 (ptr, i, 0);
456 string s2 = Marshal.PtrToStringAnsi (ptr);
457 Assert.AreEqual (0, s2.Length, "Length-2");
459 Marshal.FreeCoTaskMem (ptr);
464 public void StringToCoTaskMemAutoWithNullValues ()
467 string s = String.Empty.PadLeft (size, '\0');
468 Assert.AreEqual (size, s.Length, "Length-1");
470 IntPtr ptr = Marshal.StringToCoTaskMemAuto (s);
472 for (int i = 0; i < size; i += 4)
473 Marshal.WriteInt32 (ptr, i, 0);
475 string s2 = Marshal.PtrToStringAuto (ptr);
476 Assert.AreEqual (0, s2.Length, "Length-2");
478 Marshal.FreeCoTaskMem (ptr);
483 public void StringToCoTaskMemUniWithNullValues ()
486 string s = String.Empty.PadLeft (size, '\0');
487 Assert.AreEqual (size, s.Length, "Length-1");
489 IntPtr ptr = Marshal.StringToCoTaskMemUni (s);
491 for (int i = 0; i < size; i += 4)
492 Marshal.WriteInt32 (ptr, i, 0);
494 string s2 = Marshal.PtrToStringUni (ptr);
495 Assert.AreEqual (0, s2.Length, "Length-2");
497 Marshal.FreeCoTaskMem (ptr);
500 private const string NotSupported = "Not supported before Windows 2000 Service Pack 3";
501 private static char[] PlainText = new char[] { 'a', 'b', 'c' };
502 private static byte[] AsciiPlainText = new byte[] { (byte) 'a', (byte) 'b', (byte) 'c' };
504 private unsafe SecureString GetSecureString ()
506 fixed (char* p = &PlainText[0]) {
507 return new SecureString (p, PlainText.Length);
512 public void SecureStringToBSTR_Null ()
515 Marshal.SecureStringToBSTR (null);
517 } catch (ArgumentNullException ex) {
518 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
519 Assert.IsNull (ex.InnerException, "#3");
520 Assert.IsNotNull (ex.Message, "#4");
521 Assert.AreEqual ("s", ex.ParamName, "#5");
526 public void SecureStringToBSTR ()
529 SecureString ss = GetSecureString ();
530 IntPtr p = Marshal.SecureStringToBSTR (ss);
532 char[] decrypted = new char[ss.Length];
533 Marshal.Copy (p, decrypted, 0, decrypted.Length);
534 Assert.AreEqual (PlainText, decrypted, "Decrypted");
536 Marshal.ZeroFreeBSTR (p);
537 } catch (NotSupportedException) {
538 Assert.Ignore (NotSupported);
543 public void SecureStringToCoTaskMemAnsi_Null ()
546 Marshal.SecureStringToCoTaskMemAnsi (null);
548 } catch (ArgumentNullException ex) {
549 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
550 Assert.IsNull (ex.InnerException, "#3");
551 Assert.IsNotNull (ex.Message, "#4");
552 Assert.AreEqual ("s", ex.ParamName, "#5");
557 public void SecureStringToCoTaskMemAnsi ()
560 SecureString ss = GetSecureString ();
561 IntPtr p = Marshal.SecureStringToCoTaskMemAnsi (ss);
563 byte[] decrypted = new byte[ss.Length];
564 Marshal.Copy (p, decrypted, 0, decrypted.Length);
565 Assert.AreEqual (AsciiPlainText, decrypted, "Decrypted");
567 Marshal.ZeroFreeCoTaskMemAnsi (p);
568 } catch (NotSupportedException) {
569 Assert.Ignore (NotSupported);
574 public void SecureStringToCoTaskMemUnicode_Null ()
577 Marshal.SecureStringToCoTaskMemUnicode (null);
579 } catch (ArgumentNullException ex) {
580 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
581 Assert.IsNull (ex.InnerException, "#3");
582 Assert.IsNotNull (ex.Message, "#4");
583 Assert.AreEqual ("s", ex.ParamName, "#5");
588 public void SecureStringToCoTaskMemUnicode ()
591 SecureString ss = GetSecureString ();
592 IntPtr p = Marshal.SecureStringToCoTaskMemUnicode (ss);
594 char[] decrypted = new char[ss.Length];
595 Marshal.Copy (p, decrypted, 0, decrypted.Length);
596 Assert.AreEqual (PlainText, decrypted, "Decrypted");
598 Marshal.ZeroFreeCoTaskMemUnicode (p);
599 } catch (NotSupportedException) {
600 Assert.Ignore (NotSupported);
605 public void SecureStringToGlobalAllocAnsi_Null ()
608 Marshal.SecureStringToGlobalAllocAnsi (null);
610 } catch (ArgumentNullException ex) {
611 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
612 Assert.IsNull (ex.InnerException, "#3");
613 Assert.IsNotNull (ex.Message, "#4");
614 Assert.AreEqual ("s", ex.ParamName, "#5");
619 public void SecureStringToGlobalAllocAnsi ()
622 SecureString ss = GetSecureString ();
623 IntPtr p = Marshal.SecureStringToGlobalAllocAnsi (ss);
625 byte[] decrypted = new byte[ss.Length];
626 Marshal.Copy (p, decrypted, 0, decrypted.Length);
627 Assert.AreEqual (AsciiPlainText, decrypted, "Decrypted");
629 Marshal.ZeroFreeGlobalAllocAnsi (p);
630 } catch (NotSupportedException) {
631 Assert.Ignore (NotSupported);
636 public void SecureStringToGlobalAllocUnicode_Null ()
639 Marshal.SecureStringToGlobalAllocUnicode (null);
641 } catch (ArgumentNullException ex) {
642 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
643 Assert.IsNull (ex.InnerException, "#3");
644 Assert.IsNotNull (ex.Message, "#4");
645 Assert.AreEqual ("s", ex.ParamName, "#5");
650 public void SecureStringToGlobalAllocUnicode ()
653 SecureString ss = GetSecureString ();
654 IntPtr p = Marshal.SecureStringToGlobalAllocUnicode (ss);
656 char[] decrypted = new char[ss.Length];
657 Marshal.Copy (p, decrypted, 0, decrypted.Length);
658 Assert.AreEqual (PlainText, decrypted, "Decrypted");
660 Marshal.ZeroFreeGlobalAllocUnicode (p);
661 } catch (NotSupportedException) {
662 Assert.Ignore (NotSupported);
668 public void TestGetComSlotForMethodInfo ()
670 Assert.AreEqual (7, Marshal.GetComSlotForMethodInfo(typeof(ITestDefault).GetMethod("DoNothing")));
671 Assert.AreEqual (7, Marshal.GetComSlotForMethodInfo(typeof(ITestDual).GetMethod("DoNothing")));
672 Assert.AreEqual (7, Marshal.GetComSlotForMethodInfo (typeof(ITestDefault).GetMethod ("DoNothing")));
673 Assert.AreEqual (3, Marshal.GetComSlotForMethodInfo (typeof(ITestUnknown).GetMethod ("DoNothing")));
675 for (int i = 0; i < 10; i++)
676 Assert.AreEqual (7+i, Marshal.GetComSlotForMethodInfo(typeof(ITestInterface).GetMethod ("Method"+i.ToString())));
680 public void TestGetComSlotForMethod_Method_Null ()
683 Marshal.GetComSlotForMethodInfo (null);
685 } catch (ArgumentNullException ex) {
686 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
687 Assert.IsNull (ex.InnerException, "#3");
688 Assert.IsNotNull (ex.Message, "#4");
689 Assert.AreEqual ("m", ex.ParamName, "#5");
694 public void TestGetComSlotForMethodInfo_Method_NotOnInterface ()
696 MethodInfo m = typeof(TestCoClass).GetMethod ("DoNothing");
698 Marshal.GetComSlotForMethodInfo (m);
700 } catch (ArgumentException ex) {
701 // The MemberInfo must be an interface method
702 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
703 Assert.IsNull (ex.InnerException, "#3");
704 Assert.IsNotNull (ex.Message, "#4");
705 Assert.AreEqual ("m", ex.ParamName, "#5");
710 public void TestPtrToStringAuto ()
712 string input = Guid.NewGuid ().ToString ();
718 if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
720 ptr = Marshal.StringToHGlobalAuto (input);
721 output = Marshal.PtrToStringUni (ptr);
722 output2 = Marshal.PtrToStringUni (ptr, len);
725 ptr = Marshal.StringToHGlobalAuto (input);
726 output = Marshal.PtrToStringAnsi (ptr);
727 output2 = Marshal.PtrToStringAnsi (ptr, len);
731 Assert.AreEqual (input, output, "#1");
732 Assert.AreEqual (input.Substring (0, len), output2, "#2");
734 Marshal.FreeHGlobal (ptr);
739 public void TestGenerateProgIdForType()
743 output = Marshal.GenerateProgIdForType(typeof(TestCoClass));
744 Assert.AreEqual ("MonoTests.System.Runtime.InteropServices.TestCoClass", output, "#1");
746 output = Marshal.GenerateProgIdForType(typeof(TestCoClassWithProgId));
747 Assert.AreEqual ("CoClassWithProgId", output, "#2");
751 public void TestGlobalAlloc ()
753 IntPtr mem = Marshal.AllocHGlobal (100);
754 mem = Marshal.ReAllocHGlobal (mem, (IntPtr) 1000000);
755 Marshal.FreeHGlobal (mem);
759 public void FreeHGlobal ()
761 // clear user doubts on assistly #6749
762 for (int i = 0; i < 1024; i++) {
763 IntPtr p = Marshal.AllocHGlobal (1024 * 1024);
764 Assert.AreNotEqual (IntPtr.Zero, p, i.ToString ());
765 Marshal.FreeHGlobal (p);
769 [StructLayout (LayoutKind.Sequential)]
770 public struct SimpleStruct2 {
776 public void PtrToStructureNull ()
778 Assert.IsNull (Marshal.PtrToStructure (IntPtr.Zero, typeof (SimpleStruct2)));
782 public void TestGetExceptionForHR ()
784 const int E_OUTOFMEMORY = unchecked ((int) 0x8007000E);
785 const int E_INVALIDARG = unchecked ((int) 0X80070057);
787 Exception ex = Marshal.GetExceptionForHR (E_OUTOFMEMORY);
788 Assert.AreEqual (typeof (OutOfMemoryException), ex.GetType (), "E_OUTOFMEMORY");
790 ex = Marshal.GetExceptionForHR (E_INVALIDARG);
791 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "E_INVALIDARG");
795 int p = (int) Environment.OSVersion.Platform;
796 return ((p == 4) || (p == 128) || (p == 6));
800 [DllImport ("kernel32.dll", SetLastError = true)]
802 static extern uint GetModuleFileName (
806 StringBuilder lpFilename,
808 [MarshalAs (UnmanagedType.U4)]
814 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
815 interface ITestDefault
821 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
822 [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
823 interface ITestDispatch
829 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
830 [InterfaceType(ComInterfaceType.InterfaceIsDual)]
837 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
838 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
839 interface ITestUnknown
845 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
846 interface ITestInterface
860 public class TestCoClass : ITestDispatch
862 public void DoNothing ()
867 [ProgId("CoClassWithProgId")]
868 public class TestCoClassWithProgId : ITestDispatch
870 public void DoNothing ()