Jump to content
  • Advertisement
Sign in to follow this  
Oobydoobyscoobydo

Calling DLL export. Access error

This topic is 3668 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello ! I've got a strange error and have no idea how to move on. I'm getting a function address as follows : FunctionFunc _FunctionFunc; HINSTANCE hInstLibrary = LoadLibraryEx(_T"C:\\My.dll"),0,DONT_RESOLVE_DLL_REFERENCES); if (hInstLibrary){ _FunctionFunc = (FunctionFunc)GetProcAddress(hInstLibrary,"RTGHit"); if (_FunctionFunc){ _FunctionFunc(); } FreeLibrary(hInstLibrary); } else{ DWORD reply = GetLastError(); } and this works fine and retrieves the correct function address. The code jumps to the function in the dll correctly (monitored in debug), but when actioning the first instruction it fails with an read access violation. The statement is just an outputdebugstring. why is this ?

Share this post


Link to post
Share on other sites
Advertisement
What happens if you just use LoadLibrary() instead of LoadLibraryEx()? And are you sure that your FunctionFunc function pointer is the same type as the function being exported, particularly with respect to calling conventions (I.e. are they both __stdcall or both __cdecl)?

EDIT: DONT_RESOLVE_DLL_REFERENCES looks suspicious. That tells the OS not to load any other DLLs that DLL needs - which you almost certainly don't want to do.

Share this post


Link to post
Share on other sites
Yeah I'm with Evil Steve, my money is on this being a calling convention mismatch. Either that, or the signature used for "FunctionFunc" is otherwise different from the signature of the function exported by the DLL. If you don't mind, could post both of those here? (using the code tags, please)

Share this post


Link to post
Share on other sites
Thanks for the prompt reply.

Yes, I started with LoadLibrary then when it didn't work i've been playing around with other things hence the LoadLibraryEx !

The exported function in the dll is shown below and the line below it shows the typdef of the calling function


extern "C" __declspec(dllexport) void RTGHit();



typedef void (*FunctionFunc)();



[Edited by - Oobydoobyscoobydo on July 31, 2008 10:27:25 AM]

Share this post


Link to post
Share on other sites
woohoo fixed it !

thanks for your help guys - as you advised calling convention was wrong
corrected to

extern "C" __declspec(dllexport) void *RTGHit();

and now works a treat. THANKS

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!