C++ virtual (sealed) function - c++-cli

I am using classes from a dll in my C++ project. All is working fine, until...
When trying to call a certain method (listed in the object browser), I am getting an error that this method is not a member of the namespace.
Upon investigation, I noticed that this method is listed as "virtual void x() sealed".
Is there a way to make a call to such a function?

For future reference, I just received a response from the enterprise library support team. They posted a link to the following:
Managed C++ and IDisposable
I'm writing some code using the new Managed C++/CLI syntax and I ran into this error:
error C2039: 'Dispose' : is not a member of 'System::IDisposable'
the code I started with was this:
image->Dispose(); // image implements IDisposable
which gave me the same compiler error, so I wanted to eliminate a class/namespace error so I rewrote it as this:
((IDisposable ^)image)->Dispose();
Which gave the above error. Yikes!
Here's the fix:
use delete. Managed C++ now hides Dispose() inside the finalizer. Just delete the object, it handles the rest. Freaky.
This really works!!!!

Sealed in a C++ CLI keyword (managed C++) specific to .NET and not C++ in general.
sealed on a function means that you can't override that method in a derived type.
sealed does not mean that you can't call the function, I'm guessing your function is private.

I don't see why it being virtual and sealed should in itself prevent you from calling the function. According to MSDN, the sealed keyword is specifically meant for virtual methods anyway.
Is there any more information you can give about the function in question and how you are trying to use it?

Related

ByteBuddy - rebase already loaded class

I have the following code working in a SpringBoot application, and it does what's I'm expecting.
TypePool typePool = TypePool.Default.ofClassPath();
ByteBuddyAgent.install();
new ByteBuddy()
.rebase(typePool.describe("com.foo.Bar").resolve(), ClassFileLocator.ForClassLoader.ofClassPath())
.implement(typePool.describe("com.foo.SomeInterface").resolve())
.make()
.load(ClassLoader.getSystemClassLoader());
Its makes is so that the class com.foo.Bar implements the interface com.foo.SomeInterface (which has a default implementation)
I would like to . use the above code by referring to the class as Bar.class, not using the string representation of the name. But if I do that I get the following exception.
java.lang.UnsupportedOperationException: class redefinition failed: attempted to change superclass or interfaces
I believe due to the fact that it cause the class to be loaded, prior to the redefinition. I'm just now learning to use ByteBuddy.
I want to avoid some reflection at runtime, by adding the interface and an implementation using ByteBuddy. I've some other code that checks for this interface.
This is impossible, not because of Byte Buddy but no tool is allowed to do this on a regular VM. (There is the so-called dynamic code evolution VM which is capable of that).
If you want to avoid the problem, use redefine rather then rebase. Whenever you instrument a method, you do now however replace the original.
If this is not acceptable, have a look at the Advice class which you can use by the .visit-API to wrap logic around your original code without replacing it.

How to use a static property from an abstract sealed class (C++/CLI)

I'm trying to work with a .NET DLL. When I create a new CLR project and add the DLL reference I have a class that shows up as public : ref class <name> abstract sealed. The class has two properties both defined as public : static property.
I can't figure out how to use them. Anything I try results with a compiler error (fatal error C1001). For instance I specify the namespace and the class separated by two colons and terminate it with a semicolon, for example class::property; does not give me the System::String variable. Normally this is fine in C++ but creates a compiler error with CLR.
I've tried both Visual Studio 2015 and 2013 and I get the same error. Any help on how to use this DLL is appreciated.
There are some samples on how to use the SDK with C# but not with CLR.
Some more information:
The SDK is actually a label design software called Nicelabel and the DLL is called SDK.Net.interface and is part of the Powerforms Suite install.
When I do something simple like the statement below I get the C1001 error:
NiceLabel::SDK::PrintEngineFactory::SDKFilesPath = "c:\\Temp";

How to exclude class from build after developpement in VS 2012 vb.net

I have a Helper class in my project that I use to help me develop the application. How do I NOT include this class in the final build when I take the application in production?
I still want the people who are going to do the maintenance to have access to it though.
So the behavior I'm looking for would be for the program to function normally while I'm developing it in Visual studio with the debug configurations. But if I build it with the release configurations, I would get an error for calls to an unknown member (supposing I didn't remove the calls to the Helper).
Sort of the same kind of behavior we have with tests.
An even better solution would not have me remove the calls to the Helper in the code.
Any way to do that?
Please comment if the question is unclear.
Use the ConditionalAttribute on the methods in the class.
Passing in DEBUG will mean that only when the DEBUG symbol is defined will the class compile.
Applying ConditionalAttribute to a method indicates to compilers that a call to the method should not be compiled into Microsoft intermediate language (MSIL) unless the conditional compilation symbol that is associated with ConditionalAttribute is defined.
<ConditionalAttribute("DEBUG")> _
Sub Method1(x As Integer)
Console.WriteLine("DEBUG is defined")
End Sub

Modify Property Code At Runtime in VB.NET

Let say I have the following classes,
Public Class Base
Public Event PropertyChanged()
Sub New()
.....
End Sub
End Class
Public Class Other
Inherits Base
Public Property X As String
End Class
If I wanted to say, alter the code definition of the automatic property X (at runtime, perhaps in Sub New), such that I could throw the PropertyChanged event, how could I go about doing that?
Edit: Its seems that the Postsharp is an available tool that does the functionality I'm exploring, but I wanted my question to be more academic than practical. So, how could I implement the code injection at compile time or runtime myself?
I guess you are looking for AOP. A very nice technology that IMHO isn't mature on the dotnet platform. I believe, correct me if I am wrong, that Postsharp is the best known AOP framework. It isn't gratis though for production; installing and playing (and possibly F/OSS) is gratis. Also check this post for more info.
The answer is simple: you can't. Once a type is loaded, you can't change its code.
If you want to implement INotifyPropertyChanged without writing the same code for each property, there are several ways.
One of them is making the property MustOverride (abstract in C#) and then creating another class at runtime which implements it at runtime (for example using Castle DynamicProxy).
Another one is using AOP to rewrite the code after compilation (but before it's run) using something like PostSharp.
Also have a look at Implementing INotifyPropertyChanged - does a better way exist?, for an overview of other options.

Problem overriding methods in VB.NET (Error BC30284)

I have an overridable sub in my base class
Project1:
Public Class BaseClass
Protected Overridable Sub MySub(ByVal Parameter as MyType)
End Class
Project2:
Public Class DerivedClass
Inherits BaseClass
Protected Overrides Sub MySub(ByVal Parameter as MyType)
End Class
MyType is a type that comes from external COM library. When I'm trying to override it in a derived class, I'm getting
error BC30284: sub 'MySub' cannot be declared 'Overrides' because it does not override a function in a base class
I've added the required COM reference to both projects containing base and derived classes.
Any idea how to get rid of this error? I'm using VS2005 and .NET 2.0
Edit: Every other override is working fine, I'm only getting error if I'm using referenced COM types as parameters. If I change Parameter to Object, overriding works fine.
Have you considered or tried using TlbImp.exe to generate a static DLL from the COM type library, and reference that from both projects (instead of using a COM reference) to make sure they are referring to exactly the same thing? TlbImp is included with Visual Studio, but I can't find it on my system with only Visual Studio Express installed, so if you're using express, you might have to go hunting for it (the linked page may or may not have the version you want). I suspect that if each project has their own COM reference, Visual Studio may be creating a separate COM wrapper for each project and the generated COM wrappers may not entirely agree with each other when it comes to generated GUIDs and whatnot. So by creating a and forcing the use of a single wrapper you may be able to eliminate that as a possible problem.
Rather than using TlbImp, another option is to have a separate project where you encapsulate the MyType in a .NET class and include that project in both your samples.
So you would end up with an intermediate MyDotNetType which would take as a constructor argument Mytype (the COM object) and expose it out as a read-only property.
Then the MySub call, would take the MyDotNetType as an argument.
Kind Regards
Noel
Please check the signature of the Function in both base class and derived class, if you have different agruments or data type o any arguments is not matched. Then you'll get this type of error. Simple please check the function name, argument name and data type. It worked me. I hope this answer will be helpful.
Thanks,
Ramu V