Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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++?
How to write a dll using Ultimate++? [message #11148] Thu, 23 August 2007 13:56 Go to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Hi,

I couldn't find any examples or clues in the documetaion as to writing a dll using upp classes.

My question is that are there any special steps to be taken at writing a dll which uses ultimate++?

thank you.


[Updated on: Thu, 23 August 2007 13:56]

Report message to a moderator

Re: How to write a dll using Ultimate++? [message #11151 is a reply to message #11148] Thu, 23 August 2007 17:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Yes and no. Interestingly, it is relatively easy to create U++ .dll to be used from non-U++ application, to use non-U++ .dll in U++ application, but what is complicated is U++ app with U++ .dll Smile

What is your focus?

Mirek
Re: How to write a dll using Ultimate++? [message #11153 is a reply to message #11148] Thu, 23 August 2007 17:46 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Have you got DLL template dll.upt or similar? As I remember in the old 605 version there was one but not in 2007...
Maybe someone could upload one here?
Re: How to write a dll using Ultimate++? [message #11154 is a reply to message #11151] Thu, 23 August 2007 21:51 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
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. Confused I'm using
2007.1

Thank you.


[Updated on: Thu, 23 August 2007 22:01]

Report message to a moderator

Re: How to write a dll using Ultimate++? [message #11155 is a reply to message #11154] Thu, 23 August 2007 22:36 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Ok, I've found the template (but it might be not the original)
  • Attachment: Win32dll.upt
    (Size: 0.83KB, Downloaded 513 times)
Re: How to write a dll using Ultimate++? [message #11156 is a reply to message #11155] Thu, 23 August 2007 22:49 Go to previous messageGo to next message
Zardos is currently offline  Zardos
Messages: 62
Registered: April 2007
Member
You can also check this thread:

http://www.ultimatepp.org/forum/index.php?t=msg&goto=103 67&&srch=dll#msg_10367
Re: How to write a dll using Ultimate++? [message #11157 is a reply to message #11155] Thu, 23 August 2007 23:00 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Unfortunately, the template didn't help too much. Sad
(thank you very much for your help, though Smile )
But you are totally right fudadmin. I have to re-formulate my problem: Embarassed

luzr wrote on Thu, 23 August 2007 17:37

Yes and no. Interestingly, it is relatively easy to create U++ .dll to be used from non-U++ application, to use non-U++ .dll in U++ application, but what is complicated is U++ app with U++ .dll Smile

What is your focus?

Mirek


I mean, how to write a U++ app with U++ dll? Smile


regards.


[Updated on: Thu, 23 August 2007 23:07]

Report message to a moderator

Re: How to write a dll using Ultimate++? [message #11158 is a reply to message #11157] Fri, 24 August 2007 00:45 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Quote:

I mean, how to write a U++ app with U++ dll?

Is your life not enough hell? Smile Would you like another one? Smile I mean dll... Smile
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?

P.S. I had some very limited successful experiments in this area some time ago but I can't promise that I can find the correct files or the current version of U++ would work with them.
Re: How to write a dll using Ultimate++? [message #11159 is a reply to message #11158] Fri, 24 August 2007 13:25 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
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 Shocked ) 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.

2. Yes, I am happy with C/C++ dll's Smile

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 Smile


[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 Go to previous messageGo to next message
mr_ped is currently offline  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 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
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 #11165 is a reply to message #11158] Fri, 24 August 2007 23:23 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
fudadmin wrote on Thu, 23 August 2007 18:45

Quote:

I mean, how to write a U++ app with U++ dll?

Is your life not enough hell? Smile Would you like another one? Smile I mean dll... Smile



I've been using DLLs on Windows and Unix for long time, and I can help with making U++ more DLL-frendly ...

DLL is not hell, especially in case of Unix.


Regards,
Novo
Re: How to write a dll using Ultimate++? [message #11166 is a reply to message #11157] Fri, 24 August 2007 23:35 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Oblivion wrote on Thu, 23 August 2007 17:00


I mean, how to write a U++ app with U++ dll? Smile



You won't find dllexport/dllimport in the source code. So, the answer is very simple: there is no way (on Windows).


Regards,
Novo
Re: How to write a dll using Ultimate++? [message #11167 is a reply to message #11166] Sat, 25 August 2007 00:09 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
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.

It was even possible to build all packages as .dlls - that is what "SO" option in the Output mode... are for.

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
Re: How to write a dll using Ultimate++? [message #11178 is a reply to message #11167] Sun, 26 August 2007 01:49 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Something wrong here with question (project structure?) formulation... Smile
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 Smile ). 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 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
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 Smile ).

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. Smile


Secondly; as to a U++.dll, ok I give up this idea for some time Smile

Regards.


Re: How to write a dll using Ultimate++? [message #11180 is a reply to message #11179] Sun, 26 August 2007 09:29 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, if you are going to produce production quality code, make sure that you

- use MSC compiler (exe size drops 50%, is 2x faster) - the best results are with MSC7.1 if you can get it, IME MSC8.0 is worse compiler. Obviously, you need commandline tools only...

- compile in release mode

And yes, the minimal application size is 1.2MB (e.g. UWord).

Mirek
Re: How to write a dll using Ultimate++? [message #11214 is a reply to message #11167] Mon, 27 August 2007 20:19 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
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 #11215 is a reply to message #11214] Mon, 27 August 2007 20:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
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 Smile

Quote:


I couldn't find the "SO" option, I only see "Shared libs" and "All shared", but they don't seem to have any effect.



"All shared". Reflected as "SO" compile flag.

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
Re: How to write a dll using Ultimate++? [message #11217 is a reply to message #11215] Mon, 27 August 2007 23:27 Go to previous messageGo to previous message
Novo is currently offline  Novo
Messages: 1358
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 Smile



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 Wink). 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

Previous Topic: ArgcArgv – use argc and argv under Ultimate++!
Next Topic: Porting a Delphi Application
Goto Forum:
  


Current Time: Thu Mar 28 15:26:18 CET 2024

Total time taken to generate the page: 0.02564 seconds