0

这是我第一次需要加载 dll nad,不幸的是这不是 COM serwer dll,所以我不能使用 php com 函数。

我发现可以使用 winbinder 来做到这一点,但到目前为止我还没有取得那么大的成功。这是我的代码:

define("PATH_SCRIPT",   dirname(__FILE__) . "/");
define("PATH_DATA",     PATH_SCRIPT);
define("PATH_INC",      PATH_SCRIPT . "include/");
define("PATH_RES",      PATH_SCRIPT . "resources/");

//----------------------------------------------------------------- DEPENDENCIES

include PATH_INC . "winbinder.php";

//-------------------------------------------------------------------- CONSTANTS

define("APPNAME",           "Xml Reader!");    // Application name

// Control identifiers

define("ID_ABOUT",          101);


//-------------------------------------------------------------- EXECUTABLE CODE

// Create main window, then assign a procedure and an icon to it

$mainwin = wb_create_window(NULL, AppWindow, APPNAME . " - PHP " . PHP_VERSION, 320, 240);
wb_set_handler($mainwin, "process_main");
wb_set_image($mainwin, PATH_RES . "hyper.ico");

// Create toolbar


wb_create_control($mainwin, ToolBar, array(
    array(ID_ABOUT, NULL,   "About this application",   13),
), 0, 0, 16, 15, 0, 0, PATH_RES . "toolbar.bmp");


// Create status bar

$statusbar = wb_create_control($mainwin, StatusBar, APPNAME);

// Create label control inside the window

wb_create_control($mainwin, Label, "This is xml reader\n" .
  "application that will read xml.\n" .
  "from dll and write it to file.",
  10, 70, 290, 80, 0, WBC_CENTER);

// Enter application loop

wb_main_loop();

/* Process main window commands */



function process_main($window, $id)
{
    global $statusbar;

    switch($id) {

        case ID_ABOUT:
            $dll = wb_load_library("dll/OSOZMOK.dll");

            //$funcAddr = wb_get_function_address('OSOZ_Release', $dll);
            $funcAddr = wb_get_function_address('GetDllVersion', $dll);
            $dll_info = wb_call_function($funcAddr);

            $funcAddr = wb_get_function_address('OSOZ_IsConnected', $dll);
            $dll_info2 = wb_call_function($funcAddr);

            wb_release_library($dll);

            wb_message_box($window, "DLL Returned: 1) ".$dll_info. "  2) ".$dll_info2);
            break;

        case IDCLOSE:       // IDCLOSE is predefined
            wb_destroy_window($window);
            break;
    }


}

它只做两件事:创建 winbinder 窗口,如果单击“关于”,它会加载 dll 并执行 2 个函数。

问题是当我再次单击时程序崩溃了......

此外,在 TRUE 或 FALSE 等 ruturned 变量上,我得到了整数。OSOZ_IsConnected 将返回常量整数,而 OSOZ_Release 将给出随机数。

例如:

在此处输入图像描述

我真的怀疑dll无论如何都是错误的。它必须与我调用函数的方式有关。

替代方案:还有其他方法可以在 php 中加载 dll(delphi)吗?我想避免学习 c++/c# 只是为了处理这个 dll,将 xml 输出保存到文件,并在 php 中读取它:P。

感谢任何可以提供帮助的人。

4

1 回答 1

0

似乎 Winbinder 根本不够先进来处理这个问题。我用过c++。例如

HINSTANCE hGetProcIDDLL = LoadLibrary("path_to_dll.dll"); - 来自 windows.h

或者

来自 WxWidgets 的 wxDynamicLibrary 和 .load

两者都会。

于 2013-08-01T08:34:23.910 回答