Hello friends,

I created a simple dll. The code in the dll is :
Code:
extern "C" __declspec(dllexport)
int fact(int n)
{
	int i, fac;
	for(i = 2, fac = 1; i <= n; i++)
		fac*=i;
	return fac;
}
And i called the dll from this program:
Code:
#include <windows.h>
 #include <stdio.h>

 typedef int (WINAPI*function)(int);

 function fact;

 int main()
 {
	   int i=0;	  

	   HINSTANCE hLib=LoadLibrary("fact.DLL");


	   if(hLib==NULL) {

			printf("Unable to load library!");
			getchar();
			return 0;
	   }

	   char mod[50];

	   GetModuleFileName((HMODULE)hLib, (LPTSTR)mod, 50);
	   printf( "Library loaded: %s\n", mod );


	   fact=(function)GetProcAddress((HMODULE)hLib, "fact");
	   
	   if(fact==NULL)
	   {
			printf("Unable to load function fact...\n");
			FreeLibrary((HMODULE)hLib);
			getchar();
			return 0;
	   }
		
	   i = fact(5);								//call the function.
	   printf("The factorial of 5 is %d",i);  //should display 120.


	   FreeLibrary((HMODULE)hLib);
	   getchar();
 }
When i run this program, this error message comes up:
Code:
Run-Time Check Failure #0 - The value of ESP was not properly 
saved across a function call.
This came in the line:
Code:
 i = fact(5);
I dont know how to solve this one.
But the factorial is calculated correctly and displayed in the window as 120!

Please help me in solving this problem.
Thank You,
Paramesh.