hello,
I still have a problem when I'm create a conduit based on MFC classes. When
I install nothing passed and cannot find the error, somebody can help me..
thx..
here the code of my conduit
*********************************
#define STRICT 1
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC core and standard components
#include <afxcmn.h> // for CImageList in fieldlis.h
#include <string.h>
#include <wtypes.h>
#include "syncmgr.h"
#include "hslog.h"
#include "condapi.h"
#include "UpLoadCommande.h"
#include "PALM_CMN.H"
#include "basemon.h"
#include "condmgre.h"
#include "pdcmnDll.h"
#include "cmnres.h"
#include "actdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static int ClientCount = 0;
static HINSTANCE hRscInstance = 0;
static HINSTANCE hDLLInstance = 0;
HINSTANCE myInst=0;
////////////////////////////////////////////////////////////////////////////
/
// CUpLoadCommandeApp
//
class CUpLoadCommandeApp : public CWinApp
{
public:
virtual BOOL InitInstance(); // Initialization
virtual int ExitInstance(); // Termination
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CUpLoadCommandeApp)
//}}AFX_VIRTUAL
//{{AFX_MSG(CUpLoadCommandeApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
////////////////////////////////////////////////////////////////////////////
/
// CUpLoadCommandeApp
BEGIN_MESSAGE_MAP(CUpLoadCommandeApp, CWinApp)
//{{AFX_MSG_MAP(CUpLoadCommandeApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////////
/
//
// Function: InitInstance()
//
// Description: basic initialisation when DLL is loaded
//
// Parameters: none
//
// Returns: Success (non-zero) or Failure (zero)
//
////////////////////////////////////////////////////////////////////////////
/
BOOL CUpLoadCommandeApp::InitInstance()
{
// DLL initialization
TRACE0("UPLOADCOMMANDE.DLL initializing\n");
if (!ClientCount ) {
DWORD dwVersion;
hDLLInstance = AfxGetInstanceHandle();
hRscInstance = PalmLoadLanguage("UPLOADCOMMANDELANG.DLL",
hDLLInstance,
&dwVersion);
// add any extension DLLs into CDynLinkLibrary chain
InitPdcmn5DLL();
}
myInst = hRscInstance;
ClientCount++;
return TRUE;
}
////////////////////////////////////////////////////////////////////////////
/
//
// Function: ExitInstance()
//
// Description: DLL clean up before exit
//
// Parameters: none
//
// Returns: Error code
//
////////////////////////////////////////////////////////////////////////////
/
int CUpLoadCommandeApp::ExitInstance()
{
TRACE0("UPLOADCOMMANDE.DLL Terminating!\n");
// Check for last client and clean up potential memory leak.
if (--ClientCount <= 0)
{
PalmFreeLanguage(hRscInstance, hDLLInstance);
hRscInstance = hDLLInstance;
}
// DLL clean up, if required
return CWinApp::ExitInstance();
}
////////////////////////////////////////////////////////////////////////////
/
// The one and only CUpLoadCommandeApp object
CUpLoadCommandeApp conduitDll;
////////////////////////////////////////////////////////////////////////////
/
/*
*
* D�claration des variables globales
*
*
*/
long OpenRemoteDatabase(byte& hRemoteDatabase, CSyncProperties& rProps) ;
long CloseRemoteDatabase(byte hRemoteDatabase) ;
long OpenLocalDatabase(CStdioFile& file, UINT openFlags, CString fileName) ;
long CoseLocalDatabase(CStdioFile& file) ;
long ConvertHHtoPC(CRawRecordInfo& rawRecord, CString& buffer) ;
long CopyHHtoPC(CSyncProperties& rProps, byte hRemoteDatabase, CStdioFile&
localFile) ;
long FreeRowRecordMemory(CRawRecordInfo& rawRecord) ;
long AllocRowRecordMemory(CRawRecordInfo& rawRecord, WORD taille)
{
long retval = 0 ;
//Allocation de la m�moire pour les enregistrements de la structure
rawRecord.m_TotalBytes = 0 ;
rawRecord.m_pBytes = (BYTE*) new char [taille] ;
//Test de l'existence de l'enregistrement
if(rawRecord.m_pBytes)
{
rawRecord.m_TotalBytes = taille ;
memset(rawRecord.m_pBytes, 0, taille) ;
}
return (retval) ;
}
long FreeRowRecordMemory(CRawRecordInfo& rawRecord)
{
long retval = 0 ;
//Test de l'existence de l'enregistrement et suppression si existe
if(rawRecord.m_TotalBytes>0 && rawRecord.m_pBytes)
delete rawRecord.m_pBytes ;
return (retval) ;
}
long OpenRemoteDatabase(byte& hRemoteDatabase, CSyncProperties& rProps)
{
//Ouverture de la BDD qui a �t� choisi dans les propri�t�s de
synchronisation
return (SyncOpenDB(rProps.m_RemoteName[0], 0, hRemoteDatabase)) ;
}
long CloseRemoteDatabase(byte hRemoteDatabase)
{
//Ouverture de la BDD qui a �t� choisi dans les propri�t�s de
synchronisation
return (SyncCloseDB(hRemoteDatabase)) ;
}
long OpenLocalDatabase(CStdioFile& file, UINT openFlags, CString fileName)
{
long retval = 0 ;
retval = !(file.Open (LPCTSTR(fileName), openFlags)) ;
return (retval) ;
}
long CloseLocalDatabase(CStdioFile& file)
{
long retval = 0 ;
file.Close() ;
return (retval) ;
}
long ConvertHHtoPC(CRawRecordInfo& rawRecord, CString& buffer)
{
long retval = 0 ;
buffer = (char*) rawRecord.m_pBytes ;
return (retval) ;
}
long CopyHHtoPC(CSyncProperties& rProps, byte hRemoteDatabase, CStdioFile&
localFile)
{
long retval = 0 ;
CRawRecordInfo rawRecord ;
CString buffer ;
//allocation de l'enregistrement
memset(&rawRecord, 0, sizeof(CRawRecordInfo)) ;
rawRecord.m_FileHandle = hRemoteDatabase ;
rawRecord.m_RecIndex = 0 ;
AllocRowRecordMemory(rawRecord, LONGUEUR) ;
//lire l'enregistrement de la BDD
while(!(retval = SyncReadRecordByIndex(rawRecord)))
{
//convertir l'enregistrement et l'�crire dans le fichier texte
ConvertHHtoPC(rawRecord, buffer) ;
//ajouter des lignes blanches entre les enregistrements
if(rawRecord.m_RecIndex != 0)
{
localFile.Write(STR_LF, strlen(STR_LF)) ;
localFile.Write(STR_LF, strlen(STR_LF)) ;
}
//ecrire l'enregistrement
localFile.Write(LPCTSTR(buffer), buffer.GetLength()) ;
//incr�mentation de l'index
rawRecord.m_RecIndex++ ;
}
//test si la variable est en dehors des enregistrements
if(retval == SYNCERR_FILE_NOT_FOUND)
retval = 0 ;
//lib�rer la m�moire
FreeRowRecordMemory(rawRecord) ;
return (retval) ;
}
////////////////////////////////////////////////////////////////////////////
/
//
// Function: OpenConduit()
//
// Description: Extern "C" entry point into this conduit which starts
the
// process of synchronizing the local database table with
// a remote conterpart residing on the remote view device.
//
// Parameters: Pointer to a callback function used to report
progress.
//
//
//
// Returns:
//
////////////////////////////////////////////////////////////////////////////
/
ExportFunc long OpenConduit(PROGRESSFN pFn, CSyncProperties& rProps)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()) ;
long retval = -1 ;
byte hRemoteDatabase = 0 ;
CStdioFile localFile ;
CString localFileName ;
if (pFn)
{
CONDHANDLE conduitHandle = (CONDHANDLE)0;
Activity syncFinishCode = slSyncFinished;
// Register this conduit with SyncMgrDLL for communication to HH
if (retval = SyncRegisterConduit(conduitHandle))
return(retval);
//ouverture de la base de donn�es
OpenRemoteDatabase(hRemoteDatabase, rProps) ;
//r�cup�rer le nom du fichier text et son chemin
if(strlen(rProps.m_LocalName) != 0)
{
//r�cup�re se qui � �t� configur� en local
localFileName = rProps.m_PathName ;
localFileName += rProps.m_LocalName ;
}
else
{
//sinon on les d�finit avec mes variables globales
localFileName = rProps.m_PathName ;
localFileName += STR_TEXT_FILE_NAME ;
localFileName += STR_TEXT_FILE_EXT ;
}
//r�cup�ration de la direction ici je r�cup�re que la m�thode d'upload
rProps.m_SyncType = eHHtoPC ; //attention
//traiter les diff�rent type de lors de la synchronisation
switch(rProps.m_SyncType)
{
case ePCtoHH :
case eHHtoPC :
case eFast :
case eSlow :
retval = OpenLocalDatabase(localFile, CStdioFile::modeCreate |
CStdioFile::modeWrite, localFileName) ;
//on copie la BDD que si le fichier text existe
if(!retval && localFile.m_hFile != CStdioFile::hFileNull)
retval = CopyHHtoPC(rProps, hRemoteDatabase, localFile) ;
break ;
default :
break ;
}
//fermer la BDD sur le PALM
if(hRemoteDatabase)
CloseRemoteDatabase(hRemoteDatabase) ;
//fermer le fichier txt
if(localFile.m_hFile != CStdioFile::hFileNull)
CloseLocalDatabase(localFile) ;
// Notify the log that a sync is about to begin
LogAddEntry("", slSyncStarted,FALSE);
/**************************************/
/* TODO - Add synchronization logic */
/**************************************/
// log success/failure
if(!retval)
LogAddEntry("UpLoadCommande", syncFinishCode,FALSE);
else
LogAddEntry("UpLoadCommande", slSyncAborted, FALSE);
SyncUnRegisterConduit(conduitHandle) ;
}
return(retval) ;
}
////////////////////////////////////////////////////////////////////////////
/
//
// Function: GetConduitName()
//
// Description: Extern "C" entry point into this conduit which
returns
// the name to be used when display messages
regarding
// this conduit.
//
// Parameters: pszName - buffer in which to place the name
// nLen - maximum number of bytes of buffer
//
//
//
// Returns: -1 indicates erros
//
////////////////////////////////////////////////////////////////////////////
/
ExportFunc long GetConduitName(char* pszName,WORD nLen)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
char szConduitName[] = "UpLoadCommande";
memset(pszName, 0, nLen);
strncpy(pszName, szConduitName, nLen-1);
return 0;
}
////////////////////////////////////////////////////////////////////////////
/
//
// Function: GetConduitVersion()
//
// Description: Extern "C" entry point into this conduit which
returns
// the conduits version
//
// Parameters: none
//
// Returns: DWORD indicating major and minor version number
// HIWORD - reserved
// HIBYTE(LOWORD) - major number
// LOBYTE(LOWORD) - minor number
//
////////////////////////////////////////////////////////////////////////////
/
ExportFunc DWORD GetConduitVersion()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return UPLOADCOMMANDE_VERSION;
}
////////////////////////////////////////////////////////////////////////////
/
//
// Function: ConfigureConduit
//
// Description: Extern "C" entry point into this conduit which
returns
// should display the UI necessary to configure this
// conduit.
//
// Parameters: none
//
// Returns: 0 - success, !0 - failure
//
////////////////////////////////////////////////////////////////////////////
/
ExportFunc long ConfigureConduit(CSyncPreference& pref)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
long nRtn = -1;
char szName[81];
CHotSyncActionDlg actDlg(CWnd::GetActiveWindow());
pref.m_SyncPref = eNoPreference;
GetConduitName(szName,80);
actDlg.m_csGroupText = szName;
switch (pref.m_SyncType)
{
case eFast:
case eSlow:
actDlg.m_nActionIndex = 0;
break;
case ePCtoHH:
actDlg.m_nActionIndex = 1;
break;
case eHHtoPC:
actDlg.m_nActionIndex = 2;
break;
case eDoNothing:
default:
actDlg.m_nActionIndex = 3;
}
if (actDlg.DoModal() == IDOK)
{
switch (actDlg.m_nActionIndex)
{
case 0:
pref.m_SyncType = eFast;
break;
case 1:
pref.m_SyncType = ePCtoHH;
break;
case 2:
pref.m_SyncType = eHHtoPC;
break;
case 3:
default:
pref.m_SyncType = eDoNothing;
break;
}
pref.m_SyncPref = (actDlg.m_bMakeDefault) ? ePermanentPreference :
eTemporaryPreference;
nRtn = 0;
}
return nRtn;
}
////////////////////////////////////////////////////////////////////////////
/
//
// Method: GetConduitInfo
//
// Description: This function provides a way for a Conduit to provide info
// to the caller.
// In this version of the call, MFC Version, Conduit Name,
and
// Default sync action are the types of information this
call
// will return.
//
// Parameters: ConduitInfoEnum infoType - enum specifying what info is
being
// requested.
// void *pInArgs - This parameter may be null, except for
the Conduit
// name enum, this value will be a
ConduitRequestInfoType structure.
// This following to parameters vary depending upon the
info being requested.
// For enum eConduitName
// void *pOut - will be a pointer to a character buffer
// DWORD *pdwOutSize - will be a pointer to a DWORD
specifying the size of the character buffer.
//
// For enum eMfcVersion
// void *pOut - will be a pointer to a DWORD
// DWORD *pdwOutSize - will be a pointer to a DWORD
specifying the size of pOut.
//
// For enum eDefaultAction
// void *pOut - will be a pointer to a eSyncType variable
// DWORD *pdwOutSize - will be a pointer to a DWORD
specifying the size of pOut.
//
// Returns: 0 - Success.
// !0 - error code.
//
////////////////////////////////////////////////////////////////////////////
/
ExportFunc long GetConduitInfo(ConduitInfoEnum infoType, void *pInArgs, void
*pOut, DWORD *pdwOutSize)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if (!pOut)
return CONDERR_INVALID_PTR;
if (!pdwOutSize)
return CONDERR_INVALID_OUTSIZE_PTR;
switch (infoType) {
case eConduitName:
{
if (!pInArgs)
return CONDERR_INVALID_INARGS_PTR;
ConduitRequestInfoType *pInfo;
pInfo = (ConduitRequestInfoType *)pInArgs;
if ((pInfo->dwVersion != CONDUITREQUESTINFO_VERSION_1) ||
(pInfo->dwSize != SZ_CONDUITREQUESTINFO))
return CONDERR_INVALID_INARGS_STRUCT;
// Conduit name
TCHAR szConduitName[] = "UpLoadCommande";
memset((TCHAR*)pOut, 0, *pdwOutSize);
strncpy((TCHAR*)pOut, STR_TEXT_CONDUIT, (*pdwOutSize)-1); //affectation
du nom au conduit
}
break;
case eDefaultAction:
if (*pdwOutSize != sizeof(eSyncTypes))
return CONDERR_INVALID_BUFFER_SIZE;
(*(eSyncTypes*)pOut) = eFast;
break;
case eMfcVersion:
if (*pdwOutSize != sizeof(DWORD))
return CONDERR_INVALID_BUFFER_SIZE;
(*(DWORD*)pOut) = MFC_VERSION_60;
break;
default:
return CONDERR_UNSUPPORTED_CONDUITINFO_ENUM;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////
/
//
// Method: CfgConduit
//
// Description: This is the second instance of ConfigureConduit. This
function
// is provided with more info from the caller.
// This version of the function only supports the eConfig1
enum.
//
// Parameters: ConduitCfgEnum cfgType - enum specifying the version of the
// CfgConduit Call.
// void *pArgs - In the eConfig1 call, this is a pointer to
aCfgConduitInfoType
// structure. This structure provides extra info to the
conduit.
// DWORD *pdwArgsSize - This is a pointer to a DWORD
specifying the size of pArgs.
//
// Returns: 0 - Success.
// !0 - error code.
//
////////////////////////////////////////////////////////////////////////////
/
ExportFunc long CfgConduit( ConduitCfgEnum cfgType, void *pArgs, DWORD
*pdwArgsSize)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
long nRtn = -1;
ConduitRequestInfoType infoStruct;
CfgConduitInfoType *pCfgInfo;
if (!pArgs)
return CONDERR_INVALID_INARGS_PTR;
if (!pdwArgsSize)
return CONDERR_INVALID_ARGSSIZE_PTR;
if (*pdwArgsSize != SZ_CFGCONDUITINFO)
return CONDERR_INVALID_ARGSSIZE;
if (cfgType != eConfig1)
return CONDERR_UNSUPPORTED_CFGCONDUIT_ENUM;
pCfgInfo = (CfgConduitInfoType *)pArgs;
if (pCfgInfo->dwVersion != CFGCONDUITINFO_VERSION_1)
return CONDERR_UNSUPPORTED_STRUCT_VERSION;
infoStruct.dwVersion = CONDUITREQUESTINFO_VERSION_1;
infoStruct.dwSize = SZ_CONDUITREQUESTINFO;
infoStruct.dwCreatorId = pCfgInfo->dwCreatorId;
infoStruct.dwUserId = pCfgInfo->dwUserId;
strcpy(infoStruct.szUser, pCfgInfo->szUser);
TCHAR szName[256];
DWORD dwNamesize;
dwNamesize = sizeof(szName);
CHotSyncActionDlg actDlg(CWnd::GetActiveWindow());
nRtn = GetConduitInfo(eConduitName, (void *)&infoStruct, (void *)szName,
&dwNamesize);
if (nRtn)
return nRtn;
actDlg.m_csGroupText = szName;
switch (pCfgInfo->syncTemporary){
case eFast:
case eSlow:
actDlg.m_nActionIndex = 0;
break;
case ePCtoHH:
actDlg.m_nActionIndex = 1;
break;
case eHHtoPC:
actDlg.m_nActionIndex = 2;
break;
case eDoNothing:
default:
actDlg.m_nActionIndex = 3;
break;
}
nRtn = -1;
if (actDlg.DoModal() == IDOK){
switch (actDlg.m_nActionIndex) {
case 0:
pCfgInfo->syncNew = eFast;
break;
case 1:
pCfgInfo->syncNew = ePCtoHH;
break;
case 2:
pCfgInfo->syncNew = eHHtoPC;
break;
case 3:
default:
pCfgInfo->syncNew = eDoNothing;
break;
}
pCfgInfo->syncPref = (actDlg.m_bMakeDefault) ? ePermanentPreference
: eTemporaryPreference;
nRtn = 0;
}
return nRtn;
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/