Failing to call exported DLL function - HELP!
Kevin McConnell -- kevin@tigger.demon.co.uk
Wednesday, October 09, 1996
Environment: Win 95 VC++ 4.1
I have an app which uses a number of "forms", which are actually DLLs. The
DLLs contain three functions, but one of these functions does not appear to
be being called (in any of the DLLs). I do not get any error messages at
all, only that my main app doesn't work properly as a result, and I can't
see any difference with the "broken" function.
The forms work fine when built under VC 2, my guess is that I'm doing
something dodgy in the way I'm calling the functions and I was just lucky
before! I've had to experiment with the code, now, to try and get it
working.
The broken function is called "GetVersion", and it looks like:
void __declspec(dllexport) GetVersion(int FAR *number, int FAR *version,
char FAR *copyright, char FAR *name)
{
..
AfxMessageBox("why am I never called?");
strcpy(name, "Test");
..
}
And the main app uses it along the lines of...
typedef void (*PFUNC) (int *, int *, char FAR *, char FAR *);
m_FormHandleArray[counter].GetVersion=
(PFUNC) GetProcAddress(m_FormHandleArray[counter].Library,"GetVersion");
m_FormHandleArray[counter].GetVersion(
(int *) &Number, (int *) &Version,
(char *) Copyright, (char *) FormName);
The when the app calls the function, as above, the AfxMessageBox does not
appear, and the strcpy has had no effect on the contents of "FormName".
Any help would be appreciated, thanks.
Kevin McConnell
Mike Blaszczak -- mikeblas@nwlink.com
Thursday, October 10, 1996
[Mini-digest: 2 responses]
At 19:01 10/9/96 +0100, Kevin McConnell wrote:
>Environment: Win 95 VC++ 4.1
>The broken function is called "GetVersion", and it looks like:
>void __declspec(dllexport) GetVersion(int FAR *number, int FAR *version,
>char FAR *copyright, char FAR *name)
Why do you use "FAR"? It is obsolete.
>And the main app uses it along the lines of...
>
>typedef void (*PFUNC) (int *, int *, char FAR *, char FAR *);
This function prototype doesn't match the prototype you're using above. The
one above has FAR's on the integer pointers, too.
>m_FormHandleArray[counter].GetVersion=
> (FUNC) GetProcAddress(m_FormHandleArray[counter].Library,"GetVersion");
Do you check the return value of GetProcAddress()? What's it say? The handle
you're passing is valid, too, right?
>m_FormHandleArray[counter].GetVersion(
> (int *) &Number, (int *) &Version,
> (char *) Copyright, (char *) FormName);
What's with all the casts? That's dangerous. You're casting to types that
don't match the function prototype, too--you don't have FAR's. They should be
meaningless, but cleaner code makes it easier to spot problems.
>The when the app calls the function, as above, the AfxMessageBox does not
>appear, and the strcpy has had no effect on the contents of "FormName".
What happens when you use the debugger? It's a bit surprising to me that you
haven't explained what's going on when you trace into the function using the
debugger. (Did you even try to debug this yourself?) What assembler code is
generated by the compiler for your call? Are you sure you correctly copied
current versions of the DLL to where they should be?
.B ekiM
http://www.nwlink.com/~mikeblas/
Don't look at my hands: look at my _shoulders_!
These words are my own. I do not speak on behalf of Microsoft.
-----From: David Little
Are you sure that GetProcAddress returns an address? Did you use =
DUMPBIN to make sure that it is exported? Also, you can get rid of the =
FAR...You don't need it in a flat address space.
| Вернуться в корень Архива
|