|
|
Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » How to write a dll using Ultimate++?
|
|
|
Re: How to write a dll using Ultimate++? [message #11154 is a reply to message #11151] |
Thu, 23 August 2007 21:51 |
Oblivion
Messages: 1112 Registered: August 2007
|
Senior Contributor |
|
|
Well, currently I am converting my multi-protocol IM application (something like miranda, etc.) from MFC to UPP. I've already recoded the main IM framework into UPP. But my plugin system depends (as usual) on dll's and I want to use UPP instead of MFC in the plugin dlls. So that I want't to use UPP-dll in a UPP based application. Is there any way to use upp "in" the dll's? If yes, is there any barebone upp-dll example available?
(For example, in MFC you have to take some special steps (like using GETMANAGEDSTATE() macro, or in smartwin++ "cannibalizing" the main enty code with some smartwin++ routines) to get it work.)
And, no I don't have any dll.upt template or similar. I'm using
2007.1
Thank you.
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Thu, 23 August 2007 22:01] Report message to a moderator
|
|
|
|
|
|
|
Re: How to write a dll using Ultimate++? [message #11159 is a reply to message #11158] |
Fri, 24 August 2007 13:25 |
Oblivion
Messages: 1112 Registered: August 2007
|
Senior Contributor |
|
|
fudadmin wrote on Fri, 24 August 2007 00:45 |
Ok, less serious questions:
1. Why do you want U++ packed into dll?
2. Have you got any experience writing and loading C++ dll?
3. Have you successfully compiled test dll project with the template I posted?
|
1. Actually, I have a bunch of dlls which contain GUI code in my project. If I link these dlls statically with U++, I get a "huge" dll file (1 to 3 megs depending on it's profile ) Assume that I have 3 different dll's which contain U++ code, then the total file size of the dll's would get to almost 6-10 megs . Now, I call this hell! That's why I need U++ in a dll.
2. Yes, I am happy with C/C++ dll's
3. Yes, I have successfully compiled the template. But it is an ordinary win32 dll template and the problem is that whenever I load any U++ GUI class through the dll (eg. opening a TopWindow), The main or child windows layouts (eg, borders, colors) get corrupted or not drawn. In MFC, for example, AFX_MANAGE_STATE() macro is used to prevent such misfunctioning. Is there any macro, or method needed to be called before initalization of the dlls in u++?
4. Bonus: thank you for your patience
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Fri, 24 August 2007 13:30] Report message to a moderator
|
|
|
Re: How to write a dll using Ultimate++? [message #11163 is a reply to message #11148] |
Fri, 24 August 2007 19:15 |
mr_ped
Messages: 825 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
AFAIK (I'm not really an expert for UPP, Mirek (luzr) will give you much more accurate information as he is creator of UPP):
The upp is not prepared to be included into DLLs and mixed up with main UPP app.
The problem is in clashing between different threads of the UPP core.
I'm not sure about creating UPP dll with core, and than using this DLL in plugins DLLs.
But as far as I can remember you are exploring new grounds and you will very likely need some tweaks inside UPP to make this possible.
I think if your usage of UPP from plugins is limited enough, maybe it would be easier to create a wrapper interface class with those few functions used, than instantiate this wrapper class in UPP dll, which will run the only upp core in whole application, and make the wrapper instance public to plugins DLLs and call anything from UPP trough that instance.
I'm not comfortable enough with DLLs to understand what will happen with heap, memory allocations, etc... in such case. I have some vague idea that every DLL has it's own memory allocator and heap? This may get you on really thin ice, if you are not sure what you are doing.
|
|
|
Re: How to write a dll using Ultimate++? [message #11164 is a reply to message #11163] |
Fri, 24 August 2007 23:12 |
Novo
Messages: 1371 Registered: December 2006
|
Ultimate Contributor |
|
|
mr_ped wrote on Fri, 24 August 2007 13:15 | I'm not comfortable enough with DLLs to understand what will happen with heap, memory allocations, etc... in such case. I have some vague idea that every DLL has it's own memory allocator and heap? This may get you on really thin ice, if you are not sure what you are doing.
|
As long as you are linking against CRT *dynamically*, and using only one version of CRT (let say MT DLL) you will be fine.
Regards,
Novo
[Updated on: Mon, 27 August 2007 16:49] Report message to a moderator
|
|
|
|
|
|
Re: How to write a dll using Ultimate++? [message #11178 is a reply to message #11167] |
Sun, 26 August 2007 01:49 |
|
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
Something wrong here with question (project structure?) formulation...
Oblivion, you said you can't pack U++ code into dll and then you say:
Quote: | Actually, I have a bunch of dlls which contain GUI code in my project.
|
That means, you have got some extra-terrestrial (not U++) GUI code like wxWidgets, Fox etc., does it?
(additional question: Why not to convert all the GUI into U++, then)?
Quote: | If I link these dlls statically with U++, I get a "huge" dll file (1 to 3 megs depending on it's profile Shocked )
|
I wouldn't say 1-3 Mb is huge these days...
Quote: | Assume that I have 3 different dll's which contain U++ code, then the total file size of the dll's would get to almost 6-10 megs Shocked . Now, I call this hell! Razz That's why I need U++ in a dll.
| (I asssume you've checked it in release mode) But... is 6-10mb a really such a big problem to load for nowadays computers?
OTOH, check and compare theide and let's say firefox memory usage... One year ago and a bit, when I was using widows, theide memory usage was comparable to that of notepad.exe...
Also, the assumption logic that, if you merge 3 U++ programs of 2 Mb into one, you'l get 6 Mb is very suspicious (mildly speaking, imo ). Could someone (Mirek?) confirm/deny that?
So, the size of app is your main worry?
If that is the case maybe is worth to think about e.g compression of the executable, using better compiler on windows, playings with optim flags.
And lastly, why not to make U++ your main part and to load other parts as dlls?
|
|
|
Re: How to write a dll using Ultimate++? [message #11179 is a reply to message #11178] |
Sun, 26 August 2007 03:15 |
Oblivion
Messages: 1112 Registered: August 2007
|
Senior Contributor |
|
|
Quote: | That means, you have got some extra-terrestrial (not U++) GUI code like wxWidgets, Fox etc., does it?
(additional question: Why not to convert all the GUI into U++, then)?
|
I was using MFC (as a dll) in my project(s). Actually, I was nearly a "diehard" MFC user. But after considering the disadvantages of the age-old MFC and the advantages or the possible benefits of the ultimate++, I decided to convert my MFC based multi-protocol IM project into U++. I've already finished converting the main framework into U++ without any problems. The main executable (which consists of a service handler and a GUI) is now working fine (And I have to admit that, with the u++ it looks and acts much more better ).
Quote: | And lastly, why not to make U++ your main part and to load other parts as dlls?
|
Firstly; U++ is the main part of my project and I use some other parts of GUI code (gui-extension plugins) as dlls. But as I stated before,
Quote: | 3. Yes, I have successfully compiled the template. But it is an ordinary win32 dll template and the problem is that whenever I load any U++ GUI class through the dll (eg. opening a TopWindow), The main or child windows layouts (eg, borders, colors) get corrupted or not drawn. In MFC, for example, AFX_MANAGE_STATE() macro is used to prevent such misfunctioning. Is there any macro, or method needed to be called before initalization of the dlls in u++?
|
Is there any solution to this odd behaviour? Upp based GUI-extension dlls compile without any errors or warnings. But the gui components looks corrupted every time I load them through the dlls. I didn't come by any special dll entry point (dllmain()) function or macro in the documentation or in the upp source code, which I should invoke. Am I missing something?
It's no problem for me to code these dll's in any other framework. But U++ has many benefits as far as I can see. So that's why I'm insisting on the dll issue.
Secondly; as to a U++.dll, ok I give up this idea for some time
Regards.
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
|
|
|
|
Re: How to write a dll using Ultimate++? [message #11214 is a reply to message #11167] |
Mon, 27 August 2007 20:19 |
Novo
Messages: 1371 Registered: December 2006
|
Ultimate Contributor |
|
|
luzr wrote on Fri, 24 August 2007 18:09 | Actually, no dllimport/dllexport is not a problem: TheIDE builders take care about this stupid detail, making U++ dynamic linking equalt to the one in Linux in this regard.
|
That is very interesting. I know only two ways to export functions from DLL:
1) dllexport;
2) def-file;
There is probably a possibility to export everything (like -E with gcc).
How did you manage to do that? In order to build a def-file you have to know mangled names of functions/methods.
Quote: |
It was even possible to build all packages as .dlls - that is what "SO" option in the Output mode... are for.
|
I couldn't find the "SO" option, I only see "Shared libs" and "All shared", but they don't seem to have any effect.
Quote: |
Some time ago this has worked in Windows too, but it is too annoying to maintain U++ sources in "dll" friendly state - there is too much you are not allowed to do in .dll in windows... (global variables to start the list...).
Mirek
|
IMHO, global variables are allowed in DLLs on Windows. Could you please describe that problem in more details or point me out to an appropriate discussion?
P.S. IMHO, this discussion should be continued in "technology" group.
Regards,
Novo
|
|
|
|
Re: How to write a dll using Ultimate++? [message #11217 is a reply to message #11215] |
Mon, 27 August 2007 23:27 |
Novo
Messages: 1371 Registered: December 2006
|
Ultimate Contributor |
|
|
luzr wrote on Mon, 27 August 2007 14:56 |
Quote: |
That is very interesting. I know only two ways to export functions from DLL:
1) dllexport;
2) def-file;
There is probably a possibility to export everything (like -E with gcc).
How did you manage to do that? In order to build a def-file you have to know mangled names of functions/methods.
|
Look into .obj file and collect the mangled names, then autogenerate the appropriate .def file
|
It's a cool hacker's trick. And TheIDE is a a good C++ hacking tool. But that doesn't make UPP portable, if it is a plan.
Quote: |
Quote: |
IMHO, global variables are allowed in DLLs on Windows. Could you please describe that problem in more details or point me out to an appropriate discussion?
|
Unfortunately they are not. GCC has some crazy hack that makes it possible (something sort of calling a function and returning the pointer to variable), but in raw .dll, technically it is impossible, there are entries for functions only.
Mirek
|
I still do not understand you. A few years back I wrote a simple dll-testing application (mostly to test static/global object destruction order and DLL unloading order). I couldn't find any problems with DLL + MinGW (I was able to crash gcc from Cygwin ). Could you please post a code snippet that demonstrates the problem? I can upload my dll-testing application.
Thanks.
Regards,
Novo
[Updated on: Mon, 27 August 2007 23:28] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Fri Sep 20 10:56:06 CEST 2024
Total time taken to generate the page: 0.09524 seconds
|
|
|