Click here to Skip to main content
15,922,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have created one solution in VS2003 which contain two project one is ABD.exe and another one is ABC.DLL.
DLL class is declared as
C++
class __declspec(dllexport) Class Name


In DLL class, my entry point is
C++
unsigned int Convert(string, string)


From my another project, I am trying to call ABC.dll by using below code
C++
typedef unsigned int (*EntryPointfuncPtr)(string argv_1, string argv_2);

string Lib_File = "ABC.dll";
HINSTANCE LoadMe = LoadLibrary(Lib_File.c_str());

if(LoadME != NULL)
{
  EntryPointfuncPtr LibMain = (EntryPointfuncPtr)GetProcAddress(LoadMe, "Convert");
}

if (LibMain != NULL)
{
  unsigned int nRetVal = LibMain(strIn, strOut);
}
else
{
  cout << "ERROR OCCURED" << endl;
}


I am getting an Error Message : "ERROR OCCURED". This means that LibMain is Null.

Can anyone HELP me where I went wrong.?
Posted
Updated 15-Sep-11 22:55pm
v2
Comments
Mehdi Gholam 16-Sep-11 4:49am    
Is your dll file beside the exe file?
Does LoadMe have a value?
AJ83 16-Sep-11 4:52am    
yes LoadMe has a Value. It is not NULL. I have checked it.

All EXE and DLL are in same location.
Richard MacCutchan 16-Sep-11 5:25am    
You have not defined your function as extern but you are trying to access it as if it is. Take your function out of the class and define it correctly.
AJ83 16-Sep-11 5:29am    
Richard, my "convert" function is a part of class which is calling all other function declared in the class.

Basically, I have to export class bby using LoadLibrary(). Any Help!!
CPallini 16-Sep-11 5:46am    
Yes: please read the CodeProject article, I repeat the link below:
http://www.codeproject.com/KB/DLL/classesexportedusingLL.aspx

Probably the name of your function is mangled by the C++ compiler, you have to use the
C++
extern "C" {
//..
}

construct, see here[^] and here[^]to wrap your function.
 
Share this answer
 
Comments
Mehdi Gholam 16-Sep-11 4:53am    
Ah yes, my 5!
AJ83 16-Sep-11 5:01am    
When I used extern "C"
{
class __declspec(dllexport) Class Name
{
};
}

It did not work though.
CPallini 16-Sep-11 5:11am    
Why do you need the class? Cannot you just export the Convert function? Explicit DLL loading of C++ classes is a bit tricky (see for instance this article:
http://www.codeproject.com/KB/DLL/classesexportedusingLL.aspx
)
AJ83 16-Sep-11 5:23am    
Actually my application is in C++ which contain ABD.EXE and ABC.DLL.
Now ABC.DLL, I have to call from another application DSA.EXE.

That is why I need to have class as per requirement.
C++

Hi Pallini,

All of my function are declared in one class named as "ABC" and it's decelration is :
C++
class __declspec(dllexport) ABC
{
  public:
   Convert (string, string);
};


After you reply, i did like this:
C++
extern "C"
{
  class __declspec(dllexport) ABC
  {
    public:
     Convert (string, string);
  };
}


And rebuilt my dll but still LibMain is NULL

Any more suggestion or help?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900