How to use a dll function
-
THis is really an interesting question. What do you want to know?
I could just guess:you have a dll with a C interface and want to load it on runtime and call a function, look at QLibrary (dynamic loading, resolve function adress, function pointers)
you have a C or C++ dll with headers, which you want to bind during compile time, you have to use the headers with the exported functions and link against the dll.
you have a C++ dll and load it dynamically during runtime like plugins, the you need some export6ed C functions (see 1.) as creator functions and interfaces
you have a C++ dll and load it dynamically during runtime like plugins, but is has no exported C-functions as creator functions: does not work!
you want to call something from a dll but the dll is written in a different language: if the function is not exported a C-functions: you are lost...
-
Well, basically, all you need to do is change the type of target in your .pro file. Take a look at the qmake documentation for details on the different types of targets. However, you also need to make sure you actually export the functions in the right way. It depends on what kind of library you want to export how this works in detail.
Perhaps you need to explain a bit more detail what you want to achieve. A plugin is not the same as a library you want to link against at compile time, for instance. Volker already gave some options in this.
-
what I want is to write functions essaduas delphi for Qt, they were written within a dll. I would like to create a dll with these functions and add to my project and make use of functions. they lit externally. understand?
code
@function ReadString(lpAddress:DWORD):string;
var
i: Cardinal;
begin
Result := ''; // Inicia o resultado como nulo, caso não exista nada nesse address.
for i := 0 to 65535 do begin // Começa o loop
if PBYTE(lpAddress)^ = 0 then Break; // Se o primeiro byte for 0 (sem caracteres), sai do loop.
Result := Result + Chr(PBYTE(lpAddress)^); // Retorno da função = Retorno (caso já esteja depois do segundo loop + Caractere resultante do Chr (que retorna um caractere de um código ASCII especificado).
Inc(lpAddress); // Vai pro próximo caractere/byte.
end;
end;procedure WriteByte(lpAddress:DWORD;Value:Byte);
begin
PBYTE(lpAddress)^ := Value; // O conteúdo do pointer definido no parâmetro "lpAddress", em byte, vai ser igual ao definido no parâmetro "Value".
end;
@ -
Ok, so it really is about making use of an external .dll in a Qt application. What about Gerolfs contribution above isn't clear in this context? The point is that you need to make sure you export your application in a way that makes reuse from another application in another language possible. How you do that, is not Qt specific but something you need to look into for delphi.
-
-
No, you can use external dll's in Qt (or any other C++) applications. However, that dll needs to meet certain criteria, depending on the way you wish to use that dll. Gerolf talked about these criteria, and I suggest you search in dephi resources how to achieve this. The keyword to search for is exporting functions.
-
[quote author="aldoduju" date="1300650793"]and changed the focus, I noticed that it is easier to make the dll in the same Qt.
I wonder what kind of data to corespondete (Cardinal of Delphi) to Qt?
[/quote]
From this posting, I gather that aldoduju has changed his mind, and now instead of wanting to use a delphi-build dll in a Qt program, now wants to port his code to Qt and build the dll in Qt.