免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5264 | 回复: 11
打印 上一主题 下一主题

编写过PHP模块的朋友请进来指导一下! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-03-02 12:51 |只看该作者 |倒序浏览
系统信息:
Debian Etch (Kernel 2.6.18-3-686 )
5.0.32-Debian_3-log Debian etch distribution
PHP 5.2.0-8

问题:用php 源代码树下的ext_skel 创建了一个新的模块基本骨架。添加了一个模块函数。在php脚本中调用
sample_passport函数,没有任何输出。

原来的连接数据库的代码工作正常。我想把数据库的代码放到php模块函数中。

mysql代码:

query.h


  1. // system header files
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. // mysql header files
  6. #include <my_global.h>
  7. #include <my_sys.h>
  8. #include <mysql.h>


  9. static void print_error(MYSQL *mysql, char *message);
复制代码


query.c



  1. /*
  2. *  shell> gcc -o firstquery firstquery.c -lmysqlclient
  3. */
  4. #include "firstquery.h"

  5. static void print_error(MYSQL *mysql, char *message)
  6. {
  7.     fprintf (stderr, "%s\n", message);
  8.     if (mysql != NULL)
  9.     {
  10. #if MYSQL_VERSION_ID >= 40101
  11.           fprintf(stderr,"MYSQL ERROR:[ERRNO] %u [SQLSTATE] %s [MESSAGE] %s\n",
  12.                   mysql_errno(mysql), mysql_error(mysql),mysql_sqlstate(mysql));
  13. #else
  14.           fprintf(stderr,"MYSQL ERROR:[ERRNO] %u [MESSAGE] %s\n",
  15.                   mysql_errno(mysql), mysql_error(mysql));
  16. #endif
  17.     }
  18. }


  19. int main(int argc, char *argv[]) {
  20.        
  21.         /* MYSQL DATA TYPES*/
  22.         MYSQL mysql;
  23.         MYSQL_RES *result;
  24.         MYSQL_ROW row;
  25.         MYSQL_FIELD *fields;
  26.        
  27.         /* VARIABLES */
  28.         unsigned int numrows, numcols, i;
  29.        
  30.         /* init connection data structure
  31.                   conn = mysql_init (NULL);
  32.             if (conn == NULL)
  33.             {
  34.                 fprintf (stderr, "mysql_init() failed (probably out of memory)\n");
  35.                 exit (1);
  36.             }
  37.     */
  38.         mysql_init(&mysql);        //        init connection data structure  protoype: MYSQL *mysql_init(MYSQL *mysql)
  39.         if(&mysql == NULL){
  40.         fprintf (stderr, "mysql_init() failed (probably out of memory)\n");
  41.         exit(EXIT_FAILURE);
  42.         }
  43.         /* Establish a database connection
  44.           
  45.           MYSQL *mysql_real_connect(
  46.                           MYSQL *mysql,
  47.                           const char *host,
  48.                           const char *user,
  49.                           const char *passwd,
  50.                           const char *db,
  51.                           unsigned int port,
  52.                           const char *unix_socket,
  53.                           unsigned long client_flag                                  // CLIENT_COMPRESS | CLIENT_FOUND_ROWS |CLIENT_IGNORE_SPACE
  54.                                                                  // | CLIENT_INTERACTIVE | CLIENT_LOCAL_FILES
  55.                                                                  // | CLIENT_MULTI_STATEMENTS
  56.                                                                  // | CLIENT_MULTI_RESULTS | CLIENT_NO_SCHEMA
  57.                                                                  // | CLIENT_ODBC | CLIENT_SSL
  58.           )
  59.          */
  60.          
  61.         if (!mysql_real_connect(
  62.                              &mysql,                             // connect handle
  63.                              "localhost",                        // hostname
  64.                              "develop",                             // mysql username
  65.                              "**********",              // password
  66.                              "passport",                         // database name
  67.                              3306,                               // port
  68.                              "/var/run/mysqld/mysqld.sock",      // unix socket
  69.                              0)                                 
  70.         ){
  71.           print_error(&mysql,"mysql_real_connect():Can not connect to mysql database");
  72.           mysql_close(&mysql);
  73.           exit(EXIT_FAILURE);
  74.         }
  75.         /* Execute a query */
  76.         /*char query[] = "SELECT book_id, cond, title FROM book";*/
  77.         char query[] = "SELECT username,usertypeid,email,status,ipaddr_registered FROM passport";
  78.         if (mysql_query(&mysql, query) != 0)
  79.         {
  80.           print_error(&mysql,"mysql_query():failed query to database");
  81.           mysql_close(&mysql);
  82.           exit(EXIT_FAILURE);
  83.         }
  84.         /* Assign the result handle */
  85.         result = mysql_use_result(&mysql);
  86.         if (!result){
  87.           print_error(&mysql,"mysql_use_result():Can not get the result set");
  88.           mysql_close(&mysql);
  89.           exit(EXIT_FAILURE);
  90.         }
  91.         /* Find the number of columns in the result */
  92.         numcols = mysql_num_fields(result);
  93.         fields = mysql_fetch_fields(result);
  94.         /* Loop through the result set to display it */
  95.         printf("\n");
  96.         printf("----------------------------------------------------------------------\n");
  97.         for(i = 0; i < numcols; i++){
  98.            printf("%s\t",fields[i].name);
  99.         }
  100.         printf("\n");
  101.         while (row = mysql_fetch_row(result)) {

  102.                 for(i=0; i < numcols; i++) {
  103.                         printf("%s\t", row[i]);
  104.                 }
  105.                 printf("\n");
  106.         }
  107.         printf("\n");
  108.        
  109.         exit(EXIT_SUCCESS);
  110. }

