Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem calling a dll

Status
Not open for further replies.

amarti44

Programmer
Feb 16, 2001
23
0
0
US
I'm having problem calling a dll that I created having an entry point like this:

void _stdcall Entry_Point_Function(unsigned char *input, int count, unsigned char *Output)
{
Function1(Input, count);
Function2(Output);
}

Some of the internal functions in the dll are declare as static.

In the host application, the main function calls the dll like this:


typedef void (*FUNCPROC)(unsigned char *, int, unsigned char *);

int main()
{
HINSTANCE hinstLib;
FUNCPROC func_proc;

unsigned char *Input = "data";
int count = 4
unsigned char *Output;

Output = malloc(count * sizeof(unsigned char));

hinstLib = LoadLibrary("mydll");

if (hinstLib != NULL) {
func_proc = (FUNCPROC) GetProcAddress(hinstLib, "Entry_Point_Function");
if (func_proc != NULL){
(func_proc)((unsigned char *)Input, (int) count, (unsigned char *)Output);
}
else {
printf("Failed to get the function.\n");
return 1;
}
}
/* Free the DLL module.!!! */
FreeLibrary(hinstLib);
}
else {
printf("Can't load the library.\n");
return 2;
}
return 0;
}

But when I run the host executable I had this error message:
Degug Error!
Program ........\testdll.exe
Module:
File: i386\chkesp.c
Line: 42

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.

Even with that, if a press Ignore, I got the right output. But then, a fatal exception error window is displayed. I debuged the dll using the host application and the dll return the right answer. Just when I try to move to the next instruction in the host application. the error appears.
I run my code not as a dll but a normal project with the same calling function that I use as the Entry Point of the dll and everything runs find.

Any suggestion...???
 
Try this:
- replace _stdcall with __stdcall. the difference is that some compilers are converting this mopdifier into slightly different assembler code
- take away the _stdcall, or replace it with __cdecl or even with __fastcall. (I know you probably want to keep the stdcall for compliance withy VB's calling conventions or with COM's)

Anyway the problem that you have comes from the modifier for sure.

Ah, one more thing, try to export the functions from the dll with a .DEF file and use: extern __declspec(dllexport)

Hope this helps,
s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top