Seite 1 von 1

Funktionen in C++ aus DLL exportieren

Verfasst: 23.07.2005 02:43
von MVXA
Hallo!
Ich muss euch erstmal warnen, dass ich keine große C++ Leuchte bin. Ich hab da ein kleines Problem. Ich möchte in C++ eine kleine DLL programmieren und diese dann in PB verwenden. Leider wird die Funktion nicht so ganz exportiert wie ich es mir wünsche. Hier mal die Funktion, die exportiert werden soll:

Code: Alles auswählen

__declspec(dllexport) int TestFunk(int iA, int iB)
{
    int iResult;
    
    iResult = iA + iB;
    return iResult;
}
Ist noch ein Testcode. Die Funktion wird jetzt so exportiert: [c]_Z8TestFunkii[/c]. Ich hätte aber am liebsten es so, dass die Funktion so exportiert wird: [c]TestFunk[/c]. Wie bekomme ich das hin? Achja, ich verwende Dev-C++.

Re: Funktionen in C++ aus DLL exportieren

Verfasst: 23.07.2005 08:42
von Danilo
MVXA hat geschrieben:Die Funktion wird jetzt so exportiert: [c]_Z8TestFunkii[/c]. Ich hätte aber am liebsten es so, dass die Funktion so exportiert wird: [c]TestFunk[/c]. Wie bekomme ich das hin? Achja, ich verwende Dev-C++.
Da fehlt noch: extern "C"

Code: Alles auswählen

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#define ProcedureDLL(_return_type_) extern "C" __declspec (dllexport) _return_type_



  BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                         DWORD reason        /* Reason this function is being called. */ ,
                         LPVOID reserved     /* Not used. */ ) {
     /*
     switch (reason) {
        case DLL_PROCESS_ATTACH:
        case DLL_PROCESS_DETACH:
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
           break;
     }
     */

     /* Returns TRUE on success, FALSE on failure */
     return TRUE;
  }



  ProcedureDLL(int) iPlus(int iA, int iB) {
     return iA + iB;
  }



  ProcedureDLL(int) iMinus(int iA, int iB) {
     return iA - iB;
  }
TestCode:

Code: Alles auswählen

If OpenLibrary(0, "Super.DLL")
  Debug CallFunction(0,"iPlus" ,2,3)
  Debug CallFunction(0,"iMinus",8,5)
  CloseLibrary(0)
EndIf

Verfasst: 23.07.2005 15:04
von MVXA
Ich danke dir mein Held am Horizont :D