PDCurses TUI C ++ Win32 Console Application - Read Access Violation Location

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

After hours of testing the library, I saw tuidemo.c in the demos folder, compiled it into an executable file and brilliantly! exactly what i need for my project.

Now the problem is that this is C code, and I'm working on a C ++ project in VS C ++ 2008.

I need tui.c and tui.h ​​files. How to include this C file in my C ++ code? I saw some suggestions here

but the compiler was not happy with 100 warnings and errors.

How can I enable / enable the use of TUI pdcurses ??

thanks

EDIT:

I added the extern expression β€œC”, so my test now looks like this, but I get some other type of errors

#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 compiles successfully, it throws an error at runtime, which indicates a bad pointer:

 0xC0000005: Access violation reading location 0x021c52f9 

in line

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

Not sure where to go from here. Thanks again.

+1
c ++ c pdcurses
source share
2 answers

Finally, he worked. The solution was in the following steps:

First I renamed tui.c to tui.cpp

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

then in my project I just included the header without the external block "C"

 #include "tui.h" 

Compiled and it will work!

0
source share

If I'm not mistaken (and I could easily), this is due to the difference in convention calls for C / C ++. Try making extern "C" callbacks and make them call the C ++ function. Call it a trampoline :)

0
source share

All Articles