DllManager.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:4k
源码类别:

输入法编程

开发平台:

Visual C++

  1. // mydebug.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include "windows.h"
  5. #include "stdio.h"
  6. #include "DllManager.h"
  7.  DllManager:: DllManager()
  8. {
  9. hWinyDLL=NULL;
  10. hkeyDLL=NULL;
  11. hmainWin=0;
  12. svhWndParent=0;
  13. SendCH[0]=0;
  14. Control[0]=0;
  15. loaderr=0;
  16. }
  17. DllManager:: ~DllManager()
  18. {
  19. if(NULL!=hWinyDLL)
  20. {
  21. if(hmainWin!=0)
  22. CloseWin(&hmainWin);
  23. hmainWin=0;
  24. if(hkeyDLL==hWinyDLL)
  25. FreeLibrary(hWinyDLL);
  26. else
  27. {
  28. FreeLibrary(hkeyDLL);//卸载TranChiDll.dll文件;
  29. FreeLibrary(hWinyDLL);
  30. }
  31. hWinyDLL=NULL;
  32. hkeyDLL=NULL;
  33. //MessageBox (0,"FreeLibrary",0,0);
  34. }
  35. }
  36.  DllManager::mgDllEnd()
  37. {
  38.   if(NULL!=hWinyDLL)
  39. {
  40. if(hmainWin!=0)
  41. CloseWin(&hmainWin);
  42. hmainWin=0;
  43. //MessageBox (0,"FreeLibrary",0,0);
  44. }
  45. }
  46.  
  47. int DllManager::mgDllStart()
  48. {
  49. int ret=0;
  50. WIN32_FIND_DATAA tt;
  51. char ss[260];
  52. HANDLE fd1,fd2;
  53. ss[0]=0;
  54.    // MessageBox (0,"Load TranChiDll.dll",0,0);
  55. SoftkbdParentWnd=NULL;
  56. fd1=FindFirstFile("c:\jsime\TranChiDll.dll",&tt);
  57. fd2=FindFirstFile("c:\jsime\jsIMEWin.dll",&tt);
  58. if(loaderr==1)
  59. return ret;
  60.     if(fd1==INVALID_HANDLE_VALUE)
  61. {
  62.    //MessageBox(0,"文件TranChiDll.dll未找到!n 请立即保存,系统可能崩溃!?","IME c:\jsime\",0);
  63.    loaderr=1;
  64.    ret=1;
  65. }
  66. else
  67. {
  68. ///////////////////////////////////////////////////////////
  69. if(fd2!=INVALID_HANDLE_VALUE)
  70. {
  71. hWinyDLL=LoadLibrary("c:\jsime\jsIMEWin.dll"); 
  72. hkeyDLL=hWinyDLL;//通过jsIMEWin调用转换模块
  73. myCreate=(pmyCreate)GetProcAddress(hWinyDLL,"myCreate"); 
  74. CloseWin=(pCloseWin)GetProcAddress(hWinyDLL,"CloseWin"); 
  75. SetWinPosition=(pSetWinPosition)GetProcAddress(hWinyDLL,"SetWinPosition"); 
  76. SetShowString=(pSetShowString)GetProcAddress(hWinyDLL,"SetShowString"); 
  77. UpdateWinShow=(pUpdateWinShow)GetProcAddress(hWinyDLL,"UpdateWinShow"); 
  78. HideWin=(pHideWin)GetProcAddress(hWinyDLL,"HideWin"); 
  79. HideAllWin=(pHideAllWin)GetProcAddress(hWinyDLL,"HideAllWin"); 
  80. //MessageBox (0,"Load jsIMEWin.dll End .",0,0);
  81. }
  82. if(hkeyDLL==NULL)         //如果jsIMEWin没有加载则直接加载转换模块
  83. {
  84. hkeyDLL=LoadLibrary("c:\jsime\TranChiDll.dll");//加载动态链接库.dll文件; 
  85. //MessageBox (0,"窗口模块jsIMEWin没有加载成功","输入将没有提示窗口",0);
  86. }
  87. m_myImeProcessKey=(pmyImeProcessKey)GetProcAddress(hkeyDLL,"myImeProcessKey"); 
  88. if(myImeProcessKey==NULL)
  89. MessageBox (0,"入将没有提示窗口",0,0);
  90. }
  91.     //MessageBox (0,"Load TranChiDll.dll",0,0);
  92. return ret;
  93. }
  94. BOOL DllManager::myImeProcessKey(long *fcmywnd,char *SendCH,char *Control,HIMC hIMC,UINT vKey,LPARAM lKeyData,CONST LPBYTE lpbKeyState)
  95. {
  96. BOOL ret=0;
  97. if(NULL==hkeyDLL){
  98. loaderr=0;
  99. mgDllStart();
  100. if(NULL==hkeyDLL)
  101. MessageBox (0,"Load TranChiDll.dll 装载失败",0,0);
  102. }else
  103. ret=m_myImeProcessKey(fcmywnd,SendCH,Control,hIMC,vKey,lKeyData,lpbKeyState);//
  104. return ret;
  105. long DllManager:: CreateWin(char* szClassName, char* szTitle,HWND hWndParent,DWORD himc)
  106. {
  107. if(NULL==hWinyDLL)
  108. return 0;
  109. hmainWin=myCreate(szClassName,szTitle,hWndParent,himc);//
  110. svhWndParent=hWndParent;
  111. return hmainWin;
  112. long DllManager:: mgCreateWin(char* szClassName, char* szTitle,DWORD himc)
  113. {
  114. if(NULL==hWinyDLL)
  115. return 0;
  116. if(svhWndParent==0)
  117. return 0;
  118. if(hmainWin!=0)
  119. {
  120. CloseWin(&hmainWin);
  121. hmainWin=0;
  122. }
  123. hmainWin=myCreate(szClassName,szTitle,svhWndParent,himc);//
  124. return hmainWin;
  125. long DllManager:: mgUpDateaWin(DWORD himc)
  126. {
  127. if(NULL==hWinyDLL)
  128. return 0;
  129. if(hmainWin!=0)
  130. {
  131. UpdateWinShow(&hmainWin,himc);
  132. }
  133. return 0;
  134. long DllManager:: mgHideAllWin()
  135. {
  136. if(NULL==hWinyDLL)
  137. return 0;
  138. if(hmainWin!=0)
  139. {
  140. HideAllWin(&hmainWin);
  141. }
  142. return 0;
  143. long DllManager:: mgHideWin()
  144. {
  145. if(NULL==hWinyDLL)
  146. return 0;
  147. if(hmainWin!=0)
  148. {
  149. HideWin(&hmainWin);
  150. }
  151. return 0;
  152. long DllManager:: mgCloseWin()
  153. {
  154. if(NULL==hWinyDLL)
  155. return 0;
  156. if(hmainWin!=0)
  157. {
  158. CloseWin(&hmainWin);
  159. hmainWin=0;
  160. }
  161. return 0;
  162. int DllManager::mgSetShowString(char*MindleStr,char*InputStr)
  163. {
  164. if(NULL==hWinyDLL)
  165. return 0;
  166. if(hmainWin!=0)
  167. {
  168. SetShowString(&hmainWin,MindleStr,InputStr);
  169. }
  170. return 0;
  171. }
  172. int DllManager::mgSetWinPosition(HWND hWnd ,POINT SetPos)
  173. {
  174. long x,y;
  175. if(NULL==hWinyDLL)
  176. return 0;
  177. if(hmainWin!=0)
  178. {
  179. x=SetPos.x;
  180. y=SetPos.y;
  181. SetWinPosition(&hmainWin,hWnd ,&x,&y);
  182. }
  183. return 0;
  184. }