Question

I have an VC++ win 32 application which compiles into an EXE. But now I want to convert it into dll so that I can load that in another application.I tried changing in Visual Studio properties from .EXE to .DLL which successfully converted it but whn i use GetProcAddress it always returns NULL . I am not sure what I am doing is right or wrong .

Basically this what I want to achieve :

  1. I want to link project 1 and project2
  2. Project 2 should be able to invoke the functions of project1(which is an exe currenlty)

EDIT Hi guys thanks for your input .I told what you guys said . even then my GetProcAddress returns zero . Am i am doing anything wrong .Shown my dll loading code below .

HINSTANCE LoadMe  =  LoadLibrary( _T("D:\\VC++Project\\CVAList\\CVAList\\ExportTest.dll"));

   if (LoadMe != 0)
    printf("LoadMe library loaded!\n");
    else
     printf("LoadMe library failed to load!\n");


   EntryPointfuncPtr LibMainEntryPoint;   
   LibMainEntryPoint = (EntryPointfuncPtr)GetProcAddress(LoadMe,"PrintFloatsVal");
   LibMainEntryPoint (a1 ,a,b,c,d ); // 4 double 

EDIT DLL Export Code

#define DllExport   __declspec( dllexport ) 


DllExport  void  PrintFloatsVal ( int amount, double &d1 ,double &d2 , double &d3 ,double &d4)
{
....
..
}
Was it helpful?

Solution

You need to export the functions you wish to access using the __declspec dllexport keyword.

So if you add the manifest constant 'BUILDING_MY_DLL' to the project, the header file that declares the functions you care about can be used in both the DLL project and any code that uses the DLL:

#ifdef BUILDING_MY_DLL
#define MY_DLL_EXPORT __declspec dllexport
#else
#define MY_DLL_EXPORT __declspec dllimport
#endif

And decorate the functions you wish to export:

MY_DLL_EXPORT BOOL Func1(int a);

If the function you wish to access is implemented in C++ it will be decorated, for the purposes of function overloading and other purposes, and it best accessed directly like any other function. If you wish to use GetProcAddress() however you are better off giving it C-linkage by surrounding the function with extern "C" { ... }. This will make the exported name the same the name used within the code.

Reference: http://msdn.microsoft.com/en-us/library/a90k134d(v=vs.80).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top