Search code examples
c++cpdcurses

PDCurses TUI C++ Win32 console app - Access violation reading location


I have downloaded pdcurses source and was able to successfully include curses.h in my project, linked the pre-compiled library and all good.

After few hours of trying out the library, I saw the tuidemo.c in the demos folder, compiled it into an executable and brilliant! exactly what I needed for my project.

Now the problem is that it's a C code, and I am working on a C++ project in VS c++ 2008.

The files I need are tui.c and tui.h How can I include that C file in my C++ code? I saw few suggestions here

but the compiler was not too happy with 100's of warnings and errors.

How can I go on including/using that TUI pdcurses includes!?

Thanks

EDIT:

I added extern "C" statement, so my test looks like this now, but I'm getting some other type of error

#include <stdio.h>
#include <stdlib.h>
using namespace std;

extern "C" {
   #include <tui.h>
}

void sub0()
{
    //do nothing
}

void sub1()
{
    //do nothing
}


int main (int argc, char * const argv[]) {

    menu MainMenu[] =
    {
        { "Asub", sub0, "Go inside first submenu" },
        { "Bsub", sub1, "Go inside second submenu" },
        { "", (FUNC)0, "" }   /* always add this as the last item! */
    };
    startmenu(MainMenu, "TUI - 'textual user interface' demonstration program");

    return 0;
}

Although it is compiling successfully, it is throwing an Error at runtime, which suggests a bad pointer:

0xC0000005: Access violation reading location 0x021c52f9

at line

startmenu(MainMenu, "TUI - 'textual user interface' demonstration program");

Not sure where to go from here. thanks again.


Solution

  • Finally got it working. The solution was in the steps below:

    First I renamed tui.c to tui.cpp

    For the header tui.h, I followed the exact same step of wrapping the code as described here.

    then in my project i just included the header without any extern "C" block

    #include "tui.h"
    

    Compiled and it worked!