I am having trouble importing my C++ functions. If I declare them as C functions I can successfully import them. When explicit loading, if any of the functions are missing the extern as C decoration I get a the following exception:

```
First-chance exception at 0x00000000 in cpp.exe: 0xC0000005: Access violation.

```

**DLL.h:**

```
extern "C" __declspec(dllimport) int addC(int a, int b);
__declspec(dllimport) int addCpp(int a, int b);

```

**DLL.cpp:**

```
#include "DLL.h"
int addC(int a, int b) {
    return a + b;
}
int addCpp(int a, int b) {
    return a + b;
}

```

**main.cpp:**

```
#include "..DLL/DLL.h"
#include <stdio.h>
#include <windows.h>

int main() {
    int a = 2;
    int b = 1;
    typedef int (*PFNaddC)(int,int);
    typedef int (*PFNaddCpp)(int,int);

    HMODULE hDLL = LoadLibrary(TEXT("../Debug/DLL.dll"));

    if (hDLL != NULL)
    {
        PFNaddC pfnAddC = (PFNaddC)GetProcAddress(hDLL, "addC");
        PFNaddCpp pfnAddCpp = (PFNaddCpp)GetProcAddress(hDLL, "addCpp");
        printf("a=%d, b=%d\n", a,b);
        printf("pfnAddC: %d\n", pfnAddC(a,b));
        printf("pfnAddCpp: %d\n", pfnAddCpp(a,b)); //EXCEPTION ON THIS LINE

    }
    getchar();
    return 0;
}

```

How can I import c++ functions for dynamic loading? I have found that the following code works with implicit loading by referencing the \*.lib, but I would like to learn about dynamic loading.

Thank you to all in advance.

**Update:**
bindump /exports

```
1 00011109 ?addCpp@@YAHHH@Z = @ILT+260(?addCpp@@YAHHH@Z)
2 00011136 addC = @ILT+305(_addC)

```

**Solution**:

1. Create a conversion struct as
found [here](http://www.codeguru.com/cpp/w-p/dll/importexportissues/article.php/c123/Explicitly-Linking-to-Classes-in-DLLs.htm)
2. Take a look at the
file exports and copy explicitly the
c++ mangle naming convention.

PFNaddCpp pfnAddCpp = (PFNaddCpp)GetProcAddress(hDLL, "?addCpp@@YAHHH@Z");