编译旧的c代码

发布于 2024-11-14 14:23:13 字数 1237 浏览 5 评论 0原文

我承担了尝试让旧程序在 Vista/Win7 下运行的任务。
该代码看起来像 c 代码,但“奇怪”

foo.h:

int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
BOOL InitApplication(HANDLE);
BOOL InitInstance(HANDLE, int);
long CALLBACK __export MainWndProc(HWND, UINT, WPARAM, LPARAM);

foo.c:

int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
HANDLE hInstance;                /* current instance         */
HANDLE hPrevInstance;            /* previous instance        */
LPSTR lpCmdLine;                 /* command line             */
int nCmdShow;                    /* show-window type (open/icon) */
{
   /* rest of the code follows here */

我对 c 的了解有限,这种语法看起来不像我见过的任何东西。 该程序已在 WinXP 下运行,但不在 Vista/Win7 下运行 - 我怀疑 16 位编译(它那么旧......)

代码附带一个 make 文件,其中指出:

# Microsoft Visual C++ generated build script - Do not modify
...

但 VS2010 都没有, gcc 似乎也无法编译此代码(不是我尝试的方式,无论如何......) 使用VS2010,一个空的解决方案(vc++),第一个错误是:

error C2061: Syntaxerror: Identifier: 'MainWndProc' in line 4 of foo.h
error C2059: Syntaxerror: ';' in line 4 of foo.h
error C2059: Syntaxerror: 'Type' in line 4 of foo.h

有没有一种简单的方法可以在Win7/64位上编译它?

I have taken the task of trying to get an older program to run under Vista/Win7.
The code looks like c code, but "strange"

foo.h:

int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
BOOL InitApplication(HANDLE);
BOOL InitInstance(HANDLE, int);
long CALLBACK __export MainWndProc(HWND, UINT, WPARAM, LPARAM);

foo.c:

int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
HANDLE hInstance;                /* current instance         */
HANDLE hPrevInstance;            /* previous instance        */
LPSTR lpCmdLine;                 /* command line             */
int nCmdShow;                    /* show-window type (open/icon) */
{
   /* rest of the code follows here */

My knowledge of c is limited and this syntax does not look like anything I have ever seen.
The program has been running under WinXP but does not under Vista/Win7 - I suspect 16bit compilation (It is that old...)

The code comes with a make-file which states:

# Microsoft Visual C++ generated build script - Do not modify
...

But neither VS2010, nor gcc seems to be able to compile this code (not the way I tried it, anyways...)
Using VS2010, an empty solution (vc++) the first errors are:

error C2061: Syntaxerror: Identifier: 'MainWndProc' in line 4 of foo.h
error C2059: Syntaxerror: ';' in line 4 of foo.h
error C2059: Syntaxerror: 'Type' in line 4 of foo.h

Is there an easy way to get this compiled on a Win7/64bit?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

铜锣湾横着走 2024-11-21 14:23:13

这就是所谓的 K&R 风格 C,它不使用函数原型。我不记得 C89 和 C99 是否仍然支持这一点,它肯定不是合法的 C++。

It's what is known as K&R style C, which does not use function prototypes. I can't remember if this is still supported in C89 and C99, it certainly isn't legal C++.

帝王念 2024-11-21 14:23:13

除了 PASCAL 项之外,您粘贴的代码没有任何问题...它是较旧的 C 风格(对 C++ 无效),不再受青睐,但仍然有效。

去掉 PASCAL 关键字,它就会编译……但最好找到 PASCAL 所做的任何定义。我希望 #define'd 会影响该函数的 MSVC 调用约定。

Excluding the PASCAL item, there's nothing wrong with the code you've pasted... it's an older style of C (and invalid for C++), no longer in favor but still valid.

Get rid of the PASCAL keyword and it will compile... but it'd be better to find the definition of whatever PASCAL did. I would expect it was #define'd to affect the MSVC calling convention of the function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文