#include "stdafx.h"
#include "iostream.h"
#include "atlbase.h"
#include "comdef.h" ???1
#pragma warning(push)
#pragma warning(disable : 4192)
#pragma warning(disable : 4146) ???6
#import "esriSystem.olb"
raw_interfaces_only??                            
raw_native_types??                               
no_namespace??                                   
named_guids??                                     ???7
exclude("OLE_COLOR"?? "OLE_HANDLE"?? "VARTYPE")
#import "esriGeometry.olb" raw_interfaces_only?? raw_native_types?? no_namespace?? named_guids
#import "esriDataSourcesFile.olb" raw_interfaces_only?? raw_native_types?? no_namespace?? named_guids
#import "esriGeoDatabase.olb" raw_interfaces_only?? raw_native_types?? no_namespace?? named_guids
???2
#pragma warning(pop)
???5
//CString VariantToString1(VARIANT * va);
???2
int main(int argc?? char* argv[])
{
::CoInitialize(NULL);
???1
IWorkspaceFactoryPtr pWSFactory(CLSID_ShapefileWorkspaceFactory);
IWorkspacePtr pWS;
// BSTR path;
// path = ::SysAllocString(L"C:\test");
HRESULT hr = pWSFactory->OpenFromFile(CComBSTR(L"C:\test\bj")??0??&pWS);
if (FAILED(hr) || pWS==NULL)
{
cerr<<"Failed to open the destination folder."<<endl;
return 1;
} ???1
IFeatureWorkspacePtr pFWS(pWS);
IFeatureClassPtr pFClass;
pFWS->OpenFeatureClass (CComBSTR(L"bj_est1")??&pFClass);
???3
IFeatureCursorPtr pFCursor;
pFClass->Search (NULL??VARIANT_TRUE??&pFCursor);
???7
long lngFieldCount ;
IFieldsPtr pFields;
IFieldPtr pField;
pFCursor->get_Fields (&pFields);
pFields->get_FieldCount (&lngFieldCount); ???4
IFeaturePtr pFeature;
pFCursor->NextFeature (&pFeature); ???8
USES_CONVERSION; ???9
long t;
CComBSTR bsValues;
CComVariant varValue;
esriFieldType esriFldType;
while (pFeature)
{
bsValues = CComBSTR(L"  ");
for (t =0; t < lngFieldCount ; t++)
{
pFields->get_Field(t?? &pField);
pField->get_Type(&esriFldType);
switch (esriFldType)
{
case (esriFieldTypeGeometry):
bsValues += CComBSTR(L"Shape  ");
break;
default:
pFeature->get_Value(t?? &varValue);
if (varValue.vt != VT_BSTR)
varValue.ChangeType(VT_BSTR); ???4
bsValues += varValue.bstrVal;
bsValues += CComBSTR(L"  ");
break;
}
} ???3
//  _bstr_t outString(bsValues??FALSE); //????1????????????????
//  cout << outString<<endl;
//????2?????????OLE2A???????????
//?????????? USES_CONVERSION;
cout << OLE2A(bsValues)<< endl;
pFCursor->NextFeature (&pFeature);
} ???6
pWSFactory=NULL;
pWS=NULL;
pFWS=NULL;
pFClass=NULL;
pFCursor=NULL;
pFields=NULL;
pField=NULL;
???8
::CoUninitialize();
???3
return 0;
} ???5