做了个DLL供PHP使用,请教如何加文件读取的功能啊
做了个DLL供PHP使用,请问怎么加文件读取的功能啊?
我是一个C++新手,在网上查了一些文件读取的例子,但是都报错,没有正常使用的,求各位大侠帮下忙,谢谢了。
我需要的就功能如下:
STDMETHODIMP CFun::ShowT(BSTR *n1, BSTR *pReturn)
{
}
n1 为要读取的文件绝对路径,
然后按这个种径读取到文件内容,在返回。
------解决方案--------------------
如果你用的是BSTR为路径的话,那你就用吧
_wfopen
我是一个C++新手,在网上查了一些文件读取的例子,但是都报错,没有正常使用的,求各位大侠帮下忙,谢谢了。
我需要的就功能如下:
STDMETHODIMP CFun::ShowT(BSTR *n1, BSTR *pReturn)
{
}
n1 为要读取的文件绝对路径,
然后按这个种径读取到文件内容,在返回。
------解决方案--------------------
如果你用的是BSTR为路径的话,那你就用吧
_wfopen
- C/C++ code
#include <stdio.h> #include <stddef.h> #include <stdlib.h> #include <wchar.h> #define BUFFER_SIZE 50 int main(int argc, char** argv) { wchar_t str[BUFFER_SIZE]; size_t strSize; FILE* fileHandle; // Create an the xml file in text and Unicode encoding mode. if ((fileHandle = _wfopen( L"_wfopen_test.xml",L"wt+,ccs=UNICODE")) == NULL) // C4996 // Note: _wfopen is deprecated; consider using _wfopen_s instead { wprintf(L"_wfopen failed!\n"); return(0); } // Write a string into the file. wcscpy_s(str, sizeof(str)/sizeof(wchar_t), L"<xmlTag>\n"); strSize = wcslen(str); if (fwrite(str, sizeof(wchar_t), strSize, fileHandle) != strSize) { wprintf(L"fwrite failed!\n"); } // Write a string into the file. wcscpy_s(str, sizeof(str)/sizeof(wchar_t), L"</xmlTag>"); strSize = wcslen(str); if (fwrite(str, sizeof(wchar_t), strSize, fileHandle) != strSize) { wprintf(L"fwrite failed!\n"); } // Close the file. if (fclose(fileHandle)) { wprintf(L"fclose failed!\n"); } return 0; }