hi im developing a simple dll to learn win32 dll's, but when i run the test program an acess violation error is displayed by the operating system(windows xp), is not a compiler error because it compiles great,
here's the code
//dll header file dll2.h
Code:
//definicion de funciones y opciones para exportar las dll
#ifndef DLL2_H
#define DLL2_H
int number;
extern "C" int __stdcall square(int);
#endif
dll source code dllmain.cpp
Code:
#include "dll2.h"
int __stdcall square(int n)
{
number = n * n;
return number;
}
test program source test.cpp
Code:
#include <iostream>
using std::cout;
using std::endl;
#include <windows.h>
//pointer to function
typedef int(WINAPI* ptrFunc)(int);
int main(int argc, char *argv[])
{
HINSTANCE dllLib= 0;
ptrFunc funcion1 = 0;
dllLib = LoadLibrary("DLL2.DLL");
if(!dllLib){
cout << "No se pudo cargar DLL!" << endl;
return 0;
}
funcion1 = (ptrFunc)GetProcAddress(dllLib,"square");
//displays the square of 2
cout << funcion1(2) << endl;
FreeLibrary(dllLib);
return 0;
}
as i said above the program compiles just rigth but when i run it i have a memory error or something like that
if my function do not returns a value the program runs fine, i think the problem is when a function returns something from a dll function
any idea?
thanks for any help
and please excuse my poor english