i have big error in my c++ program ?

hello,

my code  was written in c++  and  after i changed the charter set  to  Use Unicode Character Set

it compiled correct

but when  i run the application  it crashes and appear this error

unhandled exception at 0x0047 cdc in .exe 0xC0000005: Access violation reading location 0x00000000

please can  any one help ??

thank  you
LVL 1
sa3qAsked:
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.

phoffricCommented:
Are you able to post the code (maybe a whittled down version that still crashes).Possibly a null pointer?
0
ZoppoCommented:
Hi sa3q,

this most probably indicates accessing a invalid (not-initialized) pointer. Without knowledge of your code we have no chance to really help you.

Using the debugger you should be able to find the place in your code where this happens. If you found the place please post the code where the crash happens.

ZOPPO

0
phoffricCommented:
If you build and run in Debug mode, and you get the unhandled exception popup. If you hit the Break button, then the debugger may take you to the location of the crash, where you may be able to inspect the local variables. If you do see a pointer in that vicinity, then you can test for NULL and throw an exception which you can trap with the debugger. (For more information on this, see http://www.experts-exchange.com/Programming/Languages/CPP/A_3530-Breakpoint-Tips-for-C-C-Visual-Studio-2008-Debugger-Part-2.html)
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

sa3qAuthor Commented:
i made message box  in first line  on   the main    

but the crash  appear before the message box

int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
//int main()
{
MessageBox(NULL, (LPCWSTR)"1", (LPCWSTR)"bonjour(s)", MB_OK);

Open in new window

0
ZoppoCommented:
Hi sa3q,

IMO you have to declare hardcoded strings different for use with UNICODE instead of just casting them to 'LPCWSTR' - use the '_T' macro, i.e:

> MessageBox(NULL, _T( "1" ), _T( "bonjour(s)" ), MB_OK);

ZOPPO
0
sa3qAuthor Commented:
i tried  to  compile it in  debug mode  and run  it    and  the debuger show to  me where the error

the file that have the problem is not of min  
it in  winmain.cpp

in this line  

if (!pThread->InitInstance())
0
phoffricCommented:
And what do you find is the value for pThread? Is it 0?
0
sa3qAuthor Commented:
this print scr
rror.png
0
phoffricCommented:
It shows pThread is NULL (i.e., 0x00000000). Somehow, when you made changes, it appears that pThread did not get initialized properly. When you initialize pThread, are you checking for errors? Set a breakpoint on the line where pThread is set, and see if you even get there.
0
AndyAinscowFreelance programmer / ConsultantCommented:
>>after i changed the charter set  to  Use Unicode Character Set

See the comment by ZOPPO - you are casting an ANSI string to a wide char string - WRONG !!!!
0
sa3qAuthor Commented:
this in the deceleration  
rror.png
0
sa3qAuthor Commented:
i commented all  the code in  the main  

and try the debug

the same error  

because pThread  in 0000000000
0
phoffricCommented:
Did you try the advice given by zoppo in http:#33453241 ?

Here's one result of researching your problem:
"The crux of the problem was that someone had accidently commented the global CWinApp constructor."
    http://blogs.msdn.com/b/dsvc/archive/2009/06/21/why-afxgetthread-returns-null-in-afxwinmain.aspx

0
ZoppoCommented:
Hm - IMO pThread can only be NULL if initialization fails for any reason. Do you see any messages in the output window like i.e. 'Warning: Error during thread initialization!' or something else which could give any indication about the problem?

And, another question: Do you have more strings in your code which aren't declared using '_T( ... )' or casted as you did in the 'MessageBox'-call?

ZOPPO

0
sa3qAuthor Commented:
Zoppo:
phoffric:
the main is empty    and  the error  appear  it  appears after  i change  character  set  to  unicode

0
ZoppoCommented:
> the main is empty
What do you mean?

With the first question in my last post I meant this: If you start your application directly within the Debugger (Menu 'Debug->Start Debugging') do you see any messages in the 'Output' window after the crash occured?

With the second question (about the '_T') I tried to find if at any place a hardcoded string is declared in a way it cannot be used as UNICODE string - if so this could explain why the crash 'appears after  i change  character  set  to  unicode ' ...
0
sa3qAuthor Commented:
i mean in empty  that the code only have  

int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
return 0;
}
0
AndyAinscowFreelance programmer / ConsultantCommented:
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)

That declares the lpCmdLine to be ANSI, not UNICODE

int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,int nCmdShow)



But why do you have this declaration?  What type of application are you trying to develop ?
0
sa3qAuthor Commented:

AndyAinscow:


i used
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,int nCmdShow)

but their  was problem
 error C2731: 'WinMain' : function cannot be overloaded
0
ZoppoCommented:
You cannot use 'WinMain' with UNICODE.

Take a look here: http://msdn.microsoft.com/en-us/library/ms633559%28VS.85%29.aspx

> Note that lpCmdLine uses the LPSTR data type instead of the LPTSTR data type. This means that WinMain
> cannot be used by Unicode programs [...] Some programming frameworks might provide an alternative entry
> point that provides a Unicode command line. For example, the Microsoft Visual Studio C++ complier uses the
> name wWinMain for the Unicode entry point.

So, if you need to write your own 'WinMain' you have to use 'wWinMain' instead ...

ZOPPO
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
AndyAinscowFreelance programmer / ConsultantCommented:
What are you trying to do?  What sort of application do you want to develop?

You say it was changed to UNICODE then problems started.  Why do you now try to modify the 'main' of the application?  Just making random changes won't cure the problems (unless you are very lucky).
0
sa3qAuthor Commented:
thank you  all


0
sa3qAuthor Commented:
that's it  thank  you

0
ZoppoCommented:
Hm - IMO you should have given points to AndyAinscow too since he first pointed out that 'WinMain' is the problem in http:#33453752
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
Editors IDEs

From novice to tech pro — start learning today.