zoukankan      html  css  js  c++  java
  • php 扩展dll




    一、准备工作:
    注:php5.2没有vc9,php5.3、php5.4没有vc6。呵呵。PHP5.5开始,不支持xp和win2003了,更是vc11了。---------------》所以,扩展5.2需要vc++6.0

    1、下载php-5.2.17.tar(源码)
    2、下载php-5.2.17-Win32-VC6-x86(需要用到它dev里的php5ts.lib)



    二、修改过程


    1、D:phpphp-5.2.17extskeleton 复制一分重命名,包括里面的子文件名

    2、把所有子文件里的extname替换为myfun,EXTNAME替换为MYFUN。(一定要严格区分大小写)如:

    三、下面就进入到编码阶段:

      1、打开php_skeleton.h文件(头文件),找到PHP_FUNCTION(confirm_myfun_compiled);,在 PHP_FUNCTION(confirm_myfun_compiled);,下面编写PHP_FUNCTION(mb_MessageBox);,声 明一个mb_MessageBox函数,此函数的作用仅是输出js弹出一个alert消息框,用于测试。

      2、下面定义函数入口,打开myfun.c文件,找到PHP_FE(confirm_myfun_compiled,NULL) ;,在下面编写 PHP_FE(mb_MessageBox,NULL),此处注意一下,PHP_FE是定义的一个宏,所以后面不用加引号。

      3、在myfun.c最后面编写函数的实体部分PHP_FUNCTION(mb_MessageBox):

    PHP_FUNCTION(confirm_myfun_compiled)
    {
        char *arg = NULL;
        int arg_len, len;
        char *strg;
    
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
            return;
        }
    
        len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "myfun", arg);
        RETURN_STRINGL(strg, len, 0);
    }
    /* }}} */
    /* The previous line is meant for vim and emacs, so it can correctly fold and 
       unfold functions in source code. See the corresponding marks just before 
       function definition, where the functions purpose is also documented. Please 
       follow this convention for the convenience of others editing your code.
    */
    
    /* __function_stubs_here__ */
    
    /*
     * Local variables:
     * tab- 4
     * c-basic-offset: 4
     * End:
     * vim600: noet sw=4 ts=4 fdm=marker
     * vim<600: noet sw=4 ts=4
     */
    
     
     PHP_FUNCTION(mb_MessageBox)
    {
        char *arg = NULL;
        int arg_len, len;
        char *strg;
    
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
            return;
        }
    
        len = spprintf(&strg, 0, "<script>alert('%s')</script>",arg); //此处正是输入的js代码
        RETURN_STRINGL(strg, len, 0);
    }

    四、到这代码书写就完成了,下面开始编译:

      1、开始->运行,输入CMD,打开命令行窗口。

      2、进入myfun的目录,输入 msdev myfun.dsp /MAKE "myfun - Win32 Release_TS",回车编译。

      3、如果没有错误,在E:php-5.2.17下会生成一个Release_TS文件夹,在里面就可以找到php_myfun.dll文件。

      至此扩展dll开发完成,下面在php中进行测试:

      4、把php_myfun.dll复制到原php目录中的ext文件夹内。

      5、打开php.ini文件,添加当前dll的扩展 extension=php_myfun.dll

      6、测试

      

      7、重启IIS或apache,在网站目录下新建一文件,输入以下内容:

    <?php
    echo mb_MessageBox("测试PHP扩展DLL by 马犇");
    //参考:http://www.cnblogs.com/madonion/articles/2272288.html

    ?>


  • 相关阅读:
    OBS直播和相关操作
    计算机信息安全易错题目整理3
    计算机信息安全易错题目整理1
    LeetCode SQL题目(第一弹)
    操作系统及安全复习笔记
    网络安全web部分
    《算法分析与设计基础》考前复习提纲
    兼容新旧浏览器的flex写法
    特效背景粒子插件particles.js
    前端工程师必备的几个实用网站
  • 原文地址:https://www.cnblogs.com/hellowzd/p/5607293.html
Copyright © 2011-2022 走看看