I am doing excel file operations with C++ ADO.
I could select, update and insert.
It cannot be deleted.
enter code here
CString strFile = _T("C:\\temp\\sample.xlsx");
CString s;
try
{
CString strCon;
strCon.Format( _T( "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=%s;Extended Properties=Excel 12.0 xml" ) , strFile );
con.CreateInstance(__uuidof(Connection));
con->Open(_bstr_t(strCon), "", "", adConnectUnspecified);
_RecordsetPtr rs;
rs.CreateInstance(__uuidof(Recordset));
rs->CursorLocation = adUseClient;
rs->Open(_variant_t( "SELECT * FROM [test$] WHERE [ID]='A1'" ), con.GetInterfacePtr(), adOpenForwardOnly, adLockOptimistic, adCmdText );
if( !rs->GetadoEOF() )
{
rs->Delete(adAffectCurrent);
rs->Close();
}
}
catch(_com_error& e)
{
s=e.ErrorMessage();
}
if( con != NULL ) con->Close();
con = NULL;
Exception occurs in delete
Related
I'm using the below code to have the taskbar jumplist open the users default browser at certain pages.
Everything has been working fine for about a year now on Win 7/8 but with Windows 10 the browser is not called when the taskbar task is clicked and the Microsoft documentation shows no changes from Win 8 to 10.
bool SetUpJumpList( )
{
HRESULT hr;
CComPtr<ICustomDestinationList> pDestList;
hr = pDestList.CoCreateInstance ( CLSID_DestinationList , NULL , CLSCTX_INPROC_SERVER );
if ( FAILED ( hr ) )
{
return false;
}
hr = pDestList->SetAppID ( _TBID );
if ( FAILED ( hr ) )
{
return false;
}
UINT cMaxSlots;
CComPtr<IObjectArray> pRemovedItems;
hr = pDestList->BeginList ( &cMaxSlots , IID_PPV_ARGS ( &pRemovedItems ) );
if ( FAILED ( hr ) )
{
return false;
}
CComPtr<IObjectCollection> pObjColl;
hr = pObjColl.CoCreateInstance ( CLSID_EnumerableObjectCollection , NULL , CLSCTX_INPROC_SERVER );
if ( FAILED ( hr ) )
{
return false;
}
if ( !AddJumpListTasks ( pObjColl ) )
{
return false;
}
CComQIPtr<IObjectArray> pTasksArray = pObjColl;
if ( !pTasksArray )
{
return false;
}
hr = pDestList->AddUserTasks ( pTasksArray );
if ( FAILED ( hr ) )
{
return false;
}
hr = pDestList->CommitList( );
return SUCCEEDED ( hr );
}
bool AddJumpListTasks ( IObjectCollection* pObjColl )
{
wchar_t pBuf[ MAX_PATH ];
int bytes = GetModuleFileName ( NULL , pBuf , MAX_PATH );
CJumpListTask aTasks[ ] =
{
{ _T ( "https://www.google.co.uk" ) , _T ( "Home Page" ) , _T ( "Home" ) , 0 },
{ _T ( "https://www.google.co.uk" ) , _T ( "Twitter Page" ) , _T ( "Twitter" ) , 9 },
{ _T ( "https://www.google.co.uk" ) , _T ( "Facebook Page" ) , _T ( "Facebook" ) , 10 }
};
CString strBrowser;
DWORD size = 1024;
AssocQueryString ( 0 , ASSOCSTR_EXECUTABLE , L"http" , L"Open" , strBrowser.GetBufferSetLength ( size ) , &size );
for ( int i = 0; i < _countof ( aTasks ); i++ )
{
if ( !AddJumpListTask ( pObjColl , aTasks[ i ] , strBrowser , pBuf ) )
{
strBrowser.ReleaseBuffer( );
return false;
}
}
strBrowser.ReleaseBuffer( );
return true;
}
bool AddJumpListTask ( IObjectCollection* pObjColl , const CJumpListTask& rTask , LPCTSTR szExePath , LPCTSTR pBuf )
{
HRESULT hr;
CComPtr<IShellLink> pLink;
hr = pLink.CoCreateInstance ( CLSID_ShellLink , NULL , CLSCTX_INPROC_SERVER );
if ( FAILED ( hr ) )
{
return false;
}
hr = pLink->SetPath ( szExePath );
if ( FAILED ( hr ) )
{
return false;
}
hr = pLink->SetArguments ( rTask.szArgs );
if ( FAILED ( hr ) )
{
return false;
}
hr = pLink->SetIconLocation ( pBuf , rTask.nIconIndex );
if ( FAILED ( hr ) )
{
return false;
}
CComQIPtr<IPropertyStore> pPropStore = pLink;
PROPVARIANT pv;
if ( !pPropStore )
{
return false;
}
hr = InitPropVariantFromString ( CT2CW ( rTask.szTitle ) , &pv );
if ( FAILED ( hr ) )
{
return false;
}
hr = pPropStore->SetValue ( PKEY_Title , pv );
PropVariantClear ( &pv );
if ( FAILED ( hr ) )
{
return false;
}
hr = pPropStore->Commit( );
if ( FAILED ( hr ) )
{
return false;
}
hr = pObjColl->AddObject ( pLink );
return SUCCEEDED ( hr );
}
I've noticed several other applications such as CCleaner that also use this method do not function either but Microsoft applications such as Office 2013 still work so the question is how do I get this running again on Windows 10?
I'm certain this is not related to the customDestinations-ms files stored in the CustomDestinations folder as with a clean install of Windows 10 the same non functionality appears.
The taskbar task menu is created with the desired text and icon and debugging shows the correct URL is added along with the correct default browser and browser path.
Edit:
Using Visual Studio 2015 with toolset Windows XP v140_xp
As a workaround you could use, if possible for you, the MFC Class "CJumplist" from the latest Windows SDK.
We found out it would fix this issue, but only if using the latest SDK version. Using an older SDK using the same MFC class (eg Windows 7 SDK) would cause exactly the same issues you are experiencing.
This is a sample code working on Windows 10 with VC2013 and latest SDK (Target v12.0), but only when using MFC in a shared Dll. Linking with a static MFC Dll does not seem to work.
CJumpList *pJumpList = new CJumpList();
pJumpList->SetAppID(m_pszAppID);
result = pJumpList->AddTask(szPath, _T("-data1"), _T("number 4"), szPath, 0);
result = pJumpList->AddTask(szPath, _T("-data2"), _T("number 5"), szPath, 0);
pJumpList->CommitList();
delete pJumpList;
I do not know what changes Microsoft developers have done in this class to make it work. Our pure Win32 code suffers the same issues as you reported.
A little update to this, a reinstall of Windows due to other issues followed by a reinstall of VS but not checking the XP compatibility options results in the Jumplists working again, I dont need XP support anyhow but I assume this issue is related to the XP library's.
I am working an extension for Internet explorer to read network traffic using BHO in C++. My code is based on the following,
https://github.com/salsita/passthruapp
Is there a way that I can access cookies that are stored on the browser? I want to be able to read a cookie set for a particular domain and also store a cookie for the domain.
I used InternetGetCookieEx and InternetSetCookieEx. My goal was just to expire cookies so I had the following:
#define EXPIRED_COOKIE_DATE L"expires = Sat,01-Jan-2000 00:00:00 GMT"
void ExpireCookies( const CString& strUrl )
{
DWORD dwSize;
BOOL bResult = InternetGetCookieEx( strUrl, NULL, NULL, &dwSize, INTERNET_COOKIE_HTTPONLY, NULL );
if ( !bResult || dwSize <= 0 )
return;
TCHAR *lpszData = new TCHAR[dwSize];
LPCWSTR usrauth = NULL;
bResult = InternetGetCookieEx( strUrl, usrauth, lpszData, &dwSize, INTERNET_COOKIE_HTTPONLY, NULL );
if ( !bResult )
goto Exit;
{
CString cookieDataString( lpszData );
int nTokenPos = 0;
CString cookie = cookieDataString.Tokenize( _T( "; " ), nTokenPos );
while ( nTokenPos >= 0 )
{
int separator = cookie.Find( _T( '=' ) );
CString cookieName = cookie.Left( separator );
CString value = cookie.Mid( separator + 1 );
VERIFY( InternetSetCookieEx( strUrl, cookieName, EXPIRED_COOKIE_DATE, INTERNET_COOKIE_HTTPONLY, NULL ) );
cookie = cookieDataString.Tokenize( _T( "; " ), nTokenPos );
}
}
Exit:
SAFE_DELETE_ARR( lpszData );
}
Hope it helps you some!
I am trying to copy some blob data from one sqlite table to another in C++. However, once the data has been copied over to the new table, it seems to be getting corrupted. The said data contains some jpeg images. The code I am using to copy from TABLE1 to TABLE2 is shown below:
// Read the blob from the database
int64_t rowID = 0;
sscanf( id.c_str(), "%llu", &rowID );
sqlite3_blob* blobHandle = NULL;
if( sqlite3_blob_open( m_dbHandle_temp, "main", m_currentTileTable.c_str(), "tile_data", rowID, 0, &blobHandle ) != SQLITE_OK )
{
sqlite3_blob_close( blobHandle ); // An SQLite blob will be initialised regardless of the success of 'sqlite3_blob_open'
return false;
}
tiles_insert_statement.append( ")" );
// Copy blob to database
sqlite3_stmt *stmt = 0;
const char* tail;
sqlite3_prepare_v2( m_dbHandle, tiles_insert_statement.c_str(), strlen( tiles_insert_statement.c_str() )+1, &stmt, &tail );
int bindSuccess = sqlite3_bind_blob( stmt, 1, blobHandle, sqlite3_blob_bytes( blobHandle ), SQLITE_TRANSIENT );
if( sqlite3_step( stmt ) != SQLITE_DONE )
printf( "Error message: %s\n", sqlite3_errmsg( m_dbHandle ) );
sqlite3_finalize( stmt );
// close handles
sqlite3_blob_close( blobHandle );
Is there anything I am doing wrong in the above code, the reason I say that it is getting corrupted is because, I am reading the blobs on an android device to be displayed in an image viewer. The blobs in the TABLE 1 can be read and displayed fine, however the ones in TABLE 2 do not display anything. Any help is greatly appreaciated.
SOLUTION:
// Read the blob from the database
int64_t rowID = 0;
sscanf( id.c_str(), "%llu", &rowID );
sqlite3_blob* blobHandle = NULL;
if( sqlite3_blob_open( m_dbHandle_temp, "main", m_currentTileTable.c_str(), "tile_data", rowID, 0, &blobHandle ) != SQLITE_OK )
{
sqlite3_blob_close( blobHandle ); // An SQLite blob will be initialised regardless of the success of 'sqlite3_blob_open'
return false;
}
unsigned int length = sqlite3_blob_bytes( blobHandle );
// TODO - instances of this class OWN the buffer.
// Delete the buffer in the destructor ;)
unsigned char* buffer = new unsigned char[ length ];
if( sqlite3_blob_read( blobHandle, buffer, length, 0 ) != SQLITE_OK )
{
return false;
}
tiles_insert_statement.append( ")" );
sqlite3_stmt *stmt = 0;
const char* tail;
sqlite3_prepare_v2( m_dbHandle, tiles_insert_statement.c_str(), strlen( tiles_insert_statement.c_str() )+1, &stmt, &tail );
int bindSuccess = sqlite3_bind_blob( stmt, 1, buffer, length, SQLITE_TRANSIENT );
if( sqlite3_step( stmt ) != SQLITE_DONE )
printf( "Error message: %s\n", sqlite3_errmsg( m_dbHandle ) );
sqlite3_finalize( stmt );
// close handles
sqlite3_blob_close( blobHandle );
sqlite3_bind_blob expects a pointer to the actual blob data; it is not possible to use a blob handle for that.
To get the blob data as a memory chunk, execute a query like SELECT tile_data FROM MyTable WHERE ... and read the value with sqlite3_column_blob.
How can I pin application icon to metro start screen in win8 programmatically(c++)? I know how to do it manually. I also know that it will be added automatically once I launch that application.
I found this solution here
BOOL PinToStart( LPCWSTR szFilePath )
{
BOOL bSuccess = FALSE;
// break into file name and path
WCHAR lpszDirectoryName[ MAX_PATH ] = { 0 };
LPCWSTR lpszFileName = ::PathFindFileName( szFilePath );
wcscpy_s( lpszDirectoryName, szFilePath );
::PathRemoveFileSpec( lpszDirectoryName );
// load shell32.dll
HMODULE hShell32 = LoadLibrary( L"SHELL32" );
if( hShell32 != NULL )
{
// get the localized translation of 'Pin to Start' verb
WCHAR szPinToStartLocalized[ MAX_PATH ] = { 0 };
int nPinToStartLocalizedLength = LoadString( (HINSTANCE)hShell32, 51201, szPinToStartLocalized, MAX_PATH );
if( nPinToStartLocalizedLength > 0 )
{
// create the shell object
IShellDispatch *pShellDispatch = NULL;
HRESULT hr = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void**)&pShellDispatch);
if( SUCCEEDED( hr ) )
{
Folder *pFolder = NULL;
variant_t vaDirectory( lpszDirectoryName );
// get the namespace
if( SUCCEEDED( pShellDispatch->NameSpace( vaDirectory, &pFolder ) ) )
{
FolderItem *pItem = NULL;
bstr_t vaFileName( lpszFileName );
// parse the name
if( SUCCEEDED( pFolder->ParseName( vaFileName, &pItem ) ) )
{
FolderItemVerbs* pVerbs = NULL;
// get the verbs
if( SUCCEEDED( pItem->Verbs(&pVerbs) ) )
{
long nCount = 0;
if( SUCCEEDED ( pVerbs->get_Count( &nCount ) ) )
{
variant_t vaIndex;
vaIndex.vt = VT_I4;
// iterate through verbs
for( vaIndex.lVal = 0; vaIndex.lVal<nCount; vaIndex.lVal++ )
{
FolderItemVerb* pVerb = NULL;
if( SUCCEEDED( pVerbs->Item( vaIndex, &pVerb ) ) )
{
BSTR bstrVerbName = NULL;
// check for 'Pin to Start' verb
if( SUCCEEDED( pVerb->get_Name( &bstrVerbName ) ) )
{
if( 0 == wcscmp( bstrVerbName, szPinToStartLocalized ) )
{
bSuccess = SUCCEEDED( pVerb->DoIt() );
vaIndex.lVal = nCount; // break for
}
::SysFreeString( bstrVerbName );
}
pVerb->Release();
} // if
} // for
}
pVerbs->Release();
}
pItem->Release();
}
pFolder->Release();
}
pShellDispatch->Release();
}
}
::FreeLibrary( hShell32 );
}
return bSuccess;
}
Hope it's help you
I have a fairly simple application that contains the following:
context->mFaceTracker = FTCreateFaceTracker();
hr = context->mFaceTracker->Initialize( &mVideoCameraConfig, &mDepthCameraConfig, NULL, NULL );
which works fine and returns S_OK and mFaceTracker is (as far as I can tell) initialized properly. However, the next line is:
hr = context->mFaceTracker->CreateFTResult( &context->mFTResult );
which always returns FT_ERROR_UNINITIALIZED, doesn't allocate the pointer, and has me puzzled. I've tried many different strategies for getting this to work from changing how the threading for the device and detector works, to changing my FTcontext object from a class to a struct to match the samples, all with no success. The Kinect SDK samples all work fine, but trying to use them in my own application doesn't seem to, despite my closely mirroring how they initialize the device and the Face Tracker. I'm curious if anyone else has run into this or similar problems around initializing either IFTFaceTracker or the IFTResult. Also, I'm curious how else I can test the IFTFaceTracker for correct intialization, other than testing the HRESULT that Initialize() returns. Thanks in advance,
=== edit
I've had a few request for more code. It's built on Cinder and is using this block for Cinder: https://github.com/BanTheRewind/Cinder-KinectSdk
I can't post all of the code, but I've posted at least most of the relevant Kinect initialization code here:
void Kinect::start( const DeviceOptions &deviceOptions )
{
if ( !mCapture ) {
// Copy device options
mDeviceOptions = deviceOptions;
string deviceId = mDeviceOptions.getDeviceId();
int32_t index = mDeviceOptions.getDeviceIndex();
// Clamp device index
if ( index >= 0 ) {
index = math<int32_t>::clamp( index, 0, math<int32_t>::max( getDeviceCount() - 1, 0 ) );
}
// Initialize device instance
long hr = S_OK;
if ( index >= 0 ) {
hr = NuiCreateSensorByIndex( index, &mSensor );
if ( FAILED( hr ) ) {
trace( "Unable to create device instance " + toString( index ) + ": " );
error( hr );
return;
}
} else if ( deviceId.length() > 0 ) {
_bstr_t id = deviceId.c_str();
hr = NuiCreateSensorById( id, &mSensor );
if ( FAILED( hr ) ) {
trace( "Unable to create device instance " + deviceId + ":" );
error( hr );
return;
}
} else {
trace( "Invalid device name or index." );
return;
}
// Check device
hr = mSensor != 0 ? mSensor->NuiStatus() : E_NUI_NOTCONNECTED;
if ( hr == E_NUI_NOTCONNECTED ) {
error( hr );
return;
}
// Get device name and index
if ( mSensor != 0 ) {
mDeviceOptions.setDeviceIndex( mSensor->NuiInstanceIndex() );
BSTR id = ::SysAllocString( mSensor->NuiDeviceConnectionId() );
_bstr_t idStr( id );
if ( idStr.length() > 0 ) {
std::string str( idStr );
mDeviceOptions.setDeviceId( str );
}
::SysFreeString( id );
} else {
index = -1;
deviceId = "";
}
flags |= NUI_INITIALIZE_FLAG_USES_COLOR;
}
hr = mSensor->NuiInitialize( flags );
if ( FAILED( hr ) ) {
trace( "Unable to initialize device " + mDeviceOptions.getDeviceId() + ":" );
error( hr );
return;
}
hr = mSensor->NuiSkeletonTrackingEnable( 0, flags );
if ( FAILED( hr ) ) {
trace( "Unable to initialize skeleton tracking for device " + mDeviceOptions.getDeviceId() + ": " );
error( hr );
return;
}
mIsSkeletonDevice = true;
mThread = CreateThread(NULL, 0, &Kinect::StaticThread, (PVOID)this, 0, 0);
}
}
DWORD WINAPI Kinect::StaticThread(PVOID lpParam)
{
Kinect* device = static_cast<Kinect*>(lpParam);
if (device)
{
return device->run();
}
return 0;
}
void run() {
if(mSensor) {
if(mEnabledFaceTracking)
{
if(mNeedFaceTracker) {
mFaceTracker = new FaceTracker(
mDeviceOptions.getVideoSize().x,
mDeviceOptions.getVideoSize().y,
mDeviceOptions.getDepthSize().x,
mDeviceOptions.getDepthSize().y,
1.0,
1 );
mNeedFaceTracker = false;
}
// make sure we have both color && depth buffers to work with
if(newDepth || newVideo)
{
FT_SENSOR_DATA sensorData(mFTColorImage, mFTDepthImage);
FT_VECTOR3D hint[2]; // this is initialized elsewhere
mFaceTracker->checkFaces( (NUI_SKELETON_FRAME*) &skeletonFrame, mFTColorImage, mFTDepthImage, 1.0, 0);
if(mFaceTracker->getNumFaces() > 0) {
cout << " we have a face " << mFaceTracker->getNumFaces() << endl;
mNewFaceTrackData = true;
mFaceData.clear();
for( int i = 0; i < mFaceTracker->getNumFaces(); i++) {
Face newFace;
mFaceTracker->getProjectedShape(0, newFace.scale, newFace.rotation, newFace.transform, newFace.screenPositions);
mFaceData.push_back(newFace);
}
}
}
}
Sleep( 8 );
}
}
It looks like you never call (or omitted including in the code sample) NuiImageStreamOpen(), such as this code snippet from the SingleFace sample, KinectSensor.cpp in the Init method:
hr = NuiImageStreamOpen(
colorType,
colorRes,
0,
2,
m_hNextVideoFrameEvent,
&m_pVideoStreamHandle );
if (FAILED(hr))
{
return hr;
}
hr = NuiImageStreamOpen(
depthType,
depthRes,
(bNearMode)? NUI_IMAGE_STREAM_FLAG_ENABLE_NEAR_MODE : 0,
2,
m_hNextDepthFrameEvent,
&m_pDepthStreamHandle );
Calling those before you call CreateFTResult() may fix the uninitialized error.
Additionally, you call CreateThread() and then call run(), but there is no while loop so that thread will exit almost immediately, certainly without enough time for the Kinect to start providing data to the FaceTracking.
It doesn't look like you have included the Thread or event loop that is checking the sensor for new data, updating mFTColorImage and mFTDepthImage, and setting the newDepth and newVideo flags. This could be in the same thread that you create above (provided you create a while loop, and ignoring performance or other classes needing the Kinect data), or could be a different thread as in the SingleFace Kinect SDK sample.