Home » Community » Coffee corner » Load dll with U++
Load dll with U++ [message #56697] |
Sat, 03 April 2021 16:21  |
BetoValle
Messages: 204 Registered: September 2020 Location: Brasil Valinhos SP
|
Experienced Member |
|
|
HI,
How should i write code in a GUI application to load
a dll.
(for example how to load the generated dll
that is in the Assembly reference "CaptureScreenDll" ?)
Thanks
|
|
|
|
|
Re: Load dll with U++ [message #56702 is a reply to message #56700] |
Sun, 04 April 2021 00:00   |
BetoValle
Messages: 204 Registered: September 2020 Location: Brasil Valinhos SP
|
Experienced Member |
|
|
Hi Novo Thanks,
but
for a beginner, it is difficult to understand at first a reference to in-depth routines such as "DL"!
this topic of your link does not clarify much.
See after searching the forum, I also didn't get any practical example. So, only about 2 links commented on the "DL", then I made a comparison with some examples of Dll´s p / c ++ from the tutorialspoint, and even then, I hit my head, but in the end I got it wrong and tried it. I thank my guardian angel too!!!
..
//didn't have this component so I had to look for how to download...ide->menu Setup->UppHub and select Functions4U
//in the declaration
#include <Functions4U/Functions4U.h>
...
Dl screen;
void (*yF)(int x, int y, int cx, int cy, char *filename);
...
//AA is my class with method below
// integer n is saves lives
//lifeguards that I had to adapt because
//the link https://www.ultimatepp.org/src$Functions4U$Dl$en-us.html
//that exemplifies on windows will fail (bug?) if it [b]loads repeatedly[/b]
void AA::clickDll(){
if(n==0){
if (!screen.Load(AppendFileName("C:\\Temp\\outU++\\NOVOXXX\\CLANGx64.Debug.Debug_Full.Gui", "CaptureScreenDll.dll")))
throw Exc(Format(t_("% dll not found"), "Capture"));
yF = (void (*)(int,int,int,int,char *))screen.GetFunction("capture_screen");
}
if (!yF)
throw Exc(Format(t_("Function %s does not found in dll"), "captureScreen"));
char* f="teste.png";
yF(669,187,420,22,f);
n++;
}
|
|
|
Re: Load dll with U++ [message #56703 is a reply to message #56702] |
Sun, 04 April 2021 02:06   |
Novo
Messages: 1430 Registered: December 2006
|
Ultimate Contributor |
|
|
BetoValle wrote on Sat, 03 April 2021 18:00
for a beginner, it is difficult to understand at first a reference to in-depth routines such as "DL"!
this topic of your link does not clarify much.
Dynamic linker
Dynamic loading
AA::clickDll() is an example of dynamic loading.
dli-files are doing the same but in a more convenient way.
Example: uppsrc/Oracle/Oci8.cpp
Another example: bazaar/Firebird/fb.cpp
Regards,
Novo
|
|
|
Re: Load dll with U++ [message #56704 is a reply to message #56703] |
Sun, 04 April 2021 06:20   |
BetoValle
Messages: 204 Registered: September 2020 Location: Brasil Valinhos SP
|
Experienced Member |
|
|
Hi Novo, Thanks
In example below with traditional way also works but ... why application freeze when set FreeLibrary ?
this will not cause a problem or in the end does the code generated in U ++ free from memory?
...
typedef void (*importFunction)(int, int, int, int, char *);
...
void AA::clickDll2(){
importFunction fscreen;
HINSTANCE hinstLib = LoadLibrary(AppendFileName("C:\\Temp\\outU++\\NOVOXXX\\CLANGx64.Debug.Debug_Full.Gui", "CaptureScreenDll.dll"));
if (hinstLib == NULL) {
PromptOK("ERRO: não foi possível carregar a DLL\n");
return;
}
fscreen = (importFunction)GetProcAddress(hinstLib, "capture_screen");
if (fscreen == NULL) {
PromptOK("ERRO: não foi possível achar a função na DLL\n");
//FreeLibrary(hinstLib); uncommenting will abort here
return;
}
char* f="teste2.png";
fscreen(0,0,500,600,f);
//FreeLibrary(hinstLib); uncommenting will abort here
}
|
|
|
Re: Load dll with U++ [message #56705 is a reply to message #56703] |
Sun, 04 April 2021 06:27   |
Novo
Messages: 1430 Registered: December 2006
|
Ultimate Contributor |
|
|
Another thing to explore: Project -> Package Organizer -> Libraries.
If you add your DLL to a list of libraries, TheIDE will link against it, and DLL will be loaded at app launch time by OS.
BTW, each application/executable is a DLL (you can link against it), and each DLL is an executable (for example, try to run /lib/x86_64-linux-gnu/libc.so.6 on Linux)
Regards,
Novo
|
|
|
Re: Load dll with U++ [message #56706 is a reply to message #56704] |
Sun, 04 April 2021 06:39   |
Novo
Messages: 1430 Registered: December 2006
|
Ultimate Contributor |
|
|
BetoValle wrote on Sun, 04 April 2021 00:20Hi Novo, Thanks
In example below with traditional way also works but ... why application freeze when set FreeLibrary ?
this will not cause a problem or in the end does the code generated in U ++ free from memory?
I do not know that. Loading and unloading of DLLs is a very complicated process.
You need to debug/trace loading/unloading in your app.
Dependency Walker can trace all DLL-related function calls on Windows.
In case of Unix you do not need any extra-tools: man ld.so
Regards,
Novo
|
|
|
Re: Load dll with U++ [message #56707 is a reply to message #56704] |
Sun, 04 April 2021 09:58   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
.dli is only handy if you have more than like 8 functions you want to import from the .dll.
Check CtrlCore/Win32Wnd.cpp:107 for simple way how to do this.
Or you can you DllFn:
static BOOL (WINAPI *GetPointerPenInfoHistory)(UINT32 pointerId, UINT32 *entriesCount, POINTER_PEN_INFO *penInfo);
ONCELOCK {
DllFn(GetPointerPenInfoHistory, "User32.dll", "GetPointerPenInfoHistory");
};
Mirek
[Updated on: Sun, 04 April 2021 16:00] Report message to a moderator
|
|
|
|
|
|
Goto Forum:
Current Time: Sun May 11 01:53:55 CEST 2025
Total time taken to generate the page: 0.00655 seconds
|