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
LoadLibrary() returning NULL
I am having a problem loading a run time dll, which I am attempting to do like so:
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
The specified module could not be found. ERROR_MOD_NOT_FOUND
Quote:Original post by DOrmisherTry using a full path. And make sure you use forward slashes in the path, or escape the backslashes.
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
If that still fails, show is the code you're using.
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.
Quote:Original post by dmailForward slashes work fine. From the documentation: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.
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.
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?
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 (/).
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 ); }}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement