【问题标题】:Calling external function from DLL with PowerBuilder 10.0 error使用 PowerBuilder 10.0 错误从 DLL 调用外部函数
【发布时间】:2011-08-31 16:50:39
【问题描述】:

我使用 Visual C++ 2008 创建了一个 DLL,它创建了两个外部函数。使用 python,我创建了两个单独的可执行函数来运行它们。使用 PowerBuilder 调用该函数时,第一个可执行文件运行良好。第二个可执行文件导致运行时错误:error calling external function %s。我使用.def 文件并为每个函数设置正确的序号。有什么建议吗?

C 中的函数声明如下(抱歉,它们很长):

extern "C" int __stdcall start_proctor( double points[], double weights[], double opoints[],  double &SG, char sg_estimated[], double &smooth, char ptitle[], double &pheight, double &pwidth, char save_location[], int &show, int &ZV, char roundM[], char roundD[], int &zoom, char cwd[], int &x_scale_major_tick,int &y_scale_major_tick, char points_of[], char points_color[], char points_type[], int &points_size, char curve_of[], char curve_color[], int &curve_alpha, int &curve_size, char grid_of[], char grid_color[], int &grid_alpha, int &grid_x_dash, int &grid_y_dash, char opt_of[], char opt_color[], int &opt_alpha, int &opt_x_dash, int &opt_y_dash, int &x_scale_major_tick_c, int &y_scale_major_tick_c, char points_of_c[], char points_color_c[], char points_type_c[], int &points_size_c, char curve_of_c[], char curve_color_c[], int &curve_alpha_c, int &curve_size_c, char grid_of_c[], char grid_color_c[], int &grid_alpha_c, int &grid_x_dash_c, int &grid_y_dash_c, char opt_of_c[], char opt_color_c[], int &opt_alpha_c, int &opt_x_dash_c, int &opt_y_dash_c, int &return_default, int &splash, double &optmoisture, double &maxdd,  double &percent_oversized, double &o_SG , double &o_moisture, double &o_optmoisture, double &o_maxdd, int &oversized_flag, int &debug, char c_output[] );

extern "C" int __stdcall start_grain_size( char dsn_name[], char userID[], char passwd[], double test_data[], int &td_length, double upper_bound[], int &ub_length, double lower_bound[], int &lb_length, char envelope[], char specification[], char pointmarker[], char splinemarker[], char display[], char scale[], char units[], char xlabel[], char direction[], char maximum_density_line[], int &pan, char title[], char save_location[], char cwd[], int &show, double &width, double &height, char output[] );

在 powerbuilder 中,外部函数声明是:

Function int start_proctor(ref double points[3,8], ref double weigthts[8], ref double opoints[3,8], ref double sg, ref string sg_estimated, ref double smooth, ref string ptitle, ref double pheight, ref double pwidth, ref string save_location, ref int show, ref int zv, ref string roundm, ref string roundd, ref int zoom, ref string cwd, ref int li_x_scale_major_tic, ref int li_y_scale_major_tic, ref string ls_points_of, ref string ls_points_color, ref string ls_points_type, ref int li_points_size, ref string ls_curve_of, ref string ls_curve_color, ref int li_curve_alpha, ref int li_curve_size, ref string ls_grid_of, ref string ls_grid_color, ref int li_grid_alpha, ref int li_grid_x_dash, ref int li_grid_y_dash, ref string ls_opt_of, ref string ls_opt_color, ref int li_opt_alpha, ref int li_opt_x_dash, ref int li_opt_y_dash, ref int li_x_scale_major_tic_t, ref int li_y_scale_major_tic_t, ref string ls_points_of_t, ref string ls_points_color_t, ref string ls_points_type_t, ref int li_points_size_t, ref string ls_curve_of_t, ref string ls_curve_color_t, ref int li_curve_alpha_t, ref int li_curve_size_t, ref string ls_grid_of_t, ref string ls_grid_color_t, ref int li_grid_alpha_t, ref int li_grid_x_dash_t, ref int li_grid_y_dash_t, ref string ls_opt_of_t, ref string ls_opt_color_t, ref int li_opt_alpha_t, ref int li_opt_x_dash_t, ref int li_opt_y_dash_t, ref int li_return_default, ref int li_splash, ref double optmoisture, ref double maxdd, ref double pover, ref double osg, ref double om,  ref double o_optmoisture, ref double o_maxdd, ref int oversized_flag, ref int debug_flag, ref string output) LIBRARY "ELMTREE_EXTERNAL.dll" ALIAS FOR "start_proctor;ansi"

Function int start_grain_size(ref string dsn_name, ref string userid, ref string passwd, ref double test_data[], ref int td_length, ref double upper_bound[], ref int ub_length, ref double lower_bound[], ref int lb_length, ref string envelope, ref string specification, ref string pointmarker, ref string splinemarker, ref string display, ref string scale, ref string units, ref string xlabel, ref string direction, ref string maximum_density_line, ref int pan, ref string title, ref string save_location, ref string cwd, ref int show, ref double width, ref double height, ref string output) LIBRARY "ELMTREE_EXTERNAL.dll" ALIAS FOR "start_grain_size;ansi"

start_grain_size 导致错误

【问题讨论】:

  • 根据这里的信息无法说出问题所在。
  • 请在 C 中添加您的函数声明,并在 PowerBuilder 中添加相应的外部函数声明。
  • 只是要清楚,哪个函数会导致错误?
  • @Hugh Brackett--start_grain_size 导致错误

标签: c++ dll powerbuilder python-c-api


【解决方案1】:

我认为 PB 代码没有任何问题。我认为您的错误出在调用 Python 的 C 代码中。您可能没有正确设置要调用的函数的名称。这就是错误消息中的 %s 所暗示的。我为 python-c-api 标记了这个问题,试图吸引一些大师。他们无疑会希望看到调用 Python 的 C 代码。

【讨论】:

    【解决方案2】:

    我将尝试一个疯狂的猜测(还没有足够的信息来确定),并说 PB 应用程序很难找到有问题的 DLL。您可以通过使用Process Monitor 来确认这一点来观看您的 PB 应用程序(确保您设置了过滤器,以便进程名称与您的应用程序相匹配,否则您将获得大量信息,尽管您可以在事后过滤)并观看对于在失败案例中访问 DLL 的任何失败。可能是当前目录正在更改,DLL 的位置取决于搜索链中的那个链接。

    如果是这种情况,我建议为您的应用程序创建一个App Path,其中包括您的应用程序的路径,即使它只是包含您的 EXE 的文件夹。输入法,它已经解决了这些问题。

    祝你好运,

    特里。

    【讨论】:

    • 它与有效的函数在同一个 DLL 中。很遗憾 PB 不再构建和编译 C++。回到过去,您可以直接追溯到调度和编组代码以及函数。您仍然可以附加到该过程。确定设置断点的内存地址留给读者作为练习。我的猜测是 PB 不喜欢正在传递的变量之一。
    • 我并不是说 DLL 是问题所在。可能是对 DLL 的 first 调用是成功的,因为它依赖于 Windows DLL 搜索算法中的某些元素,它像当前目录一样是瞬态的。如果两次调用之间的某些内容更改了当前目录,那么第一次可以找到的 DLL 可能会在第二次“丢失”。我以前见过不止一次。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-06
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多