Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

AFX_MANAGE_STATE(AfxGetStaticModuleState()) needs to be taken  out

Posted on 2006-06-07
11
Medium Priority
?
844 Views
Last Modified: 2013-12-03
Hi all,
  I got a question that has been bothering me for a long time now. I have 4 builds....debug, unicode debug, release, and unicode release. The macro
"AFX_MANAGE_STATE(AfxGetStaticModuleState())" works fine for all the builds except
unicode release. In order for unicode release to work, I need to take that macro out. Has anyone ever seen this before, or is it just indiginous to my application???

500 pts.

thanks
0
Comment
Question by:Joe_Banks_217
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16859026
I think if you remove that line then your unicode release version ought to be likely to fail in use.

Are you using any other special flags for the unicode release that you don't for the other builds?
0
 

Author Comment

by:Joe_Banks_217
ID: 16861249
no i don't think so andy. what do you think could be causing this?

0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16861338
From a dll generated by the MFC wizards.

//
//      Note!
//
//            If this DLL is dynamically linked against the MFC
//            DLLs, any functions exported from this DLL which
//            call into MFC must have the AFX_MANAGE_STATE macro
//            added at the very beginning of the function.
//
//            For example:
//
//            extern "C" BOOL PASCAL EXPORT ExportedFunction()
//            {
//                  AFX_MANAGE_STATE(AfxGetStaticModuleState());
//                  // normal function body here
//            }
//
//            It is very important that this macro appear in each
//            function, prior to any calls into MFC.  This means that
//            it must appear as the first statement within the
//            function, even before any object variable declarations
//            as their constructors may generate calls into the MFC
//            DLL.
//
//            Please see MFC Technical Notes 33 and 58 for additional
//            details.
//

Removing that line *could* be very dangerous.


Your problem - I've not encountered it.  Are you using any other special flags for the unicode release that you don't for the other builds?  (Check your project settings - specifically the 'release' and the 'unicode release' versions)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Joe_Banks_217
ID: 16862224
Andy, what do you mean by special flags? Like preprocessor directives?
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16862248
yes.
0
 

Author Comment

by:Joe_Banks_217
ID: 16862778
Andy, could the problem be  because the project has both atl and mfc in it?
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16863603
? - but why should it work in debug and non-unicode versions?

If the settings are the same for debug and release then I have no other ideas at present.
0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 1500 total points
ID: 16867839
Have you specifically checked if the unicode release is using the shared or the static libraries?
0
 

Author Comment

by:Joe_Banks_217
ID: 16871936
Andy, what would shared or static libraries have to do with it?
0
 

Author Comment

by:Joe_Banks_217
ID: 16874522
I found this article.

http://www.codeguru.com/cpp/com-tech/atl/atl/article.php/c55/

I kind of thought that it was applicable because it mentions that AfxGetApp() would not work right in such an application. In my application,  two main reasons why the unicode release crashes
are 1) AfxGetApp()->GetProfileString either crashes the program or fails and 2) the interface functions we call crash. However, I still don't really understand the problem, or for that matter how to solve it.




0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16875712
static/shared linkage.

//          If this DLL is dynamically linked against the MFC         <<------------------ It seems to say only required for shared linkage
//          DLLs, any functions exported from this DLL which
//          call into MFC must have the AFX_MANAGE_STATE macro
//          added at the very beginning of the function.



2) the interface functions we call crash.  
I think this is due to you removing this line AFX_MANAGE_STATE(AfxGetStaticModuleState())
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

610 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