上下文:Windows 7,XLW 5.x,Microsoft Excel 2007,Visual Studio 2010,C ++
给出以下代码......
#import "c:\windows\system32\scrrun.dll" raw_interfaces_only, \
raw_native_types, \
named_guids, \
rename("DeleteFile", "_DeleteFile"), \
rename("MoveFile","_MoveFile"), \
rename("CopyFile", "_CopyFile"), \
rename("GetFreeSpace", "_GetFreeSpace")
using namespace Scripting;
我现在如何实例化FileSystemObject并调用其方法?
答案 0 :(得分:1)
这对我有用
std::wstring fileExists(std::wstring name)
{
VARIANT_BOOL b = 0;
::CoInitialize(NULL);
{
CComPtr<IFileSystem> spFSO;
HRESULT hr = spFSO.CoCreateInstance(L"Scripting.FileSystemObject");
if (SUCCEEDED(hr) && spFSO)
{
BSTR theName = SysAllocStringLen( name.data(), name.size());
hr = spFSO->FileExists(theName, &b);
}
}
::CoUninitialize();
return (b == -1) ? L"Exists" : L"Doesn't exist";
}
这至少让我与这个功能联系在一起。这种情况仍然是正确的,但这超出了发布的范围。