Hi to all, I'm new here, I start reading the forum and you have help me, now I heve the following problem, hope you can help me
Thanks.
Now my problem:
I want to write a DLL that returns an Object
I write a function in the DLL, that returns the object(this is an object I create, it has its header and cpp files), the DLL project compiles and I receive an DLL file
//--------------------------------------------------------------------------
MyObject GetMyObject()
{
MyObject ObjectFromDLL();
return ObjectFromDLL;
}
//--------------------------------------------------------------------------
I also, write in the DLL project a Def file with:
//--------------------------------------------------------------------------
LIBRARY "ObjectDLL"
EXPORTS
GetMyObject @1
//--------------------------------------------------------------------------
* Until here, everytingh is OK, I think or I doing something wrong
An then comes the other project(exe, console) that uses the DLL, I did the following:
I define:
//--------------------------------------------------------------------------
typedef MyObject (CALLBACK* LPFNDLLFUNC1)(VOID);
HINSTANCE hDLL;
LPFNDLLFUNC1 MyFunc1;
And then:
///Load DLL
hDLL = LoadLibrary("C:\\DLL\\ObecjtDLL.dll");
if (hDLL != NULL)
{
MyFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"GetMyObject");
if (!MyFunc1)
FreeLibrary(hDLL);
else
MyObject test = MyFunc1();
}
//--------------------------------------------------------------------------
The console program compiles, but in the line "MyObject test = MyFunc1();", the program crashes, I receive the message:
//--------------------------------------------------------------------------
Debug Error!
Run-Timw Check Failure #0 - The value of ESP was not properly saved acrros a function call, This is usually a result of calling a function declared with one convention with a function pointer declared with different calling convetion.
//--------------------------------------------------------------------------
What I can do to makes this work, I really nedd your help, Thanks :eek: