123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- // lyfzEasyPrinter.cpp : 定义 DLL 的初始化例程。
- //
- #include "stdafx.h"
- #include "lyfzEasyPrinter.h"
- #include "EasyPrinter.h"
- #include "EasyPrinterV1.h"
- #include "EasyPrinterV2.h"
- #include <Shlwapi.h>
- // 全局变量;
- CEasyPrinterV2 *g_EasyPrinter = NULL;
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- //
- //TODO: 如果此 DLL 相对于 MFC DLL 是动态链接的,
- // 则从此 DLL 导出的任何调入
- // MFC 的函数必须将 AFX_MANAGE_STATE 宏添加到
- // 该函数的最前面。
- //
- // 例如:
- //
- // extern "C" BOOL PASCAL EXPORT ExportedFunction()
- // {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // // 此处为普通函数体
- // }
- //
- // 此宏先于任何 MFC 调用
- // 出现在每个函数中十分重要。这意味着
- // 它必须作为函数中的第一个语句
- // 出现,甚至先于所有对象变量声明,
- // 这是因为它们的构造函数可能生成 MFC
- // DLL 调用。
- //
- // 有关其他详细信息,
- // 请参阅 MFC 技术说明 33 和 58。
- //
- // ClyfzEasyPrinterApp
- BEGIN_MESSAGE_MAP(ClyfzEasyPrinterApp, CWinApp)
- END_MESSAGE_MAP()
- // ClyfzEasyPrinterApp 构造
- ClyfzEasyPrinterApp::ClyfzEasyPrinterApp()
- {
- // TODO: 在此处添加构造代码,
- // 将所有重要的初始化放置在 InitInstance 中
- }
- // 唯一的一个 ClyfzEasyPrinterApp 对象
- ClyfzEasyPrinterApp theApp;
- // ClyfzEasyPrinterApp 初始化
- BOOL ClyfzEasyPrinterApp::InitInstance()
- {
- CWinApp::InitInstance();
- return TRUE;
- }
- extern "C" BOOL PASCAL EXPORT LoadTemplateFromJson(IN LPCTSTR lpJsonTemplate)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // 此处为普通函数体;
- if ( lpJsonTemplate == NULL || lpJsonTemplate[0] == '\0')
- return FALSE;
- if (g_EasyPrinter == NULL)
- g_EasyPrinter = new CEasyPrinterV2();
- if (!g_EasyPrinter->LoadTemplateFromJson(lpJsonTemplate))
- {
- delete g_EasyPrinter;
- g_EasyPrinter = NULL;
- return FALSE;
- }
- return TRUE;
- }
- extern "C" BOOL PASCAL EXPORT LoadTemplateFromFile(IN LPCTSTR lpTemplateFile)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // 此处为普通函数体;
- if (lpTemplateFile == NULL || !PathFileExists(lpTemplateFile))
- return FALSE;
- if ( g_EasyPrinter == NULL )
- g_EasyPrinter = new CEasyPrinterV2();
- if (!g_EasyPrinter->LoadTemplateFromFile(lpTemplateFile))
- {
- delete g_EasyPrinter;
- g_EasyPrinter = NULL;
- return FALSE;
- }
- return TRUE;
- }
- extern "C" BOOL PASCAL EXPORT LoadValuesFromJson(IN LPCTSTR lpKeyValueJson)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // 此处为普通函数体;
- if (g_EasyPrinter == NULL || lpKeyValueJson == NULL || lpKeyValueJson[0] == '\0')
- return FALSE;
- return g_EasyPrinter->LoadValuesFromJson(lpKeyValueJson);
- }
- extern "C" BOOL PASCAL EXPORT LoadValuesFromFile(IN LPCTSTR lpValuesFile)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // 此处为普通函数体;
- if (g_EasyPrinter == NULL || lpValuesFile == NULL || !PathFileExists(lpValuesFile))
- return FALSE;
- return g_EasyPrinter->LoadValuesFromFile(lpValuesFile);
- }
- extern "C" BOOL PASCAL EXPORT SetPrinter(IN LPCTSTR lpPrinterName)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // 此处为普通函数体
- if (g_EasyPrinter == NULL || lpPrinterName == NULL)
- return FALSE;
- g_EasyPrinter->SetPrinter(lpPrinterName);
- return TRUE;
- }
- extern "C" BOOL PASCAL EXPORT StartPrint( )
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // 此处为普通函数体
- if (g_EasyPrinter == NULL )
- return FALSE;
- g_EasyPrinter->PrintByJson();
- if (g_EasyPrinter)
- delete g_EasyPrinter;
- g_EasyPrinter = NULL;
- return TRUE;
- }
|