Zugriffsverletzung-Ausnahme bei Verwendung einer DLL-Funktion

Habe ich eine einfache DLL, die als Teil meiner C++ - übungen, aber ich bin immer eine access violation exception beim Aufruf von DLL-Funktion. Hier ist die DLL-header-Datei(ich bezweifle, dass der CPP wird nützlich sein hier):

#pragma once

namespace MathFuncs
{
class MyMathFuncs
{
public:
    //Returns a + b
    static __declspec(dllexport) double Add(double a, double b);

    //Returns a - b
    static __declspec(dllexport) double Subtract(double a, double b);

    //Returns a * b
    static __declspec(dllexport) double Multiply(double a, double b);

    //Returns a /b
    //Throws DivideByZeroException if b is 0
    static __declspec(dllexport) double Divide(double a, double b);
};
}

Und hier ist mein main:

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

using namespace std;

int main(void)
{
    double (__cdecl *MYPROC)(double,double);
    /* get handle to dll */
    HINSTANCE hGetProcIDDLL = LoadLibrary("DLLExample.dll"); 
if(hGetProcIDDLL == NULL)
    throw;
   /* get pointer to the function in the dll*/
    FARPROC lpfnGetProcessID = GetProcAddress(hGetProcIDDLL,"Add"); 
    if(lpfnGetProcessID)
        throw;
    MYPROC = (double (__cdecl *)(double,double))lpfnGetProcessID;
    if(MYPROC)
        throw;

    double x = MYPROC(5.5,5);

    return 0;
}

Irgendwelche Vorschläge? Danke!

  • Ist die DLL im gleichen Ordner, wo dein main-Programm ausgeführt wird?
InformationsquelleAutor RiskX | 2012-09-14
Schreibe einen Kommentar