DLL aufrufen

Anfängerfragen zum Programmieren mit PureBasic.
heiko22
Beiträge: 3
Registriert: 25.06.2018 08:37

DLL aufrufen

Beitrag 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
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Re: DLL aufrufen

Beitrag 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
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
heiko22
Beiträge: 3
Registriert: 25.06.2018 08:37

Re: DLL aufrufen

Beitrag 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
Benutzeravatar
_JON_
Beiträge: 389
Registriert: 30.03.2010 15:24

Re: DLL aufrufen

Beitrag 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.
PureBasic 5.46 LTS (Windows x86/x64) | windows 10 x64 Oktober failure
heiko22
Beiträge: 3
Registriert: 25.06.2018 08:37

Re: DLL aufrufen

Beitrag 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
Antworten