I'm using wxWidgets 2.8.9, built with the default settings under Windows XP, VC9. And I have absolutely standard EXE with IMPLEMENT_APP like this:
#include <wx/wx.h>
#include <wx/image.h>
#include "MainFrame.h"
class MyMainApp: public wxApp {
public:
bool OnInit();
};
IMPLEMENT_APP(MyMainApp)
bool MyMainApp::OnInit()
{
wxInitAllImageHandlers();
wxFrame* frame_mainFrame = new MainFrame(NULL, wxID_ANY, wxEmptyString);
SetTopWindow(frame_mainFrame);
frame_mainFrame->Show();
return true;
}
The MainFrame is a wxFrame with a "HelloWorld" text. This works fine when everything is linked in the EXE. The problem is, I would like to reuse this MainFrame class in another application and therefore I would like to have it in a DLL, so I can use the DLL code from everywhere.
Because my DLL has different export macro than wxWidgets, I can't export any derived from wxFrame class outside my Dll, so I make a factory class, which simply has one static method create(), returning new MainFrame(NULL, wxID_ANY, wxEmptyString);
So far so good. I have now a DLL, containing the MainFrame class, and one more FrameFactory class. Only the FrameFactory class is exported from my DLL and I can create the MainFrame in the EXE, in the OnInit() method like this: wxFrame* frame_mainFrame = FrameFactory::create();
The problem is that the constructor of the base class wxFrame calls wxTopLevelWindowMSW::CreateFrame(...), where the macro wxTheApp is invoked. This wxTheApp macro is actually a call to wxApp::GetInstance(). I was surprised that my wxApp instance is NULL when MainFrame is not in the EXE.
Could somebody familiar with wxWidgets help me what am I doing wrong? I made several more expreriments and always wxTheApp is NULL when the code using this instance variable is used in a different module, than the one where macro IMPLEMENT_APP is called.
I don't use wxWidgets myself (go Qt!) But did you by any chance statically link your DLL to wxWidgets, such that the EXE and the DLL each have their own copy of the lib...?
http://wiki.wxwidgets.org/Creating_A_DLL_Of_An_Application
That would explain why your DLL's global variables for tracking the instance would be null (while the EXEs were set up in app initialization). If this is the case I'd be concerned about your SetInstance() workaround...who knows what other singletons there are:
When to use dynamic vs. static libraries
Related
I create widget, inherited from C++ class below.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Widget_Manager.generated.h"
UCLASS()
class CRY_API UWidget_Manager : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, Category ="test")
int32 x;
UFUNCTION(BlueprintCallable, Category = "test")
int32 increase_x(int32 i);
};
I want to output the value of x in value1, then increase it, and output it to value2.
My problem is that the blueprints do not see the function increase_x().
Not in elements list, not in function search.
Also i tried property CallInEditor.
How I can call this function in widget?
Please make sure that your not using Hot Reload (the Compile C++ button in the Editor).
If you make changes to your C++ code, especially Headers, always close the Editor and recompile it from Visual Studio. Hot Reload cannot resolve changes to Header files, which means things like Functions and new Properties will not be available in Blueprint if your using Hot Reload until you do a recompile from Visual Studio.
Also its best to leave Context Sensitivity on.
I am very new to C++, I'm making this music application using wxWidgets, this is my first project in C++. As of now, I have 4 files, app.hpp and app.cpp which has a class that inherits from wxApp that launches the application, and frame.hpp and frame.cpp which holds the base frame and panel, and all the widgets, and their appropriate functions. I want to move all the functions to a separate file, but I get some errors like there is this function in frame.cpp
void Frame::ClearPlaylist(wxCommandEvent& event)
{
mediaCtrl->Stop();
playlistBox->Clear();
}
I tried moving it in another file called command.cpp and created a new class called command and prefixed all functions to Command:: .... and somethings like the playlistBox here, is a widget which I want in frame.cpp only, as it is a widget, so I did #include frame.hpp and prefixed it with Frame::playlistBox, but that gave a error saying invalid use of non static data member. So do I have to make everything in frame.hpp a static object? Or if anyone has a better solution for organizing a project like this please do share.
I'm trying to override some functions on CMFCVisualManager to customize my ribbon. So I created a class and derived from it.
void CMyVisualManager::OnDrawRibbonCategory(CDC* pDC, CMFCRibbonCategory* pCategory, CRect rectCategory)
Now this works and can change colors etc, but there are some functions that I cant or override or not doing it right like
void CMyVisualManager::OnDrawRibbonLaunchButton(CDC* pDC, CMFCRibbonLaunchButton* pButton, CMFCRibbonPanel* pPanel)
My method doesnt override the original, and the original function gets called
But https://msdn.microsoft.com/en-us/subscriptions/downloads/65a24718-8128-43f9-973d-25262bdceae7(v=vs.90)
says it can be overridden.
If anyone can point me in the right direction, I've been looking but can't find an answer thanks
Yes you override a function in your class.
But you visual manager isn't the one that is created. So it is never used.
When your program starts an instance of the visual manager is created. And this instance is used.
Only if you also force the MFC to use your visual manager your overriden functions are used.
There for use SetDefaultManager with the runtime class of your class in InitInstance of your program.
I am using Qt 4.7.2 under Fedora 14.
I have a working library of custom widgets which I am trying to integrate into Qt Designer.
There is a simple widget base class, then some more complex widgets inheriting from it.
The simple widget integrates fine, but I have a problem with the more complex ones.
The problem comes from the fact that that the more complex ones require a special structure to be passed to them on creation. So my code for creating a complex widget in the plugin is:
QWidget *myPlugin::createWidget(QWidget *parent)
{
my_struct *xyz = new my_struct;
return new myWidget("MyWidget",xyz, parent);
}
my_struct is just a simple C style struct with ints, doubles and arrays.
Then when I start Qt Designer with this plugin I get:
/usr/lib64/qt4/bin/designer: symbol lookup error: /usr/lib64/qt4/plugins/designer/libMyPlugin.so: undefined symbol: _ZN8MyWidgetC1E7QStringP17my_structP7QWidget
I am building a release version of the plugin, not a debug version.
I also tried defining xyz as a static class variable in the plugin and just passing its address to the constructor, but I still get the same error.
I also tried adding xyx as an unused static class variable to my simple widget and that does not give the error, so the error seems to be coming from the call to the myWidget constuctor.
Can anyone help me resolve this?
Thanks Arne,
You were right.
I added my library explicitly to the plugin's .pro file and then it worked.
What puzzles me is how could I build the plugin with no errors without the library?
And why did my simple widget work without the library?
The error message looks as if the linker did not find a definition for the constructor myWidget(QString, my_struct*, QWidget*). Have you added the relevant source file to your release build? Do you actually have a definition for this constructor? It is also possible that you have to exchange the object file linking order. I have seen this with larger projects in the past, so I wouldn't be too surprised. The object file containing the definition needs to be stated before the one using the definition.
I loaded the form but only buttons without functions
HMODULE hModule = LoadLibrary(L"Tools.dll");
if (hModule != NULL)
{
AfxSetResourceHandle(hModule);
CDialog dgl(MAKEINTRESOURCE(199), NULL);
dgl.DoModal();
}
so how I can load a full function of form
and I don't have the DLL source code
To show Dialog box from MFC dll , like scenario - you have exported function in DLL and from that function you call DoModel().This template actually stored in DLL module.You need to switch module state for current handle to be used.You can do this by using :
AFX_MANAGE_STATE(AfxGetStaticModuleState());
AFX_MODULE_STATE AfxGetStaticModuleState()
->The AFX_MODULE_STATE structure contains global data for the module,that is the portion of the module state that is pushed or popped.
IN DLL code will be like this :
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CMyDlg objMyDlg;
iRet = objMyDlg.DoModal();
This is possible only if you are sure that dialog class implementation is MFC based and the class is exported from Tools.dll. You can try inspect your .dll with Dependency Walker utility.
Please note the compiler mangles constructor name. This is what I got for the following declaration.
class __declspec(dllexport) TestDialog : public CDialog
{
public:
TestDialog()
:CDialog(10)
{
}
};
Mangled constructor name: ??_7TestDialog##6B#
Probably you will be able to recreate dialog class header based on the results of your inspection. You should also make sure you have the same version of MFC both for Tools.dll and your application.