PDCurses TUI C++ Win32 控制台应用程序 - 访问冲突读取位置
我已经下载了 pdcurses 源代码,并能够成功地将curses.h包含在我的项目中,链接了预编译的图书馆,一切都很好。
经过几个小时的试用该库后,我在 demos 文件夹中看到了 tuidemo.c,将其编译为可执行文件,非常棒!正是我的项目所需要的。
现在的问题是它是一个C代码,我正在VS c++ 2008中开发一个C++项目。
我需要的文件是tui.c和tui.h 如何将该 C 文件包含在我的 C++ 代码中?我看到这里有一些建议
但是编译器对数百个警告和错误不太满意。
我怎样才能继续包含/使用 TUI pdcurses 包含的内容!?
谢谢
编辑:
我添加了 extern "C" 语句,所以我的测试现在看起来像这样,但我收到了一些其他类型的错误
#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;
}
但它在运行时抛出错误,这表明一个错误的指针:
0xC0000005: Access violation reading location 0x021c52f9
虽然它编译成功, line
startmenu(MainMenu, "TUI - 'textual user interface' demonstration program");
不知道从这里去哪里。 再次感谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我没记错的话(而且我很容易记错),这是由于 C/C++ 调用约定的差异造成的。尝试将回调设置为 extern "C",并让它们调用 C++ 函数。称之为蹦床:)
If I'm not mistaken (and I could easily be), it's due to the difference in calling conventions for C/C++. Try making the callbacks extern "C", and make them call a C++ function. Call it a trampoline :)
终于成功了。解决方案如下:
首先,我将 tui.c 重命名为 tui.cpp
对于标头 tui.h,我按照 完全相同 的步骤包装代码,如 此处。
然后在我的项目中我刚刚包含了没有任何外部“C”块的标头
已编译并且有效!
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
Compiled and it worked!