Forum: PC-Programmierung Velleman k8055: main.cpp erkennt .dll-Datei nicht!


von Quentin K. (kreazynismus)


Lesenswert?

Hallo!
Ich bin Anfänger im Programmieren und habe deshalb noch einige Fragen, 
die eventuell für Profis lachhaft erscheinen mögen. :D
Entschuldigen Sie das bitte.

Ich möchte Programme für das Velleman K8055 schreiben und benutze dazu 
C++ in der IDE DevC++ / DevCpp.

Anfangs würde ich gerne den von Velleman mitgelieferten Code "main.cpp" 
ausführen:

#include <cstdlib>
#include <windows.h>
#include <iostream>

typedef void(CALLBACK* t_func)(int );
typedef void(CALLBACK* t_func0)();
typedef int(CALLBACK* t_func1)();
typedef void(CALLBACK* t_func2)(int *, int *);
typedef void(CALLBACK* t_func3)(int , int );
typedef int(CALLBACK* t_func4)(int );
typedef bool(CALLBACK* t_func5)(int );

t_func4 OpenDevice;
t_func0 CloseDevice;
t_func0 Version_;
t_func4 ReadAnalogChannel;
t_func2 ReadAllAnalog;
t_func3 OutputAnalogChannel;
t_func3 OutputAllAnalog;
t_func ClearAnalogChannel;
t_func0 ClearAllAnalog;
t_func SetAnalogChannel;
t_func0 SetAllAnalog;
t_func WriteAllDigital;
t_func ClearDigitalChannel;
t_func0 ClearAllDigital;
t_func SetDigitalChannel;
t_func0 SetAllDigital;
t_func5 ReadDigitalChannel;
t_func1 ReadAllDigital;

HINSTANCE hDLL;
int foundDLL = 0;
int init();

using namespace std;

int main(int argc, char *argv[])
{
    int CardAddress;
    int dataOut1, dataOut2;
    int dataIn1, dataIn2;
    int h;


    h = init();
  if (!h)
  {
    cout << "DLL found" << endl;
    foundDLL = 1;
  }
  else
  {
    cout << "DLL not found " << endl;
  }
  if (foundDLL)
  {
    h = OpenDevice(0);
    if (h == 0)
    {
      cout << "Card 0 opened" << endl;
    }
    else
    {
      cout << "Card not found" << endl;
    }
  }
  if (foundDLL)
  {

        cout << "Press Enter to \"SetAllDigital\"" << endl;
        cin.get();
        SetAllDigital();
        cout << "Press Enter to \"OutputAllDigital 0x55\"" << endl;
        cin.get();
        WriteAllDigital(0x55);

        cout << "Press Enter to \"ReadAllDigital\"" << endl;
        cin.get();

        int i = ReadAllDigital();
        cout << i << endl;
        cout << "Press Enter to \"ReadDigitalChannel 1\"" << endl;
        cin.get();
        bool b = ReadDigitalChannel(1);
        cout << b << endl;
        cout << "Press Enter to \"ReadDigitalChannel 1\"" << endl;
        cin.get();
        b = ReadDigitalChannel(1);
        cout << b << endl;

        /*
        cout << "Press Enter to \"ClearAllDigital\"" << endl;
        cin.get();
        ClearAllDigital();

        cout << "Press Enter to \"OutputAllAnalog dataOut1, dataOut2\"" 
<< endl;
        cin.get();
        int h = 0;
        for (int i = 0; i<256; i++)
        {
            OutputAnalogChannel(1, i);
            h = ReadAnalogChannel(1);

        }

        int j;
         for (int i = 0; i<3; i++)
        {
            for (j = 0;j < 5;j++)
            OutputAnalogChannel(1, 0);
            for (j = 0;j < 5;j++)
            OutputAnalogChannel(1, 255);
        }

        dataOut1 =80;
        dataOut2 = 255;
        //OutputAllAnalog(dataOut1, dataOut2);
      */

        cout << "Press Enter to \"ReadAllAnalog dataIn1, dataIn2\"" << 
endl;
        cin.get();
        ReadAllAnalog(&dataIn1, &dataIn2);
            cout << "dataIn1 = " << dataIn1 << endl;
            cout << "dataIn2 = " << dataIn2 << endl;

        cout << "Press Enter to \"CloseDevices\" and to \"FreeLibrary\"" 
<< endl;
        cin.get();
        CloseDevice();

        FreeLibrary(hDLL);
    }

}

