这是我第一次需要加载dll nad不幸的是这不是COM服务器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窗口,如果点击“about”,它会加载dll并执行2个函数。
问题是当我再次点击该程序时崩溃...
另外,对于像TRUE或FALSE这样的ruturned变量,我得到了intigers。 OSOZ_IsConnected将返回常量intiger,OSOZ_Release将随机返回。
例如:
我真的怀疑dll无论如何都是错的。它必须与我调用函数的方式一致。
替代方法:有没有其他方法在PHP中加载DLL(delphi)?我想避免学习c ++ / c#来处理这个dll,将xml输出保存到文件中,并在php中读取它:P。
对于任何可以提供帮助的人来说都是一个好消息。
答案 0 :(得分:0)
似乎Winbinder根本不是高级应该处理这个问题。我用过c ++。例如
HINSTANCE hGetProcIDDLL = LoadLibrary(“path_to_dll.dll”); - 来自windows.h
OR
来自WxWidgets的wxDynamicLibrary和.load
双方都这样做。