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 » Community » Coffee corner » Load dll with U++
Load dll with U++ [message #56697] Sat, 03 April 2021 16:21 Go to next message
BetoValle is currently offline  BetoValle
Messages: 202
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 #56699 is a reply to message #56697] Sat, 03 April 2021 19:50 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Load dynamically or link against it?

Regards,
Novo
Re: Load dll with U++ [message #56700 is a reply to message #56699] Sat, 03 April 2021 19:58 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
You can start here: Runtime dynamic linking using .dli files

Regards,
Novo
Re: Load dll with U++ [message #56702 is a reply to message #56700] Sun, 04 April 2021 00:00 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 202
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 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
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 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 202
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 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
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 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
BetoValle wrote on Sun, 04 April 2021 00:20
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?

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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
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

Re: Load dll with U++ [message #56710 is a reply to message #56706] Sun, 04 April 2021 19:29 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
I conclude that the freeze occurs because
was considering 32-bit code when in reality
the compiled dll for 64 bits. Construction should consider
the path below:


#if defined(PLATFORM_WIN32) 
	HINSTANCE hinstLib = 0;	
#else
	void *hinstLib = 0;
#endif


So that I could go deeper I would have to build a code to obtain the addressing of the process
for an old code that would take more time.
I will skip this step and logically use the DI class.
So I only registered this complementary post because I found the reason, although I did not write the solution, which would end up equivalent to that of the DI class itself.

Thanks!
Re: Load dll with U++ [message #56729 is a reply to message #56707] Wed, 07 April 2021 20:55 Go to previous message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi Mirek

using DllFn as you suggested you could put it here as you would build it to load the U++ example "CaptureScreenDll.dll"
to better understand?

Thanks
Previous Topic: Best way to chat between two pc
Next Topic: GLCtrl Linux dependency
Goto Forum:
  


Current Time: Thu Mar 28 13:28:15 CET 2024

Total time taken to generate the page: 0.01468 seconds