[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

MFC and Shell Assert errors

Posted on 2000-02-05
5
Medium Priority
?
500 Views
Last Modified: 2013-11-20
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

0
Comment
Question by:dirtdart
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:NT_Programmer
ID: 2494316
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
 
LVL 5

Author Comment

by:dirtdart
ID: 2494689
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
 
LVL 1

Expert Comment

by:NT_Programmer
ID: 2494829
What OS are you running on?
0
 
LVL 1

Accepted Solution

by:
NT_Programmer earned 800 total points
ID: 2494841
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
 
LVL 5

Author Comment

by:dirtdart
ID: 2496610
Sounds like a weiner to me.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses
Course of the Month7 days, 14 hours left to enroll

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question