I am still trying to resolve the problem I described in this thread where I basically have a DLL written in native C and want to develop a wrapper function for it and call the C functions from within a C++ application. The solution described in that thread works, but it requires me to modify my original C DLL's files (which I don't want to because I have a lot of them, and not all of them compile on Windows), so I am trying to find a way that allows me to make direct calls to the functions of the DLL without having to dllexport/import...etc.

I found this and I thought I could try it out. I did basically the same thing as before.

My DLL is coded as follows

#include "addition.h"
#include <stdio.h>

int add(int x, int y){
return x+y;

My wrapper project, hereafter I'm calling it MyProject consists of just MyProject.cpp:

#include <Windows.h>
#include <iostream>

using namespace std;

int CallMyDLL(void) 
    /* get handle to dll */ 
   HINSTANCE hGetProcIDDLL = LoadLibrary("C:\\AdditionDLL.dll"); 

   /* get pointer to the function in the dll*/ 
   FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"add"); 

      Define the Function in the DLL for reuse. This is just prototyping the dll's function. 
      A mock of it. Use "stdcall" for maximum compatibility. 
   typedef int (__stdcall * pICFUNC)(int, int); 

   pICFUNC add; 
   add = pICFUNC(lpfnGetProcessID); 

   /* The actual call to the function contained in the dll */ 
   int intMyReturnVal = add(4, 5); 

   /* Release the Dll */ 

   /* The return val from the dll */ 

int main(){
int res=0;
res = CallMyDLL();
cout << "The result is ";
cout << res;

Both codes compile with no errors. I have copied and pasted the AdditionDLL.dll in the C:// directory. But when I run the program, I get Unhandled exception access violation. What's the problem?

5 Years
Discussion Span
Last Post by beaute

GetProcAddress() probably returned a NULL pointer.

The spelling and case of a function name pointed to by lpProcName must be identical to that in the EXPORTS statement of the source DLL's module-definition (.def) file.

Notice the functions still must be exported.

Edited by Ancient Dragon: n/a


You had to do these:
at dll Project:

int __stdcall add(int x, int y);

1.2-add def file With:

LIBRARY	"addition"

Edited by mazzica1: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.