int init()
{
  hDLL = LoadLibrary("k8055d");
  if (hDLL != NULL)
  {
    OpenDevice = (t_func4) GetProcAddress(hDLL, "OpenDevice");
    if (!OpenDevice)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    CloseDevice = (t_func0) GetProcAddress(hDLL, "CloseDevice");
    if (!CloseDevice)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    ReadAnalogChannel = (t_func4) GetProcAddress(hDLL, 
"ReadAnalogChannel");
    if (!ReadAnalogChannel)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    ReadAllAnalog = (t_func2) GetProcAddress(hDLL, "ReadAllAnalog");
    if (!ReadAllAnalog)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    OutputAnalogChannel = (t_func3) GetProcAddress(hDLL, 
"OutputAnalogChannel");
    if (!OutputAnalogChannel)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    OutputAllAnalog = (t_func3) GetProcAddress(hDLL, "OutputAllAnalog");
    if (!OutputAllAnalog)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    ClearAnalogChannel = (t_func) GetProcAddress(hDLL, 
"ClearAnalogChannel");
    if (!ClearAnalogChannel)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    ClearAllAnalog = (t_func0) GetProcAddress(hDLL, "ClearAllAnalog");
    if (!ClearAllAnalog)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    SetAnalogChannel = (t_func) GetProcAddress(hDLL, 
"SetAnalogChannel");
    if (!SetAnalogChannel)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    SetAllAnalog = (t_func0) GetProcAddress(hDLL, "SetAllAnalog");
    if (!SetAllAnalog)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    WriteAllDigital = (t_func) GetProcAddress(hDLL, "WriteAllDigital");
    if (!WriteAllDigital)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    ClearDigitalChannel = (t_func) GetProcAddress(hDLL, 
"ClearDigitalChannel");
    if (!ClearDigitalChannel)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    ClearAllDigital = (t_func0) GetProcAddress(hDLL, "ClearAllDigital");
    if (!ClearAllDigital)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    SetDigitalChannel = (t_func) GetProcAddress(hDLL, 
"SetDigitalChannel");
    if (!SetDigitalChannel)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    SetAllDigital = (t_func0) GetProcAddress(hDLL, "SetAllDigital");
    if (!SetAllDigital)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    ReadDigitalChannel = (t_func5) GetProcAddress(hDLL, 
"ReadDigitalChannel");
    if (!ReadDigitalChannel)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    ReadAllDigital = (t_func1) GetProcAddress(hDLL, "ReadAllDigital");
    if (!ReadAllDigital)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    Version_ = (t_func0) GetProcAddress(hDLL, "Version");
    if (!Version_)
    {            // handle the error
      FreeLibrary(hDLL);
      return -2;
    }
    return 0;        // ok
  }
  return -1;          // error load DLL
}




Die Ausgabe ist immer DLL not found, obwohl die benötigte .dll-Datei 
korrekt im Projektordner liegt.
Woran liegt das und was kann ich tuen?


Vielen Dank im Vorraus.
LG Q

: Verschoben durch User
von Peter II (Gast)


Lesenswert?

[c]
hDLL = LoadLibrary("k8055d");
[c]

wie heißt denn die dll? Ich denke man muss schon den kompletten Namen 
angeben.

von Quentin K. (kreazynismus)


Lesenswert?

Peter II schrieb:
> [c]
> hDLL = LoadLibrary("k8055d");
> [c]
>
> wie heißt denn die dll? Ich denke man muss schon den kompletten Namen
> angeben.


Hallo Peter,
vielen Dank für deine schnelle Antwort.

Die .dll heißt K8055D.dll, muss ich das so in die Methode eintragen?
Und noch eine Frage dazu: Die [c]'s repräsentieren den Restcode. oder?
Danke im Vorraus.
LG Q

von Peter II (Gast)


Lesenswert?

Quentin K. schrieb:
> , muss ich das so in die Methode eintragen?

ja, denke ich.

Die
1
's repräsentieren den Restcode. oder?
2
3
ja, sollte eigentlich so aussehen:
4
5
[c]
6
hDLL = LoadLibrary("k8055d.dll");

von Peter II (Gast)


Lesenswert?

mist, so noch einmal:
1
hDLL = LoadLibrary("k8055d.dll");

von Quentin K. (kreazynismus)


Lesenswert?

Peter II schrieb:
> mist, so noch einmal:
>
>
1
> hDLL = LoadLibrary("k8055d.dll");
2
>

Leider muss ich nochmal stören,denn es funktioniert,Gott sei es 
geklagt,immer noch nicht.
Ich habe die Methode wie folgt inkludiert:

[c]
HINSTANCE hDLL;
hDLL = LoadLibrary("k8055d.dll");
int foundDLL = 0;
int init();
[c]

Beim Kompilieren wird nun folgende Fehlermeldung angegeben:
[Error] 'hDLL' does not name a type

Was habe ich falsch gemacht?

von Peter II (Gast)


Lesenswert?

