MFC and Shell Assert errors

I am attempting to write a small dialog based MFC program that uses the SHGetValue to check a registry value.  However, whenever I include shlwapi.h and link with shlwapi.lib, the program crashes before it can even get started with the following error:

Debug Assertation Failed!

Program: D:\depmake.exe
File: afxwin1.inl
Line: 22

When debugging, I can't even step to the first line of the code before getting this error.  If I click the retry button to get to the source, it fails on the following line:

_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
      { ASSERT(afxCurrentResourceHandle != NULL);

Does anyone know of a cure for this action?  I could really care less about using the SHGetValue function, but I'd hate to be excluded from using any shell functions simply because I'm using MFC (once again an indication of how poorly planned MFC is).

Thanks

LVL 5
dirtdartAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NT_ProgrammerCommented:
I would suggest trying the Reg type functions like:
RegOpenKeyEx
RegQueryValueEx

etc... That's the Win32 way to access registry values from _any_ Win32 program

The function SHGetValue is only for NT 5 (Windows 2000).
0
dirtdartAuthor Commented:
That is a good suggestion, and it's what I ended up doing with this program, but it doesn't solve the problem.  The program didn't crap out because of that function, it crapped out because I linked it with shlwapi.lib.
0
NT_ProgrammerCommented:
What OS are you running on?
0
NT_ProgrammerCommented:
The AfxGetResourceHandle is bombing because your app is trying to link in Shlwapi.dll but it can't find it in your system.  When you use the "Shell" functions, and link with Shlwapi.lib that puts a import block in the .idata segment of your exe.  This .idata segment instructs the OS to load the Shlwapi.dll into your process before it runs.  It can't find the Shlwapi.dll in your system, so it doesn't load.  There is also some code in the Shlwapi.lib that runs before your code does that checks to see if the dll loaded ok.  If it doesn't it asserts.  So the answer to get your app from hitting this assert is to not use the "Shell" functions and do not link in the Shlwapi.lib.

So to solve your problem, take the link instruction out and use the "Reg" style functions to access the registry.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dirtdartAuthor Commented:
Sounds like a weiner to me.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.