How could I create a method in dll written in c++ which returns a class, and how could I use that dll in java?
If i am export that class the name of that class get changed. Could any body help me? Thanks in advance.
You can't export a C++ class from a DLL and use it from a different compiler. What you can, and should, do is to export a COM object.
You can't. You could use JNI, but that's pretty horrible, and you'll have to write the code to convert from a C++ object to a corresponding Java object.
You could also look at JNA, which tries to make this a little easier.
Related
It is rather simple to get a Glib::RefPtr to any widget by using get_widget function of Gtk::Builder, but when it comes to getting other objects the corresponding get_object function returns Glib::Object, which is not easily convertable to the needed class (such as Gtk::TreeView).
What is the appropriate way of doing that?
It would be best to use Glib::RefPtr<TheDerivedype>::cast_dynamic(object) .
However, Gtk::TreeView (which you mention in your question) is a Gtk::Widget, so you would use get_widget() instead of get_object().
If you meant, Gtk::TreeModel, well, defining GtkTreeModels in Glade, for use in gtkmm C++ code, is something that might work since we added some fixes for that in gtkmm recently:
https://bugzilla.gnome.org/show_bug.cgi?id=742637
But it's not something that we generally expect to work - many C++ developers would prefer the static type safety of defining the DataModel structure completely in code, and not relying on a translation between C and C++ types. For instance: https://developer.gnome.org/gtkmm-tutorial/stable/sec-treeview-model.html.en#treeview-model-liststore
Glib::RefPtr has a static template function which allows one to do what is needed. This function is logically called cast_static.
The sample code can be:
treeStore =
Glib::RefPtr< Gtk::TreeStore >::cast_static( builder->get_object("treestore1") );
I am creating a DLL in C++ to be used in a Delphi 7 project, this dll will use OpenMP and will replace some methods that already exist in the project, this in order to hopefully get a speed up in the application.
One of the functions is defined like this:
function ReplaceFunction(chain:String;functionTE:TEFunction):string;
The object functionTE is declared like this,
TEFunction = class(TObject)
private
FFunctionName: string;
procedure SetFunctionName(const Value: string);
function GetFunctionNameCapital: string;
public
Handle:THandle;
Funcion:Pointer;
FileName:string;
ParamNumber:integer;
Description:string;
property FunctionNameCapital:string read GetFunctionNameCapital;
property FunctionName:string read FFunctionName write SetFunctionName;
end;
How can I pass an object of this class to the dll and use it?
How can I pass an object of this class to the dll and use it?
You cannot. Only Delphi code can consume Delphi classes. And even then, only code that uses the same instance of the runtime. Which requires runtime packages.
You'll need to expose the functionality in an interop friendly manner. Either plain C style functions, or a COM style interface are the obvious options.
And not only can you not pass that object, you also must not attempt to use Delphi native strings across an interop boundary. Again you need to use interop friendly types. For strings this includes C string (null-terminated arrays of characters) and the COM BSTR.
I just want to know if there is any way to call a c++ class into our nsis script ?
Thanks.
NSIS can call functions in DLLs but the calling convention is somewhat limited and there's no direct support for classes. You will not be able to easily call class function.
You might be able to "hack" it by making extern "C" wrapper functions for every class member function, along with function that create and destroy instances of the class as necessary. You'd have to somehow passes something that represents the newly created instances back to NSIS, which then would pass it into the wrapper functions along with any necessary parameters/arguments.
Sounds like more trouble than it's worth...
In my opinion the easiest way to call your function will be to export it to dll and then call them from nsis using System::Call function.
I have a C++ class that I need to create several instances of in a C# application. Apparently this means I'll need to make a C++/CLI wrapper as you can't import C++ classes into C#, but I've never used it before. The C++ class inherits from a base class which just contains several pure virtual functions, and no data. The DLL exports just one function which creates a new instance of the class and returns a pointer to the base class.
What C++/CLI type can be used to call that function and get the pointer to the C++ class, but which can also be imported into C#?
Thanks.
You don't need any special “C++/CLI type”, you should be able to call that function like from normal C++. But if you want to use the C++ class from C#, you really need to write C++/CLI managed wrapper class that you will be able to use from C#.
The managed wrapper class will contain a filed with a pointer to the unmanaged class. It will also contain the same members as the unmanaged class, that forward to their unmanaged equivalents.
For an example of how to do that, see How to: Wrap Native Class for Use by C# on MSDN.
I have a native class which requires a function pointer in the constructor. I have tried searching the forums, but couldnt quite find what I was looking for.
The native class looks like this:
class NativeClass{
NativeClass(std::string(*callback)(std::string args)){
//native code goes here
}
};
What is the best way of passing a delegate? Any help will be appreciated.
You need to use Marshal.GetFunctionPointerForDelegate() to achieve this.
Note that this will return a function pointer that uses the stdcall calling convention. You can specify a different calling convention by using the UnmanagedFunctionPointer attribute on your delegate declaration.