sample run error(VC2008)

Microsoft Visual C++ Debug Library
Debug Assertion Failed!

Program: c:\OpenCASCADE6.5.3\samples\mfc\win32\vc9\bind\Geometry.exe
File: c:\opencascade6.5.3\samples\mfc\common\winmain.cpp
Line: 76

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
中止(A) 重试(R) 忽略(I)

nandy's picture

here pApp is NULL:

CWinApp* pApp = AfxGetApp();

int AFXAPI AfxWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)

// Redirection of standard output to console
int hCrt; BOOL rep; FILE *hf;
rep = AllocConsole();
hCrt = _open_osfhandle((long) GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT);
hf = _fdopen( hCrt, "w" );
*stdout = *hf;
// stop the buffer on stdout
// int i = setvbuf( stdout, NULL, _IONBF, 0 );
// filebuf ff(hCrt);
// cout = &ff;
cout<<"This Debug Window is defined in WinMain.cpp and will disappear in release mode"<AddPrinter (new Message_PrinterOStream ("OCCSampleRun.log", Standard_False));

ASSERT(hPrevInstance == NULL);

int nReturnCode = -1;
CWinApp* pApp = AfxGetApp();
// error here:pApp=NULL

Forum supervisor's picture

Dear lanhan,
The problem is not reproduced as in Debug as in Release mode.
'Geometry' sample starts and works properly.
Check, please building process once again (see for details 'readme.txt' file in root directory of
'mfc' based samples). Also I suggest you to check the built sample with Dependency Walker.

Andrew Hall's picture

I have also just had this issue, release built apps work, but debug built apps generate a failure to generate cwinapp error. I fixed this my running the msvc.bat vc9 win32 Debug first to set up the environment variables first before visual studio and then you can build one of the sample apps (I used modeling) and run it in debug mode.

Is there any way to setup the variables so you can build/run debug or release in developer studio without having to reset the environment variables and restart visual studio ?

p-carret's picture

I have excactly the same problem.
Sample can run in Release mode.
I think it comes from Debug Window (Console)

For a better use and stability in packages, here are 2 proposals :

1°) Do not change OCC tree organisation anymore

It surely work on OCC Developer machine because everything is correctly set
all changes in OCC tree structure does not help :
old "ros" folder name
3rdparty to each lib folder

2°) Suppress Environment Variable use

all setup with environnent variables is a headache because we do have current production version (6.2.0) and we want to test new version (6.7.0)
For each change with envvar you need a DevStudio restart
I've tried the .bat with no success

I'm sure it's pretty hard for OCC team because OCC is cross-platform, but it does not help us to follow the release seamlessly

Even though, thanks for your great work

Choi, Won-Hyuk's picture

I also experienced this problem. It seems a problem of environment variable, but I couldn't find the cause. Anyway I found that by below copying, I can work around this problem and can run the sample in debug mode.

source: ~\opencascade-6.7.1\samples\mfc\standard\win32\vc9\libd\mfcsample.dll
target: ~\opencascade-6.7.1\samples\mfc\standard\win32\vc9\bind\