COM/ATL项目 [英] COM/ATL project
问题描述
为了列出文件夹中的文件名:
In order to list the filenames from folder:
FileName(BSTR path,BSTR* Retname, LONG* counter)
{
WIN32_FIND_DATA FindData;
HANDLE FindHandle = FindFirstFile(path, &FindData);
BSTR Filelist[1000];
int i=0;
if (FindHandle != INVALID_HANDLE_VALUE)
{
do
{
Filelist[i]= FindData.cFileName;
*Retname++=Filelist[i];
++(*counter);
} while (FindNextFile(FindHandle, &FindData) != 0);
FindClose(FindHandle);
}
这是创建组件时给出的函数定义... 在客户端:
this is the function definition given while creating the component... In the client side :
BSTR *Retname;
BSTR Filelist[1000];
long count = 0;
long *counter ;
counter = &count;
Retname=Filelist;
hr=pIfiles->FileName(L"C:\\Dynamiclinklibrary\\text\\*.txt",Filelist,&count);
std::cout<<"Number of files in a folder : " << count << std::endl<< std::endl;
for(int i =0;i < count ;i++)
{
std::cout <<"filenames are: " <<Filelist<< std::endl;
//Retname++;
}
在运行时仅获取文件名的地址,而未获取文件名..我做了什么错误..请帮助..
while running im getting only the address of the filenames ,im not getting the filenames ..what mistake i ve done..please help..
推荐答案
ostream<<操作员不知道如何解密BSTR,因此它将BSTR视为一个整数并输出您看到的地址.将它们强制转换为char *(如果使用UNICODE,则将其转换为wchar_t)
The ostream << operator does not know how to decipher a BSTR so it treats it as an int and outputs the addresses that you are seeing. Cast them to a char* (or wchar_t if using UNICODE)
首先:格式化您的问题!没有人愿意读这个问题.如果只是将其作为文本和代码的随机组合发布.
First of all: format your question! No one will bother to read the question if you just post it as a random mix of text and code.
其次,在COM/ATL问题中,也最好发布* .idl文件内容.
Secondly in a COM/ATL question it might be a good idea to also post your *.idl file contents.
最后看一下您的代码,我想到一件事:BSTR应该在服务器端分配,并在客户端释放.查看:SysAllocString和SysFreeString.
And finally looking at your code one thing pops to mind: BSTR should be allocated on the server side and freed on the client side. Look at: SysAllocString and SysFreeString.
这篇关于COM/ATL项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!