Jump to content
  • Advertisement
Sign in to follow this  
DOrmisher

LoadLibrary() returning NULL

This topic is 3631 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

I am having a problem loading a run time dll, which I am attempting to do like so:
HMODULE hMod = LoadLibrary( L"DLL_Negative.dll" );
function = (IMGFUNC) GetProcAddress( hMod, "DLL_Negative" );
function( m_Image );
I add a breakpoint at the line after LoadLibrary() call, and add a watch to the hMod, but the LoadLibrary keeps returning NULL. The project is an MFC app, so I tested the same code in a simple win 32 console app with the same dll, which worked. I have tried including the full file path, which won't work, and I have even tried to load a dll from the windows system folder, which also returns NULL. I have placed the dll in all the file locations i can think of, all to no avail. The windows.h header is included. Is there something different that must be done when loading a dll in this way when in an MFC application? Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
I've just checked win32 error codes (I'm assuming thats what it is) and it the error is:

The specified module could not be found. ERROR_MOD_NOT_FOUND

Share this post


Link to post
Share on other sites
Quote:
Original post by DOrmisher
I've just checked win32 error codes (I'm assuming thats what it is) and it the error is:

The specified module could not be found. ERROR_MOD_NOT_FOUND
Try using a full path. And make sure you use forward slashes in the path, or escape the backslashes.

If that still fails, show is the code you're using.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
And make sure you use forward slashes in the path

I think you mean backslashes here steve see the docs.

This may not be that it can not find your dll yet that your dll's dependencies(mfc), try running it through depends and seeing if you can get more info.

Share this post


Link to post
Share on other sites
Quote:
Original post by dmail
Quote:
Original post by Evil Steve
And make sure you use forward slashes in the path

I think you mean backslashes here steve see the docs.
Forward slashes work fine. From the documentation:
Quote:
Note File I/O functions in the Windows API convert "/" to "\" as part of converting the name to an NT-style name, except when using the "\\?\" prefix as detailed in the following sections.
Personally, I always use forward slashes, since it's less error prone.

Share this post


Link to post
Share on other sites
When I created the dll I used a win32 dll project, will this make any difference? Do you need to create an MFC DLL project for it to load correctly in an MFC app?

Share this post


Link to post
Share on other sites
That maybe so Steve but I would think the note in LoadLibrary docs over rides that
Quote:

http://msdn.microsoft.com/en-us/library/ms684175.aspx
When specifying a path, be sure to use backslashes (\), not forward slashes (/).

Share this post


Link to post
Share on other sites
and yeah I already tried using full path name with double backslashes, there's no point showing you all the code from the source file as it is the source file for a dialog, here's the event handler where I try to load the dll:


void CAssignmentDlg::OnBnClickedButtonApply()
{
HMODULE hMod;
IMGFUNC function;

if( m_TransformCombo.GetCurSel() == 1 )
{
CBrightnessDialog brightDialog;
brightDialog.DoModal();
}
if( m_TransformCombo.GetCurSel() == 2 )
{
hMod = LoadLibrary( L"DLL_Negative.dll" );
DWORD error = GetLastError();
function = (IMGFUNC) GetProcAddress( hMod, "DLL_Negative" );
function( m_Image );
}
}

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!