复制代码


php代码:

php_sample.h

  1. #ifndef PHP_SAMPLE_H
  2. /* Prevent double inclusion */
  3. #define PHP_SAMPLE_H
  4. /* Define Extension Properties
  5. * 定义扩展属性,名称和版本号
  6. */
  7. #define PHP_SAMPLE_EXTNAME    "sample"
  8. #define PHP_SAMPLE_EXTVER      "1.0"
  9. /*
  10. * Import configure options when building outside of the PHP source tree
  11. * 在php源代码树外构建时导入配置选项
  12. */
  13. #ifdef HAVE_CONFIG_H
  14. #include "config.h"
  15. #endif
  16. /* Include PHP Standard Header
  17. * 包含php标准头文件
  18. */
  19. #include "php.h"
  20. /* Define the entry point symbol
  21. * Zend will use when loading this module
  22. * 定义入口点符号,Zend将在加载此模块时使用
  23. */
  24. extern zend_module_entry sample_module_entry;
  25. #define phpext_sample_ptr &sample_module_entry

  26. /* 本模块在phpinfo() 用户空间函数输出函数的原型定义 */
  27. static ZEND_MINFO_FUNCTION(sample);

  28. /* 模块(扩展)函数原型声明 */
  29. ZEND_FUNCTION(sample_long);
  30. ZEND_FUNCTION(sample_hello_world);
  31. ZEND_FUNCTION(sample_array_range);
  32. ZEND_FUNCTION(sample_hello_greeting);
  33. ZEND_FUNCTION(sample_hello_optional);
  34. ZEND_FUNCTION(sample_onearg);
  35. ZEND_FUNCTION(sample_getlong);
  36. ZEND_FUNCTION(sample_variable_arguments);
  37. ZEND_FUNCTION(sample_var_dump);
  38. ZEND_FUNCTION(sample_return_array);
  39. ZEND_FUNCTION(sample_array);
  40. ZEND_FUNCTION(sample_array_passport);
  41. ZEND_FUNCTION(sample_passport);


  42. #if (PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0)
  43. ZEND_FUNCTION(sample_reference_a);
  44. static
  45.     ZEND_BEGIN_ARG_INFO_EX(php_sample_retref_arginfo, 0, 1, 0)
  46.     ZEND_END_ARG_INFO ()
  47.    
  48. #endif /* PHP >= 5.1.0 */

  49. #endif /* PHP_SAMPLE_H */

  50. #include <my_global.h>
  51. #include <my_sys.h>
  52. #include <mysql.h>


  53. static void print_error(MYSQL *mysql, char *message);

复制代码



