freehandle Posted May 14, 2009 Share Posted May 14, 2009 Hello All, I am a beginner to PHP. I tried the following link "http://www.devarticles.com/c/a/Cplusplus/Developing-Custom-PHP-Extensions-Part-1/2/" to build a extension called php_devarticles.dll. I was successfully able to build it through Visual Studio 6.0 The hello_world.c which was a part of dll building looked like this -- /* include standard header */ /* you will need to include this in all of your php extension projects*/ #include "php.h" /* All the functions that will be exported (available) must be declared */ ZEND_FUNCTION(hello_world); PHP_MINFO_FUNCTION(devarticlesmod); /* Just a basic int to be used as a counter*/ int i; /* function list so that the Zend engine will know what’s here */ zend_function_entry devarticlesmod_functions[] = { ZEND_FE(hello_world, NULL) {NULL, NULL, NULL} }; /* module information */ zend_module_entry devarticlesmod_module_entry = { STANDARD_MODULE_HEADER, "DevArticles", devarticlesmod_functions, NULL, NULL, NULL, NULL, PHP_MINFO(devarticlesmod), NO_VERSION_YET, STANDARD_MODULE_PROPERTIES }; #if COMPILE_DL_DEVARTICLES_MOD ZEND_GET_MODULE(devarticlesmod) #endif PHP_MINFO_FUNCTION(devarticlesmod) { php_info_print_table_start(); php_info_print_table_row(2, "DevArticles Extension", "All Systems Go"); php_info_print_table_end(); } ZEND_FUNCTION(hello_world) { for(i=0;i<5;i++) { zend_printf("Hello World<br>"); } } When I build it and add to the ext directory where other dlls are present , and in php.ini I include extension=php_devarticlesmod.dll and also uncomment (just an example) extension=php_ldap.dll But during the IIS start-up i get the following error. [14-May-2009 20:49:04] PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'php_devarticlesmod.dll' in Unknown on line 0 Please can anybody help me to tell wats wrong in this. just add more information: <? echo phpinfo(); echo sqrt(9); ?> works but php_devarticles.dll has a function called hello_world() -- <? hello_world(); ?> Does not work Link to comment https://forums.phpfreaks.com/topic/158141-hello-world-does-not-work/ Share on other sites More sharing options...
cwarn23 Posted May 30, 2009 Share Posted May 30, 2009 You may want to note that the code you've posted is C code and not C++ code. So make sure the source code file ends in .c and that there are no compilation errors. I too am having the same problem but with the tutorial at http://www.talkphp.com/vbarticles.php?do=article&articleid=49&title=creating-custom-php-extensions So other than the advice I have posted above (the source extensension), I too have a simular error but for me it's in c++ and not c. And my c++ code is as follows: main.cpp #include "stdafx.h" ZEND_FUNCTION(fetch_talkphp_links); zend_function_entry talkphp_ext_functions[] = { ZEND_FE(fetch_talkphp_links, NULL) {NULL, NULL, NULL} }; zend_module_entry talkphp_ext_module_entry = { STANDARD_MODULE_HEADER, "TalkPHP Extension", talkphp_ext_functions, NULL, NULL, NULL, NULL, NULL, "1.0", STANDARD_MODULE_PROPERTIES }; ZEND_GET_MODULE(talkphp_ext); ZEND_FUNCTION(fetch_talkphp_links) { bool useHtml = false; char *link = ""; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &useHtml) == FAILURE) { RETURN_STRING("Missing Parameter", true); } if (useHtml == true) { link = "<a href=\"http://www.talkphp.com\">Visit TalkPHP.com!</a>"; } else { link = "http://www.talkphp.com"; } RETURN_STRING(link, true); } stdafx.h #pragma once // Include the Zend Win32 header and the general PHP header #include "zend_config.w32.h" #include "php.h" Php Code: <? echo echo fetch_talkphp_links(true); ?> Error: Fatal error: Call to undefined function fetch_talkphp_links()... Just a note, I have rebooted apachie and recompiled this code many times and yet still it will not communicate with php like on post #1. I have even double checked and re-checked the tutorial to make sure I haven't done anything wrong. And I'm using Visual C++ 2008 with Windows XP Pro. So I would really like to know what is the problem with both of our codes as they are so simular. Link to comment https://forums.phpfreaks.com/topic/158141-hello-world-does-not-work/#findComment-845689 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.