DittoAddin.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "stdafx.h"
  2. #include "DittoAddin.h"
  3. #include "Misc.h"
  4. #include "shared/TextConvert.h"
  5. CDittoAddin::CDittoAddin() :
  6. m_hModule(NULL)
  7. {
  8. }
  9. CDittoAddin::~CDittoAddin()
  10. {
  11. Cleanup();
  12. }
  13. bool CDittoAddin::DoLoad(LPCTSTR lpszDllName, CDittoInfo DittoInfo)
  14. {
  15. bool bLoaded = false;
  16. m_csLastError.Empty();
  17. Cleanup();
  18. if(lpszDllName)
  19. {
  20. _tcscpy(m_DllName, lpszDllName);
  21. m_hModule = ::LoadLibrary(lpszDllName);
  22. if( m_hModule )
  23. {
  24. bool (__cdecl *DittoAddin)(const CDittoInfo&, CDittoAddinInfo&);
  25. DittoAddin = (bool(__cdecl*)(const CDittoInfo&, CDittoAddinInfo&))GetProcAddress(m_hModule, "DittoAddin");
  26. if(DittoAddin)
  27. {
  28. bLoaded = DittoAddin(DittoInfo, m_DittoAddinInfo);
  29. if(bLoaded)
  30. {
  31. m_SupportedFunctions = (bool(__cdecl*)(const CDittoInfo&, FunctionType,std::vector<CFunction>&))GetProcAddress(m_hModule, "SupportedFunctions");
  32. SupportedFunctions(DittoInfo, eFuncType_PRE_PASTE, m_PrePasteFunctions);
  33. }
  34. else
  35. {
  36. m_csLastError.Format((_T("Ditto Addin - DittoAddin return false, not loading Addin")));
  37. }
  38. }
  39. else
  40. {
  41. m_csLastError.Format((_T("Ditto Addin - Failed to Get Function DittoAddin")));
  42. }
  43. }
  44. else
  45. {
  46. m_csLastError.Format((_T("Ditto Addin - Failed to load library on Addin %s"), lpszDllName));
  47. }
  48. }
  49. return bLoaded;
  50. }
  51. void CDittoAddin::Cleanup()
  52. {
  53. if(m_hModule)
  54. {
  55. // release resources to the dll
  56. ::FreeLibrary(m_hModule);
  57. m_hModule = NULL;
  58. }
  59. }
  60. bool CDittoAddin::SupportedFunctions(const CDittoInfo &DittoInfo, FunctionType type, std::vector<CFunction> &Functions)
  61. {
  62. bool bRet = false;
  63. m_csLastError.Empty();
  64. if(m_SupportedFunctions != NULL)
  65. {
  66. bRet = m_SupportedFunctions(DittoInfo, type, Functions);
  67. if(bRet)
  68. {
  69. INT_PTR nCount = Functions.size();
  70. for(int i = 0; i < nCount; i++)
  71. {
  72. CFunction func = Functions[i];
  73. Log(StrF(_T("Ditto Addin - Supported Function Display: %s, Function: %s, Desc: %s"), func.m_csDisplayName, CTextConvert::MultiByteToUnicodeString(func.m_csFunction), func.m_csDetailDescription));
  74. }
  75. }
  76. else
  77. {
  78. m_csLastError = _T("Ditto Addin - m_SupportedFunctions returned false");
  79. }
  80. }
  81. else
  82. {
  83. m_csLastError = _T("Ditto Addin - m_SupportedFunctions is null, not call function load supported functions");
  84. }
  85. return bRet;
  86. }
  87. bool CDittoAddin::PrePasteFunction(const CDittoInfo &DittoInfo, CStringA Function, IClip *pClip)
  88. {
  89. bool (__cdecl *PrePasteFunc)(const CDittoInfo &, IClip*);
  90. PrePasteFunc = (bool(__cdecl*)(const CDittoInfo &, IClip*))GetProcAddress(m_hModule, Function);
  91. if(PrePasteFunc)
  92. {
  93. return PrePasteFunc(DittoInfo, pClip);
  94. }
  95. return false;
  96. }