By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,872 Members | 2,392 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,872 IT Pros & Developers. It's quick & easy.

MSDEV C - "debug error esp"

P: 1
Hello All,

I have been trying to fix the following problem; this bit of code works fine when it is compiled as part of a Windows application but when I move it out to a DLL I get the debug error - esp not saved etc. The error is obviously caused by some sort of stack problem but why in the DLL and not the application? Any ideas.

HINSTANCE h_instdll;
PROC func1;

h_instdll = LoadLibrary(dllname);
if (h_instdll == NULL)
{
handle error
}
func1 = GetProcAddress(h_instdll, funcname);

retval = func1(......); // generates esp error in DLL
Jun 18 '07 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
Your HINSTANCE should be HMODULE and your PROC should be FARPROC.

Other thna that, this code:
Expand|Select|Wrap|Line Numbers
  1. retval = func1(......); // generates esp error in DLL
  2.  
cannot compile because FARPROC cannot be used as a pointer to just any function.

Let's assume you function in the dll has this prototype:
Expand|Select|Wrap|Line Numbers
  1. void MyFunct(int);
  2.  
Then you would need to typecast the FARPROC returned by GetProcAddress to a pointer to a function that takes an int argument and returns a void:
Expand|Select|Wrap|Line Numbers
  1. void (*fp)(int) = (void(*)(int))retval;
  2.  
Also, I am assuming you are writinfg in C. If you are writing in C++, be sure to use extern "C" on your dll functions to turn off the C++ mangler or create a DEF file for the dll to export the mangled name under an alias.
Jun 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.