locked
File Synchronization in C++ using MicroSoft Sync Framework RRS feed

  • Question

  • I want to synchronize files between two folders.

    Actually i search on it lot and found some sample code also here :: http://msdn.microsoft.com/en-us/library/bb902809.aspx#Y765

    But this example has too many errors...and somewhat complicated.

    Can Anyone will tell me where i would find simple example for sync between two files using c++ and Sync Framework.

    Wednesday, February 2, 2011 5:10 AM

Answers

All replies

  • Hi Sachin

    All of our file synchronization samples are in managed code, you can look at the following samples (they are in C#)

     


    Maria del Mar Alvarez Rohena Microsoft Sync Framework
    Wednesday, February 2, 2011 7:11 PM
  • Thanks for reply...

    I want to use sync framework in c++ only. thats requirement....

    I am searching it lot but cant find not even single example....

    I am beginner and not finding way to do it...

    please help me regarding......

    Thanks in advance...

    Thursday, February 3, 2011 12:39 PM
  • Please help me regarding this.....I am still in search......... 

    Nobody knows how to do it in c++..........???????????

    Friday, February 4, 2011 9:13 AM
  • Hi again Sachin

    This is actually the example that you want to be looking at, "How to: Synchronize Files by using Unmanaged Code" http://msdn.microsoft.com/en-us/library/cc305401.aspx

    The other sample is for creating custom synchronization provider, and you do not need to do that, since there Microsoft Synchronization Framework ships a ready to use file synchronization provider.

    For other help regarding synchronizing files, take a look at the rest of the Synchronizing Files documentation here http://msdn.microsoft.com/en-us/library/bb902860.aspx 


    Maria del Mar Alvarez Rohena Software Engineer in Test II Microsoft Synchronization Framework
    Friday, February 4, 2011 7:30 PM
  • Hi,

    hopes are alive......

    Thanks a lot............

    i am already refering that example......i compiled it successfuly...But with what i missunderstand is ::

    HRESULT CFileSynchronizerDlg::Synchronize(

    const GUID* pguidReplicaSrc, BSTR bstrFolderSrc,

    BSTR bstrMetaSrc,

    const GUID* pguidReplicaDest, BSTR bstrFolderDest,

    BSTR bstrMetaDest)

     

    parameters which are in bold...i thought i need to implement Replica related information and should pass values to this method.....

    I am still in confuse how to deal with that two parameters.I have written code in Win32 Console application.it is compiled succesfully......But

    CoCreateInstance(CLSID_FileSyncProvider,....)

    not returning any value to me.....

    please take a look by your experinced eyes..........please suggest change  i should go....i thing i am near to do it....

    /********************* Win32 Console Application **************************/

    /****** header files **************************************/

    #include

     

    "stdafx.h"

    #include

     

    "atlbase.h"

    #include

     

    "atlcom.h"

    #include

     

    <synchronization.h>

    #include

     

    <filesyncprovider.h>

    #include

     

    <wtypes.h>

    #include

     

    <iostream>

    using namespace std;

     

    /*****************************************/


    /********* Class  CFileSynchronizerDlg *************************/

     

    class

     

    CFileSynchronizerDlg

    {

     

            public:

                   HRESULT Synchronize(

    const GUID* pguidReplicaSrc, BSTR bstrFolderSrc,

                                                 BSTR bstrMetaSrc,

    const GUID* pguidReplicaDest, BSTR bstrFolderDest,

                                                BSTR bstrMetaDest);

    };

    /*****************************************/

    HRESULT CFileSynchronizerDlg::Synchronize(

    const GUID* pguidReplicaSrc, BSTR bstrFolderSrc,

    BSTR bstrMetaSrc,

    const GUID* pguidReplicaDest, BSTR bstrFolderDest,

    BSTR bstrMetaDest)

    {

    HRESULT hr = E_UNEXPECTED;

     

    // Create the source and destination providers.

    IFileSyncProvider* pProvSrc = NULL;

    hr = CoCreateInstance(CLSID_FileSyncProvider, NULL, CLSCTX_INPROC_SERVER,

     

    __uuidof(pProvSrc), (void**)&pProvSrc);

     

     

    if (SUCCEEDED(hr))

    {

    cout<<

    "CoCreateInstance FileSync source provider suceessfully"<<endl;

    IFileSyncProvider* pProvDest = NULL;

    hr = CoCreateInstance(CLSID_FileSyncProvider, NULL, CLSCTX_INPROC_SERVER,

     

    __uuidof(pProvDest), (void**)&pProvDest);

     

    if (SUCCEEDED(hr))

    {

     

    // Create a scope filter and fill it (some strings may be empty).

    cout<<

    "CoCreateInstance FileSync dest provider suceessfully"<<endl;

    IFileSyncScopeFilter* pFilter = NULL;

    hr = pProvSrc->CreateNewScopeFilter(&pFilter);

     

    if (SUCCEEDED(hr))

    {

     

    //cout<<"Enter Filename to be Excluded..."<<endl;

    CComBSTR ExcludeFileName=L

    "*.lnk";

     

    hr = pFilter->SetFilenameExcludes(ExcludeFileName);

     

    if (SUCCEEDED(hr))

    {

    CComBSTR ExcludeDirName=L

    "";

    hr = pFilter->SetSubDirectoryExcludes(ExcludeDirName);

    }

     

    if (SUCCEEDED(hr))

    {

    CComBSTR m_strAttrExc=

    "";

    DWORD dwMask = wcstoul(m_strAttrExc, NULL, 16);

    hr = pFilter->SetFileAttributeExcludeMask(dwMask);

    }

     

    if (SUCCEEDED(hr))

    {

     

     

    //if (!m_strFilenameInc.IsEmpty())

     

    // {

    CComBSTR strFilenameInclude=L

    "*.txt";

    hr = pFilter->SetFilenameIncludes(strFilenameInclude);

     

    // }

    }

     

    if (SUCCEEDED(hr))

    {

     

    // Initialize the providers.

     

    hr = pProvSrc->Initialize(*pguidReplicaSrc, bstrFolderSrc,

    bstrMetaSrc, NULL,

    FILESYNC_INIT_FLAGS_NONE, pFilter, NULL, NULL);

     

     

    if (SUCCEEDED(hr))

    {

    cout<<

    " FileSync source initialisation suceessfully"<<endl;

    hr = pProvDest->Initialize(*pguidReplicaDest, bstrFolderDest,

    bstrMetaDest, NULL,

    FILESYNC_INIT_FLAGS_NONE, pFilter, NULL, NULL);

     

    if (SUCCEEDED(hr))

    cout<<

    " FileSync dest initialisation suceessfully"<<endl;

    }

    }

    pFilter->Release();

    }

     

    if (SUCCEEDED(hr))

    {

     

    // Synchronize!

    IApplicationSyncServices* pSvc = NULL;

    hr = CoCreateInstance(CLSID_SyncServices, NULL, CLSCTX_INPROC_SERVER,

    IID_IApplicationSyncServices, (

    void**)&pSvc);

    cout<<

    "CoCreateInstance FileSync SERVICES suceessfully"<<endl;

     

    if (SUCCEEDED(hr))

    {

    ISyncSession* pSession = NULL;

    hr = pSvc->CreateSyncSession(pProvDest, pProvSrc, &pSession);

     

    if (SUCCEEDED(hr))

    {

    cout<<

    "CreateSyncSession success ......."<<endl;

    SYNC_SESSION_STATISTICS syncStats;

    hr = pSession->Start(CRP_NONE, &syncStats);

     

    if (SUCCEEDED(hr))

    cout<<

    "Session started ......."<<endl;

    pSession->Release();

    }

    pSvc->Release();

    }

    }

    pProvDest->Release();

    }

    pProvSrc->Release();

    }

     

    return hr;

    }

     

    Entry Point Function

    /******************Entry Point Function  ***********************/

     

    int _tmain(int argc, _TCHAR* argv[])

    {

    GUID pguidReplicaSrc;

    CoCreateGuid(&pguidReplicaSrc);

    GUID pguidReplicaDest;

    CoCreateGuid(&pguidReplicaDest);

     

    CComBSTR bstrFolderSrc=L

    "F:\\test";

    CComBSTR bstrFolderDest=L

    "G:\\Test";

    CComBSTR bstrMetaSrc=L

    "F:\\test";

    CComBSTR bstrMetaDest=L

    "G:\\Test";

    CFileSynchronizerDlg *obj=

    new CFileSynchronizerDlg();

     

    obj->Synchronize(&pguidReplicaSrc,bstrFolderSrc,

    bstrMetaSrc,&pguidReplicaDest,bstrFolderDest,bstrMetaDest);

     

     

    return 0;

    }

     

    Monday, February 7, 2011 7:24 AM
  •  I want to write file syncrinizer in c++.

    i am reffering example given here http://msdn.microsoft.com/en-us/library/cc305401.aspx.

    can any one tell me how to pass const GUID* pguidReplicaSrc pguidReplicaSrc  and  const GUID* pguidReplicaDest 

     to following method. any help is appreciated.....

    HRESULT CFileSynchronizerDlg::Synchronize(

    const GUID* pguidReplicaSrc, BSTR bstrFolderSrc,  const GUID* pguidReplicaDest, BSTR bstrFolderDest,

    BSTR bstrMetaSrc,

    BSTR bstrMetaDest)

    Thursday, February 10, 2011 6:28 AM