• ### Popular Now

• 12
• 12
• 9
• 10
• 13

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

## 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 on other sites
What does GetLastError return?

##### Share on other sites
The error code is 126, but where do I find out what that means?

##### Share on other sites
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 on other sites
Quote:
 Original post by DOrmisherI'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 on other sites
Quote:
 Original post by Evil SteveAnd 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 on other sites
Quote:
Original post by dmail
Quote:
 Original post by Evil SteveAnd 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 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 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.aspxWhen specifying a path, be sure to use backslashes (\), not forward slashes (/).

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 );	}}