sample.c


  1. #include "php_sample.h"

  2. static function_entry php_sample_functions[] = {
  3.         ZEND_FE(sample_long, NULL)
  4.     ZEND_FE(sample_hello_world, NULL)
  5.     ZEND_FE(sample_hello_greeting, NULL)
  6.     ZEND_FE(sample_hello_optional, NULL)
  7.     ZEND_FE(sample_array_range, NULL)
  8.     ZEND_FE(sample_onearg, NULL)
  9.         ZEND_FE(sample_getlong, NULL)
  10.         ZEND_FE(sample_variable_arguments, NULL)
  11.         ZEND_FE(sample_var_dump, NULL)
  12.         ZEND_FE(sample_return_array, NULL)
  13.         ZEND_FE(sample_array, NULL)
  14.         ZEND_FE(sample_array_passport, NULL)
  15.         ZEND_FE(sample_passport, NULL)
  16.     { NULL, NULL, NULL }
  17. };

  18. zend_module_entry sample_module_entry = {
  19. #if ZEND_MODULE_API_NO >= 20010901
  20.      STANDARD_MODULE_HEADER,
  21. #endif
  22.     PHP_SAMPLE_EXTNAME,
  23.     php_sample_functions,
  24.     NULL,
  25.     NULL,
  26.     NULL,
  27.     NULL,
  28.     NULL,
  29. #if ZEND_MODULE_API_NO >= 20010901
  30.     PHP_SAMPLE_EXTVER,
  31. #endif
  32.     STANDARD_MODULE_PROPERTIES
  33. };
  34. #ifdef COMPILE_DL_SAMPLE
  35. ZEND_GET_MODULE(sample)
  36. #endif


  37. ZEND_FUNCTION(sample_long)
  38. {
  39.     ZVAL_LONG(return_value, 42);
  40.     return;
  41. }
  42. ZEND_FUNCTION(sample_hello_world)
  43. {
  44.        
  45.         char *name;
  46.     int name_len;


  47.     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
  48.         RETURN_NULL();
  49.     }
  50.     php_printf("Hello ");
  51.     PHPWRITE(name, name_len);
  52.     php_printf("!<br/>");
  53.        
  54. //        ZVAL_STRING(return_value, "<br/>Hello World!<br/>",1);
  55. //        return;
  56. }

  57. /*

  58. function sample_hello_world($name, $greeting) {
  59.         echo "Hello $greeting $name!\n";
  60. }
  61. sample_hello_world('John Smith', 'Mr.');

  62. */
  63. ZEND_FUNCTION(sample_hello_greeting)
  64. {
  65.     if(ZEND_NUM_ARGS() != 2){
  66.             WRONG_PARAM_COUNT;
  67.     }       
  68.     char *name;
  69.     int name_len;
  70.     char *greeting;
  71.     int greeting_len;
  72.     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",&name, &name_len, &greeting, &greeting_len) == FAILURE) {
  73.         RETURN_NULL();
  74.     }
  75.     php_printf("Hello ");
  76.     PHPWRITE(greeting, greeting_len);
  77.     php_printf(" ");
  78.     PHPWRITE(name, name_len);
  79.     php_printf("!\n");
  80. }
  81. // 解析可选参数
  82. /*function sample_hello_world($name, $greeting='Mr./Ms.') {
  83.     echo "Hello $greeting $name!\n";
  84. }
  85. sample_hello_world('Ginger Rogers','Ms.');
  86. sample_hello_world('Fred Astaire');*/
  87. ZEND_FUNCTION(sample_hello_optional)
  88. {
  89.     if(ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2){
  90.             WRONG_PARAM_COUNT;
  91.     }
  92.         char *name;
  93.     int name_len;
  94.     char *greeting = "Mr./Mrs.";
  95.     int greeting_len = sizeof("Mr./Mrs.") - 1;
  96.    
  97.     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s",&name, &name_len, &greeting, &greeting_len) == FAILURE) {
  98.         RETURN_NULL();
  99.     }
  100.     php_printf("Hello ");
  101.     PHPWRITE(greeting, greeting_len);
  102.     php_printf(" ");
  103.     PHPWRITE(name, name_len);
  104.     php_printf("!\n");

  105. }
  106. ZEND_FUNCTION(sample_array_range)
  107. {
  108.     if (return_value_used) {
  109.         int i;
  110.         array_init(return_value);
  111.         for(i = 0; i < 1000; i++) {
  112.             add_next_index_long(return_value, i);
  113.         }
  114.         return;
  115.     } else {
  116.         php_error_docref(NULL TSRMLS_CC, E_NOTICE,"Static return-only function called without processing output");
  117.         RETURN_NULL();
  118.     }
  119. }
  120. ZEND_FUNCTION(sample_onearg)
  121. {
  122.     zval *firstarg;
  123.     if (zend_get_parameters(ZEND_NUM_ARGS(), 1, &firstarg) == FAILURE) {
  124.         php_error_docref(NULL TSRMLS_CC, E_WARNING,"Expected at least 1 parameter.");
  125.         RETURN_NULL();
  126.     }
  127. }
  128. ZEND_FUNCTION(sample_getlong)
  129. {
  130.         long foo;
  131.     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
  132.                          "l", &foo) == FAILURE) {
  133.         RETURN_NULL();
  134.     }
  135.     php_printf("The integer value of the parameter you "
  136.              "passed is: %ld\n", foo);
  137.     RETURN_TRUE;

  138. }
  139. ZEND_FUNCTION(sample_variable_arguments)
  140. {

  141. }
  142. ZEND_FUNCTION(sample_var_dump)
  143. {
  144.     int i, argc = ZEND_NUM_ARGS();
  145.     zval ***args;


  146.     args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
  147.     if (ZEND_NUM_ARGS() == 0 ||
  148.         zend_get_parameters_array_ex(argc, args) == FAILURE) {
  149.         efree(args);
  150.         WRONG_PARAM_COUNT;
  151.     }
  152.     for (i=0; i<argc; i++) {
  153.         php_var_dump(args[i], 1 TSRMLS_CC);
  154.     }
  155.     efree(args);
  156. }
  157. //ZEND_FUNCTION(sample_arg_fullnull)
  158. //{
  159. //}
  160. //ZEND_FUNCTION(sample_arg_nullok)
  161. //{
  162. //}

  163. ZEND_FUNCTION(sample_return_array)
  164. {
  165.         zval *my_long;
  166.         // Declaring and allocating return_value to be an array
  167.         array_init(return_value);
  168.         //Creates and assign the long element at (long)42
  169.         MAKE_STD_ZVAL(my_long);
  170.         ZVAL_LONG(my_long, 42);
  171.         //Make this our $array[0] I do not use add_index_long to
  172.         //to show a "by-hand" assignation
  173.         zend_hash_index_update(HASH_OF(return_value), 0, (void *)&my_long, sizeof(zval *), NULL);
  174.         //Returns nothing to satisfy the void prototype
  175.         return ;
  176. }
  177. //ZEND_FUNCTION(sample_return_object){}

  178. ZEND_FUNCTION(sample_array)
  179. {
  180.     zval *subarray;

  181.     array_init(return_value);
  182.     /* Add some scalars */
  183.     add_assoc_long(return_value, "life", 42);
  184.     add_index_bool(return_value, 123, 1);
  185.     add_next_index_double(return_value, 3.1415926535);
  186.     /* Toss in a static string, dup'd by PHP */
  187.     add_next_index_string(return_value, "Foo", 1);
  188.     /* Now a manually dup'd string */
  189.     add_next_index_string(return_value, estrdup("Bar"), 0);

  190.     /* Create a subarray */
  191.     MAKE_STD_ZVAL(subarray);
  192.     array_init(subarray);
  193.     /* Populate it with some numbers */
  194.     add_next_index_long(subarray, 1);
  195.     add_next_index_long(subarray, 20);
  196.     add_next_index_long(subarray, 300);
  197.     add_next_index_long(subarray, 1);
  198.     /* Place the subarray in the parent */
  199.     add_index_zval(return_value, 444, subarray);
  200. }
  201. ZEND_FUNCTION(sample_array_passport){
  202.         array_init(return_value);
  203.         add_assoc_long(return_value, "passport_id", 1);
  204.         add_assoc_string(return_value, "passport_name", "hezhiqiang", 1);
  205.         add_assoc_string(return_value, "passport_email", "developerworks@163.com", 1);       
  206. }
  207. ZEND_FUNCTION(sample_passport){
  208.         MYSQL mysql;
  209.         MYSQL_RES *result;
  210.         MYSQL_ROW row;
  211.         MYSQL_FIELD *fields;       
  212.         unsigned int numrows, numcols, i;
  213.        
  214. //        zval *rrow;
  215. //        MAKE_STD_ZVAL(rrow);
  216. //        array_init(return_value);
  217. //        array_init(rrow);
  218.        
  219.         mysql_init(&mysql);        //        init connection data structure  protoype: MYSQL *mysql_init(MYSQL *mysql)
  220.         if(&mysql == NULL){
  221.         fprintf (stderr, "mysql_init() failed (probably out of memory)\n");
  222.         exit(EXIT_FAILURE);
  223.         }
  224.         if (!mysql_real_connect(
  225.                              &mysql,                             // connect handle
  226.                              "localhost",                        // hostname
  227.                              "develop",                             // mysql username
  228.                              "**********",              // password
  229.                              "passport1",                         // database name
  230.                              3306,                               // port
  231.                              "/var/run/mysqld/mysqld.sock",      // unix socket
  232.                              0)                                 
  233.         ){
  234.           print_error(&mysql,"mysql_real_connect():Can not connect to mysql database");
  235.           mysql_close(&mysql);
  236.           exit(EXIT_FAILURE);
  237.         }
  238.         /* Execute a query */
  239.         char query[] = "SELECT passportid,username,usertypeid,email,status,ipaddr_registered FROM passport WHERE passportid = 1";
  240.         if (mysql_query(&mysql, query))
  241.         {
  242.           print_error(&mysql,"mysql_query():failed query to database");
  243.           mysql_close(&mysql);
  244.           exit(EXIT_FAILURE);
  245.         }
  246.         result = mysql_use_result(&mysql);  // get result set
  247.         if (!result){
  248.           print_error(&mysql,"mysql_use_result():Can not get the result set");
  249.           mysql_close(&mysql);
  250.           exit(EXIT_FAILURE);
  251.         }
  252.         numcols = mysql_num_fields(result); // get the number of columns in the result
  253.         fields = mysql_fetch_fields(result);   // get fields infomation
  254. //        for(i = 0; i < numcols; i++){
  255. //           printf("%s\t",fields[i].name);        // print field name
  256. //        }
  257. //        while (row = mysql_fetch_row(result)) {
  258. //                int j = 0;
  259. //                for(i=0; i < numcols; i++) {
  260. //                        printf("%s\t", row[i]);
  261. //                        add_assoc_string(rrow,fields[i].name,row[i],1);
  262. //                }
  263. //                add_index_zval(return_value, j, rrow);
  264. //                j++;
  265. //        }

  266.         /* Loop through the result set to display it */
  267.         printf("\n");
  268.         printf("----------------------------------------------------------------------\n");
  269.         for(i = 0; i < numcols; i++){
  270.            printf("%s\t",fields[i].name);
  271.         }
  272.         printf("\n");
  273.         while (row = mysql_fetch_row(result)) {
  274.                 for(i=0; i < numcols; i++) {
  275.                         printf("%s\t", row[i]);
  276.                 }
  277.                 printf("\n");
  278.         }
  279.         printf("\n");



  280. }

  281. static void print_error(MYSQL *mysql, char *message)
  282. {
  283.     fprintf (stderr, "%s\n", message);
  284.     if (mysql != NULL)
  285.     {
  286. #if MYSQL_VERSION_ID >= 40101
  287.           fprintf(stderr,"MYSQL ERROR:[ERRNO] %u [SQLSTATE] %s [MESSAGE] %s\n",
  288.                   mysql_errno(mysql), mysql_error(mysql),mysql_sqlstate(mysql));
  289. #else
  290.           fprintf(stderr,"MYSQL ERROR:[ERRNO] %u [MESSAGE] %s\n",
  291.                   mysql_errno(mysql), mysql_error(mysql));
  292. #endif
  293.     }
  294. }

复制代码

[ 本帖最后由 maya1982 于 2007-3-4 13:22 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2007-03-04 15:34 |只看该作者
怎么没有人回答一些呢?

论坛徽章:
0
3 [报告]
发表于 2007-03-04 17:32 |只看该作者
我前段时间整理的一些文字,希望对你能有些帮助

http://bbs.nettf.net/forums/index.php?showtopic=60320

论坛徽章:
0
4 [报告]
发表于 2007-03-04 18:53 |只看该作者
虽然没有我需要的,但是还是感谢你的关注,我大概是知道问题出在什么地方了。
我在代码中直接使用了MYSQL数据类型,但是在Zend中数据库连接是作为资源类型使用的对资源数据类型的变量要求作特殊的处理,我直接使用了声明的
MYSQL mysql;
连接数据库肯定就没有任何输出了,虽然编译没有任何错误。

论坛徽章:
0
5 [报告]
发表于 2007-03-04 22:48 |只看该作者
你可以把原来的数据库连接的代码编译成动态库,然后在php模块里面用函数指针调用
这个方法我试过,比把原来的动态库在php模块里面重新实现要简单许多
另外,如果你实在想重新实现的话,建议参看php的ext目录下的mysq目录下的l源码

论坛徽章:
0
6 [报告]
发表于 2007-03-05 11:06 |只看该作者
还有,我能直接在C api层次上直接调用ext/mysql提供的api函数?

论坛徽章:
0
7 [报告]
发表于 2007-03-05 21:00 |只看该作者
那你不如直接调用mysql提供的 C API了

论坛徽章:
0
8 [报告]
发表于 2007-03-06 15:28 |只看该作者
我研究了两天还是不能成功,望提供一些代码来研究一下。
在php模块中调用mysql api 总是没有输出。不知道问题出在什么地方。。

论坛徽章:
0
9 [报告]
发表于 2007-03-06 18:35 |只看该作者
关注,我也想这么搞

论坛徽章:
0
10 [报告]
发表于 2007-03-06 23:26 |只看该作者
下面是我程序里的部分代码,是调用我自己的一个工程用DLL的,懒得在php的模块里面重写了(要考虑一堆的内存分配、多线程等,不想折腾了),用函数指针调用的

.h 文件中:

  1. //long __stdcall nsms_ctrl_SendMsg( const char * ump, const char * msg )
  2. typedef long (__stdcall * pFunSendMsg)( const char *, const char * );
  3. pFunSendMsg funSendMsg;
复制代码


.c 文件中:

  1. /* {{{ proto long nsms_ext_init( void )
  2.    Return long to test that the module is init done. */
  3. PHP_FUNCTION(nsms_ext_init)
  4. {
  5.         long lngRet = 1;
  6.        
  7.         hNsmsCtrl = LoadLibrary( "nsms_ctrl.dll" );
  8.         if( hNsmsCtrl ) {
  9.                 funSendMsg = (pFunSendMsg)GetProcAddress( hNsmsCtrl, "nsms_ctrl_SendMsg" );
  10.                 if( funSendMsg ) {
  11.                         lngRet = 0;
  12.                 } else {
  13.                         lngRet = 3;
  14.                 }
  15.         } else {
  16.                 lngRet = 2;
  17.         }

  18.         RETURN_LONG( lngRet );
  19. }
  20. /* }}} */

  21. /* {{{ proto long nsms_ext_release( void )
  22.    Return long to test that the module is init done. */
  23. PHP_FUNCTION(nsms_ext_release)
  24. {
  25.         long lngRet = 4;
  26.        
  27.         if( hNsmsCtrl ) {
  28.                 lngRet = ( FreeLibrary( hNsmsCtrl ) > 0 ) ? 0 : 4;
  29.                 hNsmsCtrl = NULL;
  30.         } else {
  31.                 lngRet = 0;
  32.         }

  33.         RETURN_LONG( lngRet );
  34. }
  35. /* }}} */

  36. /* {{{ proto long nsms_ext_send(string mp, string msg)
  37.     */
  38. PHP_FUNCTION(nsms_ext_send)
  39. {
  40.     char *mp = NULL;
  41.     char *msg = NULL;
  42.     int argc = ZEND_NUM_ARGS();
  43.     int mp_len;
  44.     int msg_len;

  45.         long lngPort = -1;
  46.         long lngRet = ERR_UNKNOWN;

  47.     if (zend_parse_parameters(argc TSRMLS_CC, "ss", &mp, &mp_len, &msg, &msg_len) == FAILURE)
  48.                 RETURN_LONG( ERR_PARAMETERS );

  49.         //char * szTmp = estrdup( NSMS_EXT_G(com_port) );

  50.         if( ! stricmp( NSMS_EXT_G(com_port), "COM1" ) ) {
  51.                 lngPort = 0;
  52.         } else if( ! stricmp( NSMS_EXT_G(com_port), "COM2" ) ) {
  53.                 lngPort = 1;
  54.         } else if( ! stricmp( NSMS_EXT_G(com_port), "COM3" ) ) {
  55.                 lngPort = 2;
  56.         } else if( ! stricmp( NSMS_EXT_G(com_port), "COM4" ) ) {
  57.                 lngPort = 3;
  58.         } else {
  59.                 RETURN_LONG( ERR_COM_PORT );
  60.         }

  61.         if( funSendMsg ) {
  62.                 lngRet = funSendMsg( mp, msg );
  63.         } else {
  64.                 lngRet = ERR_BASE;
  65.         }

  66.     RETURN_LONG( lngRet );
  67. }
  68. /* }}} */
复制代码


其中函数 nsms_ctrl_SendMsg 就是在DLL里面exports出来的__stdcall函数
原型就是在头文件里面注释的那个
//long __stdcall nsms_ctrl_SendMsg( const char * ump, const char * msg )

希望对你能有帮助

Good Luck
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP