Page 1 of 1

problem writing an extension

Posted: Thu Jan 14, 2010 9:55 am
by gerhard_wien
Hello,

I try to write an extension to php5 on a Windows XP-system using Visual C++ 2008
I succeeded in compiling the "skeleton" extension as a DLL.
I can load it into php.
I can see its exported functions with "php --re extname"
Extension [ <persistent> extension #52 extname version 0.1 ] {

- Functions {
Function [ <internal:extname> function confirm_extname_compiled ] {
}
}

BUT:
I dont get any output:
php -r "confirm_extname_compiled('A');" outputs only an empty line.

As php -r "confirm_extname_compiled();" gives a warning about the missing parameter to confirm_extname_compiled(), I'm pretty sure, the function gets called.

The .h and .c file ist attached...
What might be wrong??

Thanks in advance for any hints!

Gerhard

Re: problem writing an extension

Posted: Thu Jan 14, 2010 10:03 am
by AbraCadaver
I don't see any code attached. What does the function print/return?

Re: problem writing an extension

Posted: Thu Jan 14, 2010 10:13 am
by gerhard_wien
Sorry, somehow I made an mistake when uploading...
I'll try again. Anyhow, here is the function:

Code: Select all

PHP_FUNCTION(confirm_extname_compiled)
{
    char *arg = NULL;
    int arg_len, len;
    char string[256];
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
        return;
    }
 
    len = sprintf(string, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "extname", arg);
    RETURN_STRINGL(string, len, 1);
}
I tried a "simpler" version:

Code: Select all

PHP_FUNCTION(say_hello)
{
    RETURN_STRING("Hello World", 1);
}
It dosn't wor either.

Gerhard

Re: problem writing an extension

Posted: Thu Jan 14, 2010 10:26 am
by AbraCadaver
Your function doesn't output anything, it just returns it, so:

Code: Select all

echo confirm_extname_compiled('A');

Re: problem writing an extension

Posted: Fri Jan 15, 2010 12:58 am
by gerhard_wien
Shame on me!


Thanks for your help.
Gerhard