簡體   English   中英

C ++ PHP擴展

[英]C++ PHP extension

我寫了一個非常簡單的PHP擴展。 現在,我希望它在啟動時讀入文件。 這是我的代碼:

#define PHP_COMPILER_ID  "VC6"


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


int number = 0;
ZEND_FUNCTION(use_html);

//declaration
ZEND_MINIT_FUNCTION(use_html);
zend_function_entry use_functions[] = 
{
    ZEND_FE(use_html, NULL)
    {NULL, NULL, NULL}
};

zend_module_entry use_html_module_entry = 
{
    STANDARD_MODULE_HEADER,
    "First_Extension",
    use_functions,
    ZEND_MINIT(use_html), 
    NULL, NULL, NULL, NULL,
    "1.0.0-tutorial",
    STANDARD_MODULE_PROPERTIES
};

ZEND_GET_MODULE(use_html);

ZEND_FUNCTION(use_html)
{
     bool useHtml;

     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &useHtml) == FAILURE)
     {
         E_ERROR;
         return;
     }

     if(useHtml)
     {
         php_printf("This string uses <a href='#'>Html</a>");
     }
     else
     {
         int sum = 0;
         int i = 0;
         for(i;i<100000;i++)
             sum += i;

         RETURN_LONG(number);
     }

     return;
}

ZEND_MINIT_FUNCTION(use_html)
{
    std::ifstream infile("file.txt");
    number++;
    return SUCCESS;
}

錯誤消息是:錯誤5錯誤C2491:'std :: endl':不允許dllimport函數的定義c:\\ program files \\ microsoft visual studio 10.0 \\ vc \\ include \\ ostream 1004 1 php_extension1

我也嘗試更改包含的順序,但沒有幫助。

編輯

這是來自ostream的問題部分

_CRTIMP2_PURE inline basic_ostream<char, char_traits<char> >&
    __CLRCALL_OR_CDECL endl(basic_ostream<char, char_traits<char> >& _Ostr)
    {   // insert newline and flush byte stream
    _Ostr.put('\n');
    _Ostr.flush();
    return (_Ostr);
    }

我找到了一個解決方案:對於php擴展開發,我僅在zend_config.w32.h中添加#include <string> ,並且編譯良好。 有關更多信息: http : //social.msdn.microsoft.com/Forums/hu-HU/vcgeneral/thread/94ed21c2-7128-4149-8a8f-05fc195a812c

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM