69 zeilen c++ c konform machen; sozusagen c++ raus - c rein.



  • hallo
    folgender code (k8055.cpp) soll so abgeändert werden, dass er in ein c program (zb. myMain.c) per #include "k8055.c" includiert werden kann und man dann in myMain.c die in k8055.c enthaltenen funktionen aufrufen kann.
    ich hoffe mich einigermassen verständlich ausgedrückt zu haben.

    vielen dank
    olli

    k8055.cpp

    typedef void(__stdcall *t_func)(long );
    typedef void(__stdcall *t_func0)();
    typedef long(__stdcall *t_func1)();
    typedef void(__stdcall *t_func2)(long *, long *);
    typedef void(__stdcall *t_func3)(long , long );
    typedef long(__stdcall *t_func4)(long );
    typedef bool(__stdcall *t_func5)(long );

    //Allgemeine Arbeitsweisen
    t_func4 OpenDevice;
    t_func0 CloseDevice;

    //Analog in Digital konvertiern
    t_func4 ReadAnalogChannel;
    t_func2 ReadAllAnalog;

    //Digital in Analog konvertieren
    t_func3 OutputAnalogChannel;
    t_func3 OutputAllAnalog;
    t_func ClearAnalogChannel;
    t_func0 ClearAllAnalog;
    t_func SetAnalogChannel;
    t_func0 SetAllAnalog;

    //Digitaler Ausgang
    t_func WriteAllDigital;
    t_func ClearDigitalChannel;
    t_func0 ClearAllDigital;
    t_func SetDigitalChannel;
    t_func0 SetAllDigital;

    //Digitaler Eingang
    t_func5 ReadDigitalChannel;
    t_func1 ReadAllDigital;

    //Zählerfunktionen
    t_func3 ReadCounter;
    t_func ResetCounter;
    t_func3 SetCounterDebounceTime;

    HINSTANCE hModule;

    int init()
    {
    hModule = LoadLibrary("k8055d.dll");
    OpenDevice = (t_func4) GetProcAddress(hModule, "OpenDevice");
    CloseDevice = (t_func0) GetProcAddress(hModule, "CloseDevice");
    ReadAnalogChannel = (t_func4) GetProcAddress(hModule, "ReadAnalogChannel");
    ReadAllAnalog = (t_func2) GetProcAddress(hModule, "ReadAllAnalog");
    OutputAnalogChannel = (t_func3) GetProcAddress(hModule, "OutputAnalogChannel");
    OutputAllAnalog = (t_func3) GetProcAddress(hModule, "OutputAllAnalog");
    ClearAnalogChannel = (t_func) GetProcAddress(hModule, "ClearAnalogChannel");
    ClearAllAnalog = (t_func0) GetProcAddress(hModule, "ClearAllAnalog");
    SetAnalogChannel = (t_func) GetProcAddress(hModule, "SetAnalogChannel");
    SetAllAnalog = (t_func0) GetProcAddress(hModule, "SetAllAnalog");
    WriteAllDigital = (t_func) GetProcAddress(hModule, "WriteAllDigital");
    ClearDigitalChannel = (t_func) GetProcAddress(hModule, "ClearDigitalChannel");
    SetDigitalChannel = (t_func) GetProcAddress(hModule, "SetDigitalChannel");
    SetAllDigital = (t_func0) GetProcAddress(hModule, "SetAllDigital");
    ClearAllDigital = (t_func0) GetProcAddress(hModule, "ClearAllDigital");
    ReadDigitalChannel = (t_func5) GetProcAddress(hModule, "ReadDigitalChannel");
    ReadAllDigital = (t_func1) GetProcAddress(hModule, "ReadAllDigital");
    ReadCounter = (t_func3) GetProcAddress(hModule, "ReadCounter");
    ResetCounter = (t_func) GetProcAddress(hModule, "ResetCounter");
    SetCounterDebounceTime = (t_func3) GetProcAddress(hModule, "SetCounterDebounceTime");
    }



  • Schön, dass du uns sagst, was DU machen musst.



  • gonso schrieb:

    ich hoffe mich einigermassen verständlich ausgedrückt zu haben.

    Viel Spaß bei der Arbeit. Wenn schon gehört das unter Projekte und dann ggf. mit Angabe der Summe die du bereit bist dem Umschreiber zu zahlen.

    Deine Arbeit wird hier jedenfall (so hoffe ich wenigstens) keiner für lau erledigen.

    cu André



  • Wo ist da C++-Code? Schon mal versucht einfach als C-Quellcode zu kompilieren.



  • ein super beispiel für faulheit.

    @OP: initialisier doch wenigstens hModule mit NULL, und überprüf, ob die DLL überhaupt geladen werden kann.

    ansonsten: das müsste eigentlich mit jedem C compiler compilierbar sein. wenn du den MS compiler hast, einfach mal in .c umbennen, oder .cpp lassen und einen großen extern "C" block drum rum schreiben.

    aber deine arbeit wird dir hier niemand abnehmen.



  • Hallo

    Xantus schrieb:

    aber deine arbeit wird dir hier niemand abnehmen.

    Du tust es doch gerade.

    chrische


Anmelden zum Antworten