Passing Class Reference over Interface - vb.net

I'm sorry for editing but I got the feeling like my question was not specific enough.
I have a Host Application, a Interface.dll and a Plugin.dll. Within my Host Application I'm globally using a Instance of a class.
However: My Plugin.dll (which implements my iInterface form the Interface.dll) needs to have access to that specific instance of my class in the Host Application.
By having my Functions names within the interface, I can access those functions in the plugin from the host application, but how can I access the global class instance from the plugin?
I cannot write
Public Interface IPlugin
Sub SetInstance(ByRef MyClassInstance As MyClass)
End Interface
But this es exactly what I want to do...
Thank you very much for your help.

There is no way to implement the class from the host application within an interface. The only way would be referencing as object which will cause plenty of other problems.
Solution was to export the common classes into a own library (.dll) and instantiate this library to both - the host application and the plugin and in the interface.
Now passing the reference is possible without any problems as if all the different code parts were within the same namespace.
Thank you guys for your help.

Related

Forcibly opening or otherwise impersonating a class in Kotlin

I'm working in Kotlin, and I have a library that I can't modify (without maintaining my own fork of this huge and rapidly changing library).
There's a class in that library I need to instantiate, and it requires an instance of another class that does some stuff for it. I need to change how that second class works, so it feeds different information to the first class. But the second class is not open, and the first class asks for it by its full, non-open type.
How do I force my way into the non-open class and extend it anyway, against the desires of the library authors? Alternately, how do I cheat the type system to pass my own class off as an instance of the class the library is demanding?
Do I need to do some fiddling around at the JAR/build system level to replace the library's class files with my own versions? Can I use reflection to somehow impersonate the non-open class? Is there some other way to do it?

How to get created objects (instances) in VB.net

I just did some researches on google but I didn't find an answer to my question.
Is there a way to get the list of the active objects (instances of classes) at runtime?
In my application I need to have single instance classes that needs to be used by different running forms but if I create an instance in the form A, ho do i get control of the same instance in the form B?
Thank you
Actually, your question has 2 parts:
1. How to create single-instance objects.
2. How to have the same object accessible from different forms.
Fortunately for you, there is a solution to both of these problems in one simple and common design pattern called Singleton.
Classes written in the Singleton pattern can only have a single instance, and as you are about to see, as a side effect, this instance is accessible through the entire application.
The simplest way to use the singleton design pattern is this:
Public Class SingletonClass
Private Shared _instance As SingletonClass
Public Shared Function GetSingletonClass() As SingletonClass
If isNothing(_instance) Then
_instance = New SingletonClass()
End If
Return _instance
End Function
Private Sub New()
'' Create the instance here
End Sub
End Class
As you can see, since the constructor is private, it is not accessible from anywhere outside of class SingletonClass, and since class SingletonClass holds a static reference to it's instance, it means that every time you write SingletonClass.GetSingletonClass() in your application you get the same instance.
This design pattern solves both of your problems in a simple, elegant, and well known architecture.
Update
I've recently read a great article about different ways to implement singleton patterns. It turns out that my above specific implementation is not so good, as it is not thread safe. The code examples in this article are C#, but it should be very easy to change them to VB.Net. If you are using .Net 4 or higher, I would recommend going with the 6th version - using .NET 4's Lazy type.
It is both thread safe and lazy loading, two advantages that the implementation I've written doesn't have.

#Local and #Remote interfaces - Pass by reference vs deep copy

We have an app with the with three interfaces per bean. A *BI (business interface) which contains all the methods, a *LI, which extends BI and is annotated as #Local, and *RI, which also extends BI, but is annotated as #Remote.
I want to remove all *LI and *RI interfaces in favor of *BI, leaving they as #Remote, but there is a problem.
Local lookup pass arguments as references, while remote lookup uses deepcopy. The app is full of pass-by-reference expectations (things that only works if pass by reference works).
If I have only #Remote interfaces, the container will know when it is a local lookup and make pass-by-reference works in that case?
Container is JBoss AS 7.1.1 Final and we use EJB 3.1.
Thanks in advance.
Since the local and remote interfaces behave differently even a local client could want to use the remote interface. So it would be a problem if the container just guessed "this client is running in the same VM, let's give him a local interface".
Details on the differences were already discussed here.
If you want to keep all your interface definitions in one place simply write an interface
and let it be inherited by two (empty) interfaces annotated with #Local and #Remote.

How to find COM interface definition for given interface GUID?

I have a COM interface GUID but I don't know that interface definition. I don't know what methods it has, what parameters they have and so on. How can I obtain such information? Is it possible in general?
Practical problem is obtaining interface definition for few COM interfaces defined in actxprxy.dll. For example IFileDialogPrivate ({AC92FFC5-F0E9-455A-906B-4A83E74A803B}). (Obviously the interface is not documented and the name does suggest there is a reason for that.) I tried to use OLE/COM Object Viewer (OleView.exe) for that but wasn't able to get the interface definition.
I am trying to implement IFileDialogPrivate while doing some experiments on forcing IExplorerBrowser control to filter Windows 7 library folders. IFileDialog (which seems to use IExplorerBrowser) does it somehow and IExplorerBrowser askes service provider for IFileDialog and IFileDialogPrivate if ICommDlgBrowser is provided so I tryied to explore that interface. (Also it asks for few other interestingly named interface - could be useful).

Visual Studio - manage multiple files that are part of one Class - classes, modules

My VB project is large enough that it requires several files. It was originally developed as a Console App and I created each file as a MODULE. All modules could use subroutines, data structures and constants from other MODULES and everything worked fine. I needed to add basic windowing to the app and this required that the app be converted from a Console App to a Windows Forms App. The main window is Form1 which is not a MODULE but a CLASS. The problem is that some MODULE based functions cannot access subroutines, data and constants that are defined within the CLASS Form1 unless they are incorporated into the CLASS file and this makes the CLASS file very large. If I add a new Class file to the project, it also cannot interoperate with Class Form1 in the same way that multi-MODULE code interoperates.
How does one spread CLASS code across several files and still allow it to interoperate as if it were in a single file? Alternatively, how does one create several CLASS files that operate the way multiple MODULE files operate.
I am sure that there are all kinds of best practices that I am violating but the goal to to get some prototype software working and interfaced to some lab equipment.
Thank you in advance
Use a partial class (Partial keyword on the class declaration). Each partial "bit" of the class will be merged at compile time. All partial bits must be in the same project.
Modules are default shared and do not require initialization with the New keyword. When you made your console app a windows app, it became a class...You could change it to the same behavior as a module simply by making it a Public shared Class and making all properties and methods inside shared as well.
so while you can access your methods and properties in your modules without initialization, you would need to use the NEW method to initialize your Class methods.
To access the Class from the module you would simply have to use:
SomeModulemethod
dim x as new CLASS
CLASS.SOMEMETHOD
someModuleMethod End
You could also use Partial Classing to split up your Classes, but it is much better to decide if you really need a separate class for what you want to do.