从 COBOL 程序调用 C(公开)函数

发布于 2024-09-01 03:37:52 字数 362 浏览 1 评论 0原文

前段时间,我创建了一个 DLL 以在另一个 C 程序中使用。基本上,我通过在 dll 中使用以下内容来公开特定的函数:

void __declspec(dllexport) MyFunc(myFirstArg, mySecondArg);

然后,我添加了一个外部文件 (MyExposedDll.h),其中包含所有公开的函数和结构到新的 C 程序并将其包含在内:

#include MyExposedDll.h

现在我如何使用这个 dll(或者主要是一个dll)到 Cobol 函数?我需要公开一个具有两个 char* 参数并返回布尔值的函数。

谢谢, 太阳

Some time ago, I had created a DLL to be used in another C program. Basically I exposed specific functions by using the following within my dll:

void __declspec(dllexport) MyFunc(myFirstArg, mySecondArg);

Then I added an external file (MyExposedDll.h) with all exposed functions and structures to the new C program and included it:

#include MyExposedDll.h

Now how can I use this dll (or mainly a dll) to a Cobol function? I need to expose a function that has two char* arguments and returns a boolean.

Thanks,
Sun

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

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

发布评论

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

评论(1

烟凡古楼 2024-09-08 03:37:52

在支持 LE 的 IBM Z/OS 环境中,这应该不难。

使用捕获布尔结果
COBOL 回电
CALL 语句的形式。字符串参数的传递方式与 COBOL CALL 语句中的任何其他参数一样。
唯一需要警惕的是 C 使用 Null 终止字符串,而 COBOL 通常不使用。你应该回顾一下
如何处理空终止字符串在
科博尔。

请查看:使用 COBOL DLL对于 C/C++ 程序,这给出了一个非常简单的示例,显示了对返回函数指针的 C++ 函数的调用。

编辑
我可能错过了你问题的一部分......当你的COBOL程序被链接编辑时,你需要提供你的DLL IMPORT文件以便它可以被绑定。请参阅 链接 DLL

编辑2

根据您的评论,我认为您正在 Z/OS 机器上运行您的应用程序。 Visual Studio 是基于 PC 的产品,所以我猜测您在那里开发代码,但将其部署在 Z/OS 下?为了让 COBOL 程序识别您的 DLL,您需要在编译 C 程序时创建一个“辅助文件”。这个“副文件”包含链接器链接 COBOL 程序时所需的 DLL 结构。您应该能够通过上面提供的链接来完成该过程。

This should not be difficult in an IBM Z/OS environment with LE support.

Capture the boolean result using the
COBOL CALL RETURNING
form of the CALL statement. The string arguments are passed just as any other arguments in a COBOL CALL statement.
The only thing to be wary of is that C uses Null terminated strings whereas COBOL generally does not. You should review
how to handle null terminated strings in
COBOL.

Have a look at: Using COBOL DLLs with C/C++ programs this gives a really simple example showing a call to a C++ function returning a function pointer.

EDIT
I may have missed part of your question... When your COBOL program is linked-edited, you need to provide the your DLL IMPORT file so it can be bound. See linking DLL's.

EDIT 2

Based on your comments, I take it you are running your application on a Z/OS box. Visual Studio is a PC based product so I am guessing that you develop your code there but deploy it under Z/OS? In order to get the COBOL program to recognize your DLL you need to create a "side file" from your C program when it is compiled. This "side file" contains the DLL structures needed by the linker when the COBOL program is linked. You should be able to get the process worked out from the links provided above.

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