Seite 1 von 1

DLL aufrufen

Verfasst: 25.06.2018 08:46
von heiko22
Hallo,

ich möchte auf eine DLL mit Purebasic zugreifen.

Folgendes geht mit Codeblocks:

Code: Alles auswählen

#include "windows.h"
#include "stdio.h"
int main(){
    // Define DLL functions
      typedef double (WINAPI *AdresseSI)(char PropertyToReturn[20], char InputProperty1[20], double InputValue1, char InputProperty2[20], double InputValue2, char Refrigerant[20]);
    // addresses
    AdresseSI PropsSIAddress;
    double result1;
    // load DLL; change this path as needed
    HINSTANCE CoolPropDll;
    CoolPropDll = LoadLibraryA("CoolProp_32.dll");
    if (CoolPropDll)
    {
         // addresses
         PropsSIAddress = (AdresseSI) GetProcAddress(CoolPropDll, "_PropsSI@32");
         // call function
         if (PropsSIAddress)
         {
                result1 = (*PropsSIAddress) ("Dmass", "T", 298.15, "P", 101325, "R410A");
                printf("R410A density: %g\n", result1);
         }

         // unload DLL
         FreeLibrary(CoolPropDll);
    }
    else{
        printf("Could not load CoolProp DLL.");
    }
}
Das habe ich versucht, funktioniert nicht:

Code: Alles auswählen

PrototypeC.i Ergebnis(Wert1.p-unicode, Wert2.p-unicode, Wert3.d, Wert4.p-unicode, Wert5.d, Wert6.p-unicode)
datei.s="X:\purebasic\DLL-Datei-ana\CoolProp_32.dll"
If OpenLibrary(0, datei)
  Test.Ergebnis=GetFunction(0, "_PropsSI@32")
  Debug Test("Dmass", "T", 298.15, "P", 101325.0, "R410A")
EndIf

CloseLibrary(0)

Kann mir jemand helfen?

__________________________________________________
Code-Tags hinzugefügt
25.06.2018
RSBasic

Re: DLL aufrufen

Verfasst: 25.06.2018 09:17
von ts-soft
1. Die DLL-Version 32 oder 64-Bit muss zum Compiler passen.
2. Die DLL-Version 32 oder 64-Bit muss zum installiertem Excel passen.
3. Dies ist eine C++ DLL, wird also von PureBasic nicht direkt unterstützt! Du benötigst also eine Art Wrapper.

Aufgrund Deiner Frage hier, gehe ich davon aus, das Dir das nötige Know How dazu fehlt und es wohl nichts wird mit PureBasic. Ein fertiger Wrapper ist mir auch nicht bekannt.

Gruß
Thomas

Re: DLL aufrufen

Verfasst: 25.06.2018 10:34
von heiko22
Hallo Thomas,

vielen Dank für Deine Antwort.
Wie Du richtig erkannt hast habe ich nicht das nötige Know How.

Ich kann die dll mit Purebasic LibraryFunctionName() lesen und erhalte mit LibraryFunctionAddress() auch eine Adresse zurück.

Verstehe ich Dich dann richtig, dass es nicht weiter geht, da C++ DLL?

Viele Grüße

Heiko

Re: DLL aufrufen

Verfasst: 25.06.2018 10:41
von _JON_
Wo ist den genau das Problem? Wenn Du eine Address bekommst ist doch schon mal alles Ok.

Ich sehe bloß "char" und Du benutzt p-unicode anstatt p-ascii.

Und PrototypeC.i sollte wohl PrototypeC.d sein.

Re: DLL aufrufen

Verfasst: 25.06.2018 10:58
von heiko22
Hallo Jon,

vielen Dank.

Jetzt geht es.

Code: Alles auswählen

PrototypeC.d Ergebnis(Wert1.p-ascii, Wert2.p-ascii, Wert3.d, Wert4.p-ascii, Wert5.d, Wert6.p-ascii)
datei.s="X:\purebasic\DLL-Datei-ana\CoolProp_32.dll"
If OpenLibrary(0, datei)
Test.Ergebnis=GetFunction(0, "_PropsSI@32")
Debug Test("Dmass", "T", 298.15, "P", 101325.0, "R410A")
EndIf
CloseLibrary(0)
Viele Grüße

Heiko

__________________________________________________
Code-Tags hinzugefügt
25.06.2018
RSBasic