php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13266 Maybe not a PHP Library ?
Submitted: 2001-09-12 11:40 UTC Modified: 2001-09-13 02:02 UTC
From: atur at vigorsoft dot com Assigned:
Status: Not a bug Package: Dynamic loading
PHP Version: 4.0.6 OS: Windows NT 4.0
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: atur at vigorsoft dot com
New email:
PHP Version: OS:

 

 [2001-09-12 11:40 UTC] atur at vigorsoft dot com
HI,

I am trying to load newly made PHP extension module (C++).
(e.g. mymodule.dll) using dl().

The error when accessing PHP file in browser with Apache Web Server is :

"Invalid Library (Maybe not a PHP Library) mymodule.dll"

I used these configurations :

PHP 4.0.6
Apache 1.3.20
Windows NT 4.0
Visual C++ 6.0

Comments Please.

Thanks.

Atur Shah.
(aturshah@hotmail.com)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-12 11:51 UTC] hholzgra@php.net
support problem and most likely not a bug (at least not enough info to find out), please ask the phpdev mailing list (and give more info)
 [2001-09-12 12:26 UTC] mfischer@php.net
Make sure your module entry is in the source

#ifdef COMPILE_DL_YOURMODULE
ZEND_GET_MODULE(yourmodule)
#endif

- Markus
 [2001-09-13 01:43 UTC] atur at vigorsoft dot com
Hi,

The module entry is in the source..
I am pasting header and source file for reference..

---------------------------------------------------------------------------
/* ------------------------------------------ */
/* php_mymodule.h --- after removing comments */
/* ------------------------------------------ */

#ifndef PHP_MYMODULE_H
#define PHP_MYMODULE_H

extern zend_module_entry mymodule_module_entry;
#define phpext_mymodule_ptr &mymodule_module_entry

#ifdef PHP_WIN32
#define PHP_MYMODULE_API __declspec(dllexport)
#else
#define PHP_MYMODULE_API
#endif

extern "C"
{
PHP_FUNCTION(confirm_mymodule_compiled);
}

#ifdef ZTS
#define MYMODULE_G(v) (mymodule_globals->v)
#define MYMODULE_LS_FETCH() zend_mymodule_globals *mymodule_globals = ts_resource(mymodule_globals_id)
#else
#define MYMODULE_G(v) (mymodule_globals.v)
#define MYMODULE_LS_FETCH()
#endif

#endif	/* PHP_MYMODULE_H */

/* ------------------------------------------ */
/* mymodule.cpp --- after removing comments   */
/* ------------------------------------------ */

#define DHAVE_APDEBUG 1 
#define DCOMPILE_DL_APDEBUG 1
#define ZTS 1

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "php.h"
#include <iostream.h>

extern "C"
{
#include "ext/standard/info.h"
#include "php_globals.h"
#include "php_ini.h"
#include "php_mymodule.h"
}

/* True global resources - no need for thread safety here */
static int le_mymodule;

/* Every user visible function must have an entry in mymodule_functions[]. */
function_entry mymodule_functions[] = {
	PHP_FE(confirm_mymodule_compiled,NULL)
	{NULL, NULL, NULL}	
};

zend_module_entry mymodule_module_entry = {
	"mymodule",
	mymodule_functions,
	NULL,NULL,NULL,NULL,NULL,
	STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_MYMODULE
extern "C"
{
ZEND_GET_MODULE(mymodule)
}
#endif

PHP_FUNCTION(confirm_mymodule_compiled)
{
	zval **arg;
	int len;
	char string[256];

	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) 
	{WRONG_PARAM_COUNT;}

	convert_to_string_ex(arg);

	len = sprintf(string, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "mymodule", Z_STRVAL_PP(arg));
	RETURN_STRINGL(string, len, 1);
}
---------------------------------------------------------------------------

Regards,

Atur Shah

 [2001-09-13 02:02 UTC] hholzgra@php.net
once again: ask the phpdev mailing list, please

supscription information can be found
on http://php.net/support.php
 [2003-09-20 01:53 UTC] adrian at ideasvivas dot com
I Found this answer in this url;
www.faqts.com/knowledge_base/index.phtml/fid/68 
ANSWER:
=======

You forgot to set the appropriate preprocessor flags for your C code.

If you look hard at the C code that the 'ext_skel' script makes for
you, you will see a small section that looks something like this:

#ifdef COMPILE_DL_MYMODULE
ZEND_GET_MODULE(mymodule)
#endif

If you do not set the value for 'COMPILE_DL_MYMODULE' into your
preprocessor, then php.exe will not recognize your module as 
a php dll.  To do this in Visual C++, go to

Project > Settings > c/c++ tab 

Set Category to Preprocessor, and add COMPILE_DL_MYMODULE to the
end of your preprocessor definitions.  You should probably also
leverage ZEND_WIN32 and PHP_WIN32 if you have windows specific
code that you wish to wrapper in preprocessors.

Welcome,
Bex
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Sep 22 08:01:23 2020 UTC