'Windows error while writing graphic codes in Code Blocks. How to fix it?

I am having trouble using graphics.h in code blocks.

I have installed winbgi. Edited 302nd line. Linked lib file and all that stuff is done. So, I don't have any error regarding graphics header file.

But whenever I run/build any code involving graphics functions, windows gives an error ".. has stopped working". How to fix this?

I am using Codeblock v16. Windows 7ultimate - 64bit.

Here is my code:

#include<graphics.h>
int main() {
   int gd = DETECT,gm;

   initgraph(&gd, &gm, "c:\\tc\\bgi");

   line(80, 100, 100, 100);
   getch();
   //return 0;
}

screenshots:

screenshot of codeblock window

Screenshot of Error window



Solution 1:[1]

[SOLVED]

Unfortunately, it was all about 'bad' library files. I think, many have downloaded same(with bug) files in internet. Now I have bug-free files shared in google drive. And also Code::Blocks 16.01 (latest version)

Here's link. Replace old files with these new ones.

I have explained those steps and few FAQs here on this topic with links and test codes.

Solution 2:[2]

use of DosBox for emulate MS-DOS in Windows7.

just i can help you with bellow link, its useful.

See : How use of DOSBox in Windows 7

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LearningSinceBigBang
Solution 2 BattleTested_закалённый в бою