Quentin K. schrieb:
> Ich habe die Methode wie folgt inkludiert:

worein inkludiert?

hast du auch die ganzen includes mit übernommen? Zum Spaß sind sie nicht 
da.


du solltest du den Dateinamen ändern, mehr nicht. Da kann es nicht auf 
einmal zu einem komplett anderen Fehler kommen.

von Quentin K. (kreazynismus)


Lesenswert?

Peter II schrieb:

> worein inkludiert?


In den Code von main.cpp
Ich gehe stark davon aus, dass die benötigten Header korrekt und 
komplett aufgeführt wurden, da main.cpp von dem Entwickler geschrieben 
und zur Verfügung gestellt wurde ...

von Peter II (Gast)


Lesenswert?

Quentin K. schrieb:
> In den Code von main.cpp
> Ich gehe stark davon aus, dass die benötigten Header korrekt und
> komplett aufgeführt wurden, da main.cpp von dem Entwickler geschrieben
> und zur Verfügung gestellt wurde ...

ja und? du hast es doch auch vorher compilieren können. Es hat sich 
nichts bis auf dem String dran geändert. Damit kann es nicht zu einer 
neuen Fehlermeldung kommen.

Keine Ahnung was du alles gemacht hast.

von Peter II (Gast)


Lesenswert?

Nachtrag:

du solltest du den vorhanden code anpassen, keine neue Zeile hinzufügen. 
Einfach das .dll an den String hängen.

von Quentin K. (kreazynismus)


Lesenswert?

Peter II schrieb:
> Nachtrag:
>
> du solltest du den vorhanden code anpassen, keine neue Zeile hinzufügen.
> Einfach das .dll an den String hängen.
Danke!
Der Code lässt sich sich so wieder kompillieren, gibt aber wieder bloß 
DLL not found aus.
Stimmt eventuell etwas am vorgegebenen Programm nicht?
LG Q

von Peter II (Gast)


Lesenswert?

Quentin K. schrieb:
> Stimmt eventuell etwas am vorgegebenen Programm nicht?
1
hDLL = LoadLibrary("k8055d.dll");


das wird wohl schief gehen, dann musst du halt mal z.b. procmon schauen, 
wo er die dll sucht. Eventuell gibt es ja noch ein 32 vs. 64 bit 
Problem.

von Quentin K. (kreazynismus)


Lesenswert?

Tut mir leid, dass übersteigt leider meine bisherigen Kenntnisse :(

1. Was ist ein(e) Procmon und wie erhalte ich Zugriff darauf?

2. Mein Computer verfügt über 64bit.
Woran erkenne ich,ob dies Komplikationen verursacht und falls dies der 
Fall sein sollte, was unternehme ich dagegen?

Entschuldige bitte die vielen Fragen :D

von Peter II (Gast)


Lesenswert?

Quentin K. schrieb:
> Tut mir leid, dass übersteigt leider meine bisherigen Kenntnisse :(

dann musst du sie dir aneignet. Mann muss wenigsten mit seinem Werkzeug 
umgehen können.

suche einfach bei Google

> Woran erkenne ich,ob dies Komplikationen verursacht und falls dies der
> Fall sein sollte, was unternehme ich dagegen?
ein 32bit Programm kann keine 64bit dll laden auch andersrum geht es 
nicht.

von Amateur (Gast)


Lesenswert?

Procmon steht für Process Monitor.

Der spricht aber nur englisch und ist nicht aus der Abteilung: Very 
easy.

Damit kann man recht einfach feststellen, wo ein Programm nach seinen 
Dateien, in Deinem Falle Bibliotheken, sucht.

von Quentin K. (kreazynismus)


Lesenswert?

Ich habe den Prozess Monitor heruntergeladen und ausgeführt, es werden 
etwa 200.000 Prozesse angezeigt.
Gibt es eine Möglichkeit, die Anzeige auf die relevanten Informationen 
zu reduzieren?

von Torsten (Gast)


Lesenswert?

Hallo Quentin,

eine DLL wird vom Programm an zwei Stellen gesucht.

1. im Systempfad wenn sie installiert wurde

2. im Ausführungspfad von deinen Programm

Der Ausführungspfad ist der Ordner in dem die IDE das Programm
ausführt. Also musst du die DLL dort hin kopieren.

Gruß Torsten

von Peter II (Gast)


Lesenswert?

Quentin K. schrieb:
> Gibt es eine Möglichkeit, die Anzeige auf die relevanten Informationen
> zu reduzieren?

bis du wirklich nicht in der Lage, einfach mal selber in dem Tools zu 
suchen ob es ein Filter gibt?

Würde zumindest schneller gehen, also ein Eintrag hier zu posten.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.