lyfzEasyPrinter.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // lyfzEasyPrinter.cpp : 定义 DLL 的初始化例程。
  2. //
  3. #include "stdafx.h"
  4. #include "lyfzEasyPrinter.h"
  5. #include "EasyPrinter.h"
  6. #include "EasyPrinterV1.h"
  7. #include "EasyPrinterV2.h"
  8. #include <Shlwapi.h>
  9. // 全局变量;
  10. CEasyPrinterV2 *g_EasyPrinter = NULL;
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #endif
  14. //
  15. //TODO: 如果此 DLL 相对于 MFC DLL 是动态链接的,
  16. // 则从此 DLL 导出的任何调入
  17. // MFC 的函数必须将 AFX_MANAGE_STATE 宏添加到
  18. // 该函数的最前面。
  19. //
  20. // 例如:
  21. //
  22. // extern "C" BOOL PASCAL EXPORT ExportedFunction()
  23. // {
  24. // AFX_MANAGE_STATE(AfxGetStaticModuleState());
  25. // // 此处为普通函数体
  26. // }
  27. //
  28. // 此宏先于任何 MFC 调用
  29. // 出现在每个函数中十分重要。这意味着
  30. // 它必须作为函数中的第一个语句
  31. // 出现,甚至先于所有对象变量声明,
  32. // 这是因为它们的构造函数可能生成 MFC
  33. // DLL 调用。
  34. //
  35. // 有关其他详细信息,
  36. // 请参阅 MFC 技术说明 33 和 58。
  37. //
  38. // ClyfzEasyPrinterApp
  39. BEGIN_MESSAGE_MAP(ClyfzEasyPrinterApp, CWinApp)
  40. END_MESSAGE_MAP()
  41. // ClyfzEasyPrinterApp 构造
  42. ClyfzEasyPrinterApp::ClyfzEasyPrinterApp()
  43. {
  44. // TODO: 在此处添加构造代码,
  45. // 将所有重要的初始化放置在 InitInstance 中
  46. }
  47. // 唯一的一个 ClyfzEasyPrinterApp 对象
  48. ClyfzEasyPrinterApp theApp;
  49. // ClyfzEasyPrinterApp 初始化
  50. BOOL ClyfzEasyPrinterApp::InitInstance()
  51. {
  52. CWinApp::InitInstance();
  53. return TRUE;
  54. }
  55. extern "C" BOOL PASCAL EXPORT LoadTemplateFromJson(IN LPCTSTR lpJsonTemplate)
  56. {
  57. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  58. // 此处为普通函数体;
  59. if ( lpJsonTemplate == NULL || lpJsonTemplate[0] == '\0')
  60. return FALSE;
  61. if (g_EasyPrinter == NULL)
  62. g_EasyPrinter = new CEasyPrinterV2();
  63. if (!g_EasyPrinter->LoadTemplateFromJson(lpJsonTemplate))
  64. {
  65. delete g_EasyPrinter;
  66. g_EasyPrinter = NULL;
  67. return FALSE;
  68. }
  69. return TRUE;
  70. }
  71. extern "C" BOOL PASCAL EXPORT LoadTemplateFromFile(IN LPCTSTR lpTemplateFile)
  72. {
  73. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  74. // 此处为普通函数体;
  75. if (lpTemplateFile == NULL || !PathFileExists(lpTemplateFile))
  76. return FALSE;
  77. if ( g_EasyPrinter == NULL )
  78. g_EasyPrinter = new CEasyPrinterV2();
  79. if (!g_EasyPrinter->LoadTemplateFromFile(lpTemplateFile))
  80. {
  81. delete g_EasyPrinter;
  82. g_EasyPrinter = NULL;
  83. return FALSE;
  84. }
  85. return TRUE;
  86. }
  87. extern "C" BOOL PASCAL EXPORT LoadValuesFromJson(IN LPCTSTR lpKeyValueJson)
  88. {
  89. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  90. // 此处为普通函数体;
  91. if (g_EasyPrinter == NULL || lpKeyValueJson == NULL || lpKeyValueJson[0] == '\0')
  92. return FALSE;
  93. return g_EasyPrinter->LoadValuesFromJson(lpKeyValueJson);
  94. }
  95. extern "C" BOOL PASCAL EXPORT LoadValuesFromFile(IN LPCTSTR lpValuesFile)
  96. {
  97. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  98. // 此处为普通函数体;
  99. if (g_EasyPrinter == NULL || lpValuesFile == NULL || !PathFileExists(lpValuesFile))
  100. return FALSE;
  101. return g_EasyPrinter->LoadValuesFromFile(lpValuesFile);
  102. }
  103. extern "C" BOOL PASCAL EXPORT SetPrinter(IN LPCTSTR lpPrinterName)
  104. {
  105. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  106. // 此处为普通函数体
  107. if (g_EasyPrinter == NULL || lpPrinterName == NULL)
  108. return FALSE;
  109. g_EasyPrinter->SetPrinter(lpPrinterName);
  110. return TRUE;
  111. }
  112. extern "C" BOOL PASCAL EXPORT StartPrint( )
  113. {
  114. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  115. // 此处为普通函数体
  116. if (g_EasyPrinter == NULL )
  117. return FALSE;
  118. g_EasyPrinter->PrintByJson();
  119. if (g_EasyPrinter)
  120. delete g_EasyPrinter;
  121. g_EasyPrinter = NULL;
  122. return TRUE;
  123. }