_CrtlsValidHeapPointer(block) error when using opencv in c++ winforms application

asked 2016-02-21 06:28:35 -0600

valentine gravatar image

updated 2016-02-22 02:50:26 -0600

Dear All,

I am trying to use opencv with windows forms application to display an image. I created two extra classes. one as the model and other as the controller class. I imported opencv libraries in the model class, imported the modal class in the controller class and then the controller class in form.h. see code below` Model class

#include "opencv2\core\core.hpp";
#include "opencv2\imgproc\imgproc.hpp";
#include "opencv2\imgcodecs\imgcodecs.hpp"
#include "opencv2\highgui\highgui.hpp"
using namespace cv;
class ReadImage
      cv::String imagepath;
      Mat Image;
      ReadImage() :imagepath("C:/") {
      void ReadImage4rmfile() {
        Image = imread(imagepath);
      void setImagepath(cv::String mpath) {
        imagepath = mpath;
      void ShowImage() {
        imshow("ShowImage", Image);

Controller class:

#include "ReadImage.hpp"

   class ImageController
          ReadImage* rimage;
          ImageController(cv::String mpath) {
             rimage =  new ReadImage();
          void ImconShowImage() {
          ~ImageController() {
            delete rimage;


forms.h class:

#include "ImageController.hpp"
   private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
    System::String^ temp = textBox1->Text;
    IntPtr pointer_temp = Marshal::StringToHGlobalAnsi(temp);
    const char* input_location = static_cast<const char*>(pointer_temp.ToPointer());

    ImageController Imgcon = ImageController(input_location);


When i run the app i get the following error "Debug failed _CrtlsValidHeapPointer(block)" image description

The funny thing is the opencv settings such as the linker input and the likes was used on console application and it works well and using it winforms am getting this error.

please anyone can help.

edit retag flag offensive close merge delete