How to call PHP extension function from C++ code

General discussion on PHP

How to call PHP extension function from C++ code

Postby neostar666 on Thu Feb 07, 2013 2:51 pm

Hi to everybody.

I’ve created an extension DLL for PHP 5.2.17 for Windows. The extension contains a function. In the function I’ve been trying to load another extension DLL for PHP, and then tried to call a function from this (second) DLL.

A piece of code, describing a situation, is represented below:

Code: Select all
ZEND_FUNCTION(test)
{              
    LPCWSTR test = TEXT("php_some_extension.dll");
   
    HINSTANCE hGetProcIDDLL = LoadLibrary(test);   
 
    FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL), "get_module");
   
    typedef zend_module_entry * (__stdcall * pICFUNC)();

    pICFUNC getModuleFunction = pICFUNC(lpfnGetProcessID);
 
    zend_module_entry * module = getModuleFunction();
    zend_function_entry * func = module->functions;

    zval * input;
    zval * result;
   
    while (func->fname)
    {
        if (strcmp(func->fname, "function_name_that_we_need_to_call") == 0)
        {
            func->handler(1, input, &result, ???, 1, ???);
         
            RETURN_RESOURCE(result);
        }

        func++;
    }
}


Notes:

function_name_that_we_need_to_call - This function takes a parameter of a “string” type and return a result of the “resource” type.
handler - This is a macros called INTERNAL_FUNCTION_PARAMETERS:

#define INTERNAL_FUNCTION_PARAMETERS int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used TSRMLS_DC

The main question is:
What exactly parameters do I need to pass to func->handler ? Are there any examples?

Will appreciate any help,
Regards,
Igor
neostar666
 
Posts: 1
Joined: Thu Feb 07, 2013 2:45 pm

Return to PHP

Who is online

Users browsing this forum: No registered users and 4 guests