code_junkie

circular dependencies between dlls with visual studio

Nov 12th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. Public Function foo(ByVal value As C.IB) As Integer Implements C.IA.foo
  2. Return value.bar(Me)
  3. End Function
  4.  
  5. Public Function bar(ByVal value As C.IA) As Integer Implements C.IB.bar
  6. Return value.foo(Me)
  7. End Function
  8.  
  9. Public Interface IA
  10. Function foo(ByVal value As IB) As Integer
  11. End Interface
  12.  
  13. Public Interface IB
  14. Function bar(ByVal value As IA) As Integer
  15. End Interface
  16.  
  17. Sub Main()
  18.  
  19. Dim a As New A.A
  20. Dim b As New B.B
  21.  
  22. a.foo(b)
  23.  
  24. End Sub
  25.  
  26. // IFoo.cs: (build IFoo.dll)
  27. interface IFoo {
  28. void foo(int i);
  29. }
  30.  
  31. public class FooFactory {
  32. public static IFoo CreateInstance()
  33. {
  34. return (IFoo)Activator.CreateInstance("Foo", "foo").Unwrap();
  35. }
  36. }
  37.  
  38. // IBar.cs: (build IBar.dll)
  39. interface IBar {
  40. void bar(int i);
  41. }
  42.  
  43. public class BarFactory {
  44. public static IBar CreateInstance()
  45. {
  46. return (IBar)Activator.CreateInstance("Bar", "bar").Unwrap();
  47. }
  48. }
  49.  
  50. // foo.cs: (build Foo.dll, references IFoo.dll and IBar.dll)
  51. public class Foo : IFoo {
  52. void foo(int i) {
  53. IBar objBar = BarFactory.CreateInstance();
  54. if (i > 0) objBar.bar(i -i);
  55. }
  56. }
  57.  
  58. // bar.cs: (build Bar.dll, references IBar.dll and IFoo.dll)
  59. public class Bar : IBar {
  60. void bar(int i) {
  61. IFoo objFoo = FooFactory.CreateInstance();
  62. if (i > 0) objFoo.foo(i -i);
  63. }
  64. }
  65.  
  66. IFoo objFoo = FooFactory.CreateInstance();
  67.  
  68. IFoo objFoo = (IFoo)Activator.CreateInstance("Foo", "foo").Unwrap();
  69.  
  70. // foo.h
  71. #if defined(COMPILING_BAR_DLL)
  72. inline void foo(int x)
  73. {
  74. HMODULE hm = LoadLibrary(_T("foo.dll");
  75. typedef void (*PFOO)(int);
  76. PFOO pfoo = (PFOO)GetProcAddress(hm, "foo");
  77. pfoo(x); // call the function!
  78. FreeLibrary(hm);
  79. }
  80. #else
  81. extern "C" {
  82. __declspec(dllexport) void foo(int);
  83. }
  84. #endif
Add Comment
Please, Sign In to add comment