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)
11 using NUnit.Framework;
14 using System.Reflection;
16 using System.Reflection.Emit;
18 using System.Runtime.InteropServices;
19 using System.Security;
22 namespace MonoTests.System.Runtime.InteropServices
25 public class MarshalTest
27 [StructLayout (LayoutKind.Sequential)]
36 [StructLayout (LayoutKind.Explicit)]
38 [FieldOffset (0)] public int field;
41 [StructLayout (LayoutKind.Sequential)]
42 struct StrSequential {
50 [StructLayout (LayoutKind.Explicit)]
52 [FieldOffset (0)] public int field;
56 public void SizeOf_Class_LayoutSequential ()
58 Marshal.SizeOf (typeof (ClsSequential));
62 public void SizeOf_Class_LayoutNotSet ()
65 Marshal.SizeOf (typeof (ClsNoLayout));
67 } catch (ArgumentException ex) {
68 // Type '...MarshalTest+ClsNoLayout' cannot be
69 // marshaled as an unmanaged structure; no
70 // meaningful size or offset can be computed
71 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
72 Assert.IsNull (ex.InnerException, "#3");
73 Assert.IsNotNull (ex.Message, "#4");
78 public void SizeOf_Class_LayoutExplicit ()
80 Marshal.SizeOf (typeof (ClsExplicit));
84 public void SizeOf_Struct_LayoutSequential ()
86 Marshal.SizeOf (typeof (StrSequential));
90 public void SizeOf_Struct_LayoutNotSet ()
92 Marshal.SizeOf (typeof (StrNoLayout));
96 public void SizeOf_Struct_LayoutExplicit ()
98 Marshal.SizeOf (typeof (StrExplicit));
102 public void SizeOf_Array ()
105 Marshal.SizeOf (typeof (string []));
107 } catch (ArgumentException ex) {
108 // Type 'System.String[]' cannot be marshaled
109 // as an unmanaged structure; no meaningful
110 // size or offset can be computed
111 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
112 Assert.IsNull (ex.InnerException, "#3");
113 Assert.IsNotNull (ex.Message, "#4");
118 public unsafe void Sizeof_Pointer ()
120 int size = Marshal.SizeOf (typeof (char*));
121 Assert.IsTrue (size == 4 || size == 8);
125 public void PtrToStringWithNull ()
127 Assert.IsNull (Marshal.PtrToStringAnsi (IntPtr.Zero), "A");
128 Assert.IsNull (Marshal.PtrToStringUni (IntPtr.Zero), "C");
132 public void PtrToStringAnsi_Ptr_Zero ()
135 Marshal.PtrToStringAnsi (IntPtr.Zero, 0);
137 } catch (ArgumentNullException ex) {
138 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
139 Assert.IsNull (ex.InnerException, "#3");
140 Assert.IsNotNull (ex.Message, "#4");
141 Assert.AreEqual ("ptr", ex.ParamName, "#5");
146 public void PtrToStringWithUni_Ptr_Zero ()
149 Marshal.PtrToStringUni (IntPtr.Zero, 0);
151 } catch (ArgumentNullException ex) {
152 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
153 Assert.IsNull (ex.InnerException, "#3");
154 Assert.IsNotNull (ex.Message, "#4");
155 Assert.AreEqual ("ptr", ex.ParamName, "#5");
160 public unsafe void UnsafeAddrOfPinnedArrayElement ()
162 short[] sarr = new short [5];
165 IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement (sarr, 2);
166 Assert.AreEqual (3, *(short*) ptr.ToPointer ());
170 public void AllocHGlobalZeroSize ()
172 IntPtr ptr = Marshal.AllocHGlobal (0);
173 Assert.IsTrue (ptr != IntPtr.Zero);
174 Marshal.FreeHGlobal (ptr);
186 public void OffsetOf_FieldName_Static ()
189 Marshal.OffsetOf (typeof (Foo), "b");
191 } catch (ArgumentException ex) {
192 // Field passed in is not a marshaled member of
193 // the type '...MarshalTest+Foo'
194 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
195 Assert.IsNull (ex.InnerException, "#3");
196 Assert.IsNotNull (ex.Message, "#4");
197 Assert.AreEqual ("fieldName", ex.ParamName, "#5");
202 public void GetHINSTANCE ()
205 Assert.Ignore ("GetHINSTANCE only applies to Windows.");
209 StringBuilder fileName;
211 fileName = new StringBuilder (255);
212 a = Assembly.GetExecutingAssembly ();
213 hinstance = Marshal.GetHINSTANCE (a.GetModules () [0]);
214 Assert.IsTrue (GetModuleFileName (hinstance, fileName,
215 fileName.Capacity) > 0, "#A1");
216 Assert.AreEqual (a.Location, fileName.ToString (), "#A2");
219 a = typeof (int).Assembly;
220 hinstance = Marshal.GetHINSTANCE (a.GetModules () [0]);
221 Assert.IsTrue (GetModuleFileName (hinstance, fileName,
222 fileName.Capacity) > 0, "#B1");
223 Assert.IsTrue (File.Exists (fileName.ToString ()), "#B3");
224 Assert.AreEqual ("mscorlib.dll", Path.GetFileName (fileName.ToString ()), "#B4");
228 public void GetHINSTANCE_Module_Dynamic ()
230 AssemblyName aname = new AssemblyName ();
233 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
234 aname, AssemblyBuilderAccess.Save,
235 Path.GetTempPath ());
236 ModuleBuilder mb = ab.DefineDynamicModule ("foo.dll", false);
238 IntPtr hinstance = Marshal.GetHINSTANCE (mb);
239 Assert.AreEqual (-1, hinstance.ToInt32 ());
243 public void GetHINSTANCE_Module_Null ()
246 Marshal.GetHINSTANCE ((Module) null);
248 } catch (ArgumentNullException ex) {
249 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
250 Assert.IsNull (ex.InnerException, "#3");
251 Assert.IsNotNull (ex.Message, "#4");
252 Assert.AreEqual ("m", ex.ParamName, "#5");
256 [Test] // bug #319009
257 public void StringToHGlobalUni ()
259 IntPtr handle = Marshal.StringToHGlobalUni ("unicode data");
260 string s = Marshal.PtrToStringUni (handle);
261 Assert.AreEqual (12, s.Length, "#1");
263 handle = Marshal.StringToHGlobalUni ("unicode data string");
264 s = Marshal.PtrToStringUni (handle);
265 Assert.AreEqual (19, s.Length, "#2");
269 public void ReadIntByte ()
271 IntPtr ptr = Marshal.AllocHGlobal (4);
273 Marshal.WriteByte (ptr, 0, 0x1);
274 Marshal.WriteByte (ptr, 1, 0x2);
275 Assert.AreEqual (0x1, Marshal.ReadByte (ptr));
276 Assert.AreEqual (0x1, Marshal.ReadByte (ptr, 0));
277 Assert.AreEqual (0x2, Marshal.ReadByte (ptr, 1));
279 Marshal.FreeHGlobal (ptr);
284 public void ReadInt16 ()
286 IntPtr ptr = Marshal.AllocHGlobal (64);
288 Marshal.WriteInt16 (ptr, 0, 0x1234);
289 Marshal.WriteInt16 (ptr, 2, 0x4567);
290 Marshal.WriteInt16 (ptr, 5, 0x4567);
291 Assert.AreEqual (0x1234, Marshal.ReadInt16 (ptr));
292 Assert.AreEqual (0x1234, Marshal.ReadInt16 (ptr, 0));
293 Assert.AreEqual (0x4567, Marshal.ReadInt16 (ptr, 2));
295 Assert.AreEqual (0x4567, Marshal.ReadInt16 ((ptr + 5)));
297 Assert.AreEqual (0x4567, Marshal.ReadInt16 (ptr, 5));
299 Marshal.FreeHGlobal (ptr);
304 public void ReadInt32 ()
306 IntPtr ptr = Marshal.AllocHGlobal (64);
308 Marshal.WriteInt32 (ptr, 0, 0x12345678);
309 Marshal.WriteInt32 (ptr, 4, 0x77654321);
310 Marshal.WriteInt32 (ptr, 10, 0x77654321);
311 Assert.AreEqual (0x12345678, Marshal.ReadInt32 (ptr));
312 Assert.AreEqual (0x12345678, Marshal.ReadInt32 (ptr, 0));
313 Assert.AreEqual (0x77654321, Marshal.ReadInt32 (ptr, 4));
315 Assert.AreEqual (0x77654321, Marshal.ReadInt32 ((ptr + 10)));
317 Assert.AreEqual (0x77654321, Marshal.ReadInt32 (ptr, 10));
319 Marshal.FreeHGlobal (ptr);
324 public void ReadInt32_Endian ()
326 IntPtr ptr = Marshal.AllocHGlobal (4);
328 Marshal.WriteByte (ptr, 0, 0x01);
329 Marshal.WriteByte (ptr, 1, 0x02);
330 Marshal.WriteByte (ptr, 2, 0x03);
331 Marshal.WriteByte (ptr, 3, 0x04);
332 // Marshal MUST use the native CPU data
333 if (BitConverter.IsLittleEndian){
334 Assert.AreEqual (0x04030201, Marshal.ReadInt32 (ptr), "ReadInt32");
336 Assert.AreEqual (0x01020304, Marshal.ReadInt32 (ptr), "ReadInt32");
339 Marshal.FreeHGlobal (ptr);
344 public void ReadInt64 ()
346 IntPtr ptr = Marshal.AllocHGlobal (16);
348 Marshal.WriteInt64 (ptr, 0, 0x12345678ABCDEFL);
349 Marshal.WriteInt64 (ptr, 8, 0x87654321ABCDEFL);
350 Assert.AreEqual (0x12345678ABCDEFL, Marshal.ReadInt64 (ptr));
351 Assert.AreEqual (0x12345678ABCDEFL, Marshal.ReadInt64 (ptr, 0));
352 Assert.AreEqual (0x87654321ABCDEFL, Marshal.ReadInt64 (ptr, 8));
354 Marshal.FreeHGlobal (ptr);
359 [Category ("MobileNotWorking")]
360 public void BSTR_Roundtrip ()
363 IntPtr ptr = Marshal.StringToBSTR (s);
364 string s2 = Marshal.PtrToStringBSTR (ptr);
365 Assert.AreEqual (s, s2, "string");
369 [Category ("MobileNotWorking")]
370 public void StringToBSTRWithNullValues ()
373 string s = String.Empty.PadLeft (size, '\0');
374 Assert.AreEqual (size, s.Length, "Length-1");
376 IntPtr ptr = Marshal.StringToBSTR (s);
378 for (int i = 0; i < size; i += 4)
379 Marshal.WriteInt32 (ptr, i, 0);
381 string s2 = Marshal.PtrToStringBSTR (ptr);
382 Assert.AreEqual (128, s2.Length, "Length-2");
384 Marshal.FreeBSTR (ptr);
389 public void StringToHGlobalAnsiWithNullValues ()
392 string s = String.Empty.PadLeft (size, '\0');
393 Assert.AreEqual (size, s.Length, "Length-1");
395 IntPtr ptr = Marshal.StringToHGlobalAnsi (s);
397 for (int i = 0; i < size; i += 4)
398 Marshal.WriteInt32 (ptr, i, 0);
400 string s2 = Marshal.PtrToStringAnsi (ptr);
401 Assert.AreEqual (0, s2.Length, "Length-2");
403 Marshal.FreeHGlobal (ptr);
408 public void StringToHGlobalAutoWithNullValues ()
411 string s = String.Empty.PadLeft (size, '\0');
412 Assert.AreEqual (size, s.Length, "Length-1");
414 IntPtr ptr = Marshal.StringToHGlobalAuto (s);
416 for (int i = 0; i < size; i += 4)
417 Marshal.WriteInt32 (ptr, i, 0);
419 string s2 = Marshal.PtrToStringAuto (ptr);
420 Assert.AreEqual (0, s2.Length, "Length-2");
422 Marshal.FreeHGlobal (ptr);
427 public void StringToHGlobalUniWithNullValues ()
430 string s = String.Empty.PadLeft (size, '\0');
431 Assert.AreEqual (size, s.Length, "Length-1");
433 IntPtr ptr = Marshal.StringToHGlobalUni (s);
435 for (int i = 0; i < size; i += 4)
436 Marshal.WriteInt32 (ptr, i, 0);
438 string s2 = Marshal.PtrToStringUni (ptr);
439 Assert.AreEqual (0, s2.Length, "Length-2");
441 Marshal.FreeHGlobal (ptr);
446 public void StringToCoTaskMemAnsiWithNullValues ()
449 string s = String.Empty.PadLeft (size, '\0');
450 Assert.AreEqual (size, s.Length, "Length-1");
452 IntPtr ptr = Marshal.StringToCoTaskMemAnsi (s);
454 for (int i = 0; i < size; i += 4)
455 Marshal.WriteInt32 (ptr, i, 0);
457 string s2 = Marshal.PtrToStringAnsi (ptr);
458 Assert.AreEqual (0, s2.Length, "Length-2");
460 Marshal.FreeCoTaskMem (ptr);
465 public void StringToCoTaskMemAutoWithNullValues ()
468 string s = String.Empty.PadLeft (size, '\0');
469 Assert.AreEqual (size, s.Length, "Length-1");
471 IntPtr ptr = Marshal.StringToCoTaskMemAuto (s);
473 for (int i = 0; i < size; i += 4)
474 Marshal.WriteInt32 (ptr, i, 0);
476 string s2 = Marshal.PtrToStringAuto (ptr);
477 Assert.AreEqual (0, s2.Length, "Length-2");
479 Marshal.FreeCoTaskMem (ptr);
484 public void StringToCoTaskMemUniWithNullValues ()
487 string s = String.Empty.PadLeft (size, '\0');
488 Assert.AreEqual (size, s.Length, "Length-1");
490 IntPtr ptr = Marshal.StringToCoTaskMemUni (s);
492 for (int i = 0; i < size; i += 4)
493 Marshal.WriteInt32 (ptr, i, 0);
495 string s2 = Marshal.PtrToStringUni (ptr);
496 Assert.AreEqual (0, s2.Length, "Length-2");
498 Marshal.FreeCoTaskMem (ptr);
502 private const string NotSupported = "Not supported before Windows 2000 Service Pack 3";
503 private static char[] PlainText = new char[] { 'a', 'b', 'c' };
504 private static byte[] AsciiPlainText = new byte[] { (byte) 'a', (byte) 'b', (byte) 'c' };
506 private unsafe SecureString GetSecureString ()
508 fixed (char* p = &PlainText[0]) {
509 return new SecureString (p, PlainText.Length);
514 public void SecureStringToBSTR_Null ()
517 Marshal.SecureStringToBSTR (null);
519 } catch (ArgumentNullException ex) {
520 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
521 Assert.IsNull (ex.InnerException, "#3");
522 Assert.IsNotNull (ex.Message, "#4");
523 Assert.AreEqual ("s", ex.ParamName, "#5");
528 public void SecureStringToBSTR ()
531 SecureString ss = GetSecureString ();
532 IntPtr p = Marshal.SecureStringToBSTR (ss);
534 char[] decrypted = new char[ss.Length];
535 Marshal.Copy (p, decrypted, 0, decrypted.Length);
536 Assert.AreEqual (PlainText, decrypted, "Decrypted");
538 Marshal.ZeroFreeBSTR (p);
539 } catch (NotSupportedException) {
540 Assert.Ignore (NotSupported);
545 public void SecureStringToCoTaskMemAnsi_Null ()
548 Marshal.SecureStringToCoTaskMemAnsi (null);
550 } catch (ArgumentNullException ex) {
551 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
552 Assert.IsNull (ex.InnerException, "#3");
553 Assert.IsNotNull (ex.Message, "#4");
554 Assert.AreEqual ("s", ex.ParamName, "#5");
559 public void SecureStringToCoTaskMemAnsi ()
562 SecureString ss = GetSecureString ();
563 IntPtr p = Marshal.SecureStringToCoTaskMemAnsi (ss);
565 byte[] decrypted = new byte[ss.Length];
566 Marshal.Copy (p, decrypted, 0, decrypted.Length);
567 Assert.AreEqual (AsciiPlainText, decrypted, "Decrypted");
569 Marshal.ZeroFreeCoTaskMemAnsi (p);
570 } catch (NotSupportedException) {
571 Assert.Ignore (NotSupported);
576 public void SecureStringToCoTaskMemUnicode_Null ()
579 Marshal.SecureStringToCoTaskMemUnicode (null);
581 } catch (ArgumentNullException ex) {
582 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
583 Assert.IsNull (ex.InnerException, "#3");
584 Assert.IsNotNull (ex.Message, "#4");
585 Assert.AreEqual ("s", ex.ParamName, "#5");
590 public void SecureStringToCoTaskMemUnicode ()
593 SecureString ss = GetSecureString ();
594 IntPtr p = Marshal.SecureStringToCoTaskMemUnicode (ss);
596 char[] decrypted = new char[ss.Length];
597 Marshal.Copy (p, decrypted, 0, decrypted.Length);
598 Assert.AreEqual (PlainText, decrypted, "Decrypted");
600 Marshal.ZeroFreeCoTaskMemUnicode (p);
601 } catch (NotSupportedException) {
602 Assert.Ignore (NotSupported);
607 public void SecureStringToGlobalAllocAnsi_Null ()
610 Marshal.SecureStringToGlobalAllocAnsi (null);
612 } catch (ArgumentNullException ex) {
613 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
614 Assert.IsNull (ex.InnerException, "#3");
615 Assert.IsNotNull (ex.Message, "#4");
616 Assert.AreEqual ("s", ex.ParamName, "#5");
621 public void SecureStringToGlobalAllocAnsi ()
624 SecureString ss = GetSecureString ();
625 IntPtr p = Marshal.SecureStringToGlobalAllocAnsi (ss);
627 byte[] decrypted = new byte[ss.Length];
628 Marshal.Copy (p, decrypted, 0, decrypted.Length);
629 Assert.AreEqual (AsciiPlainText, decrypted, "Decrypted");
631 Marshal.ZeroFreeGlobalAllocAnsi (p);
632 } catch (NotSupportedException) {
633 Assert.Ignore (NotSupported);
638 public void SecureStringToGlobalAllocUnicode_Null ()
641 Marshal.SecureStringToGlobalAllocUnicode (null);
643 } catch (ArgumentNullException ex) {
644 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
645 Assert.IsNull (ex.InnerException, "#3");
646 Assert.IsNotNull (ex.Message, "#4");
647 Assert.AreEqual ("s", ex.ParamName, "#5");
652 public void SecureStringToGlobalAllocUnicode ()
655 SecureString ss = GetSecureString ();
656 IntPtr p = Marshal.SecureStringToGlobalAllocUnicode (ss);
658 char[] decrypted = new char[ss.Length];
659 Marshal.Copy (p, decrypted, 0, decrypted.Length);
660 Assert.AreEqual (PlainText, decrypted, "Decrypted");
662 Marshal.ZeroFreeGlobalAllocUnicode (p);
663 } catch (NotSupportedException) {
664 Assert.Ignore (NotSupported);
671 public void TestGetComSlotForMethodInfo ()
673 Assert.AreEqual (7, Marshal.GetComSlotForMethodInfo(typeof(ITestDefault).GetMethod("DoNothing")));
674 Assert.AreEqual (7, Marshal.GetComSlotForMethodInfo(typeof(ITestDual).GetMethod("DoNothing")));
675 Assert.AreEqual (7, Marshal.GetComSlotForMethodInfo (typeof(ITestDefault).GetMethod ("DoNothing")));
676 Assert.AreEqual (3, Marshal.GetComSlotForMethodInfo (typeof(ITestUnknown).GetMethod ("DoNothing")));
678 for (int i = 0; i < 10; i++)
679 Assert.AreEqual (7+i, Marshal.GetComSlotForMethodInfo(typeof(ITestInterface).GetMethod ("Method"+i.ToString())));
683 public void TestGetComSlotForMethod_Method_Null ()
686 Marshal.GetComSlotForMethodInfo (null);
688 } catch (ArgumentNullException ex) {
689 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
690 Assert.IsNull (ex.InnerException, "#3");
691 Assert.IsNotNull (ex.Message, "#4");
692 Assert.AreEqual ("m", ex.ParamName, "#5");
697 public void TestGetComSlotForMethodInfo_Method_NotOnInterface ()
699 MethodInfo m = typeof(TestCoClass).GetMethod ("DoNothing");
701 Marshal.GetComSlotForMethodInfo (m);
703 } catch (ArgumentException ex) {
704 // The MemberInfo must be an interface method
705 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
706 Assert.IsNull (ex.InnerException, "#3");
707 Assert.IsNotNull (ex.Message, "#4");
708 Assert.AreEqual ("m", ex.ParamName, "#5");
713 public void TestPtrToStringAuto ()
715 string input = Guid.NewGuid ().ToString ();
721 if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
723 ptr = Marshal.StringToHGlobalAuto (input);
724 output = Marshal.PtrToStringUni (ptr);
725 output2 = Marshal.PtrToStringUni (ptr, len);
728 ptr = Marshal.StringToHGlobalAuto (input);
729 output = Marshal.PtrToStringAnsi (ptr);
730 output2 = Marshal.PtrToStringAnsi (ptr, len);
734 Assert.AreEqual (input, output, "#1");
735 Assert.AreEqual (input.Substring (0, len), output2, "#2");
737 Marshal.FreeHGlobal (ptr);
742 public void TestGenerateProgIdForType()
746 output = Marshal.GenerateProgIdForType(typeof(TestCoClass));
747 Assert.AreEqual ("MonoTests.System.Runtime.InteropServices.TestCoClass", output, "#1");
749 output = Marshal.GenerateProgIdForType(typeof(TestCoClassWithProgId));
750 Assert.AreEqual ("CoClassWithProgId", output, "#2");
754 public void TestGlobalAlloc ()
756 IntPtr mem = Marshal.AllocHGlobal (100);
757 mem = Marshal.ReAllocHGlobal (mem, (IntPtr) 1000000);
758 Marshal.FreeHGlobal (mem);
762 public void FreeHGlobal ()
764 // clear user doubts on assistly #6749
765 for (int i = 0; i < 1024; i++) {
766 IntPtr p = Marshal.AllocHGlobal (1024 * 1024);
767 Assert.AreNotEqual (IntPtr.Zero, p, i.ToString ());
768 Marshal.FreeHGlobal (p);
772 [StructLayout (LayoutKind.Sequential)]
773 public struct SimpleStruct2 {
779 public void PtrToStructureNull ()
781 Assert.IsNull (Marshal.PtrToStructure (IntPtr.Zero, typeof (SimpleStruct2)));
786 public void TestGetExceptionForHR ()
788 const int E_OUTOFMEMORY = unchecked ((int) 0x8007000E);
789 const int E_INVALIDARG = unchecked ((int) 0X80070057);
791 Exception ex = Marshal.GetExceptionForHR (E_OUTOFMEMORY);
792 Assert.AreEqual (typeof (OutOfMemoryException), ex.GetType (), "E_OUTOFMEMORY");
794 ex = Marshal.GetExceptionForHR (E_INVALIDARG);
795 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "E_INVALIDARG");
800 int p = (int) Environment.OSVersion.Platform;
801 return ((p == 4) || (p == 128) || (p == 6));
805 [DllImport ("kernel32.dll", SetLastError = true)]
807 static extern uint GetModuleFileName (
811 StringBuilder lpFilename,
813 [MarshalAs (UnmanagedType.U4)]
819 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
820 interface ITestDefault
826 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
827 [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
828 interface ITestDispatch
834 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
835 [InterfaceType(ComInterfaceType.InterfaceIsDual)]
842 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
843 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
844 interface ITestUnknown
850 [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
851 interface ITestInterface
865 public class TestCoClass : ITestDispatch
867 public void DoNothing ()
872 [ProgId("CoClassWithProgId")]
873 public class TestCoClassWithProgId : ITestDispatch
875 public void DoNothing ()