I first tried to run a simple program before writing a code for my hardware. Following is the code
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void _stdcall Out32(short PortAddress, short data);
int main(void)
{
Out32(0x37A,0x00A); //I have linked my program to inpout.lib for Out32()'s definition.
return 0;
}
But when I changed the code to this
Code:
#include <Windows.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
typedef void (* Out32)(short PortAddress, short data);
int main(void)
{
Out32 out;
HINSTANCE HLib;
HLib=LoadLibrary(L"F:/inpout32.dll");
if(HLib==NULL)
{
printf("Error loading Library");
return 0;
}
out=(Out32)GetProcAddress(HLib,"Out32");
if(out==NULL)
{
printf("Error loading function");
return 0;
}
out(0x37A,0x00A);
FreeLibrary(HLib); // <- error is occurring first at this line
return 0; // <- then after pressing continue same error occurs at this line
}
It started giving a new error!
"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."