home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2001 January / VPR0101A.BIN / OLS / TAR32053 / tar32053.exe / SRC / NKF.C < prev    next >
C/C++ Source or Header  |  1999-05-23  |  2KB  |  73 lines

  1. #ifndef __DEFCONF_H
  2. #include "defconf.h"
  3. #endif
  4. /* nkf.c */
  5. #ifdef USE_NKF_DLL
  6.  
  7. #include "nkf.h"
  8. #include <windows.h>
  9.  
  10. static char *NKF_DLL_NAME="NKF32.DLL";
  11.  
  12. static EXIST_NKF=0;    /* NKFが存在するか?*/
  13. static FIRST_NKF=1;    /* 関数が呼ばれたのが一番最初か?*/
  14.  
  15. static char nkf_option[100];
  16. /* WINAPI=FAR PASCAL */
  17. static void (WINAPI *OrigGetNkfVersion)(LPSTR verStr);
  18. static int (WINAPI *OrigSetNkfOption)(LPCSTR optStr);
  19. static void (WINAPI *OrigNkfConvert)(LPSTR outStr,LPCSTR inStr);
  20.  
  21. void GetNkfVersion(char * verStr)
  22. {
  23.     if(FIRST_NKF){init_nkf();}
  24.     if(EXIST_NKF==0){
  25.         strcpy(verStr,"");
  26.     }else{
  27.         OrigGetNkfVersion(verStr);
  28.     }
  29. }
  30. int SetNkfOption(const char * optStr)
  31. {
  32.     if(FIRST_NKF){init_nkf();}
  33.     if(EXIST_NKF==0){
  34.         return -1;
  35.     }else{
  36.         strcpy(nkf_option,optStr);
  37.         OrigSetNkfOption(optStr);
  38.     }
  39. }    
  40. void NkfConvert(char * outStr,const char * inStr)
  41. {
  42.     if(FIRST_NKF){init_nkf();}
  43.     /* オプションがない時は変換しない。*/
  44.     if(EXIST_NKF==0 || strcmp(nkf_option,"")==0){
  45.         strcpy(outStr,inStr);
  46.     }else{
  47.         OrigNkfConvert(outStr,inStr);
  48.     }
  49. }    
  50.  
  51. int init_nkf(void)
  52. {
  53.     HINSTANCE hLib;
  54.     
  55.     if(EXIST_NKF==1){return 0;}
  56.     FIRST_NKF=0;
  57.     hLib=LoadLibrary(NKF_DLL_NAME);
  58.     if(hLib<(HINSTANCE)HINSTANCE_ERROR){
  59.         return -1;
  60.     }
  61.  
  62.     OrigGetNkfVersion=(void (WINAPI *)(LPSTR verStr))GetProcAddress(hLib,"GetNkfVersion");
  63.     OrigSetNkfOption=(int (WINAPI *)(LPCSTR optStr))GetProcAddress(hLib,"SetNkfOption");
  64.     OrigNkfConvert=(void (WINAPI *)(LPSTR outStr,LPCSTR inStr))GetProcAddress(hLib,"NkfConvert");
  65.     if(OrigGetNkfVersion==NULL || OrigSetNkfOption==NULL || OrigNkfConvert==NULL){
  66.         return -1;
  67.     }
  68.     EXIST_NKF=1;
  69.     return 0;
  70. }
  71.  
  72.  
  73. #endif /*USE_NKF_DLL*/