Subversion Repositories filter_foundry

Rev

Rev 496 | Rev 522 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.     This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
  3.     Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au
  4.     Copyright (C) 2018-2022 Daniel Marschall, ViaThinkSoft
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19. */
  20.  
  21. #include "ff.h"
  22.  
  23. void strcpy_advance_id(TCHAR** str, int msgid) {
  24.     //TCHAR tmp[1000];
  25.     int len;
  26.  
  27.     len = FF_GetMsg(*str, msgid);
  28.  
  29.     *str += len;
  30.  
  31.     //FF_GetMsg(&tmp[0], msgid);
  32.     //len = xstrlen(&tmp[0]);
  33.     if (len == 0) {
  34.         simplealert(TEXT("strcpy_advance_id ist len=0!"));
  35.     }
  36.    
  37. }
  38.  
  39. // Attention: No bounds checking!
  40. int FF_GetMsg(TCHAR* ret, int MsgId) {
  41. #ifdef WIN_ENV
  42.  
  43. #ifdef UNICODE
  44.     TCHAR* szMsg;
  45.     int len;
  46.     len = LoadString(hDllInstance, MsgId, (LPTSTR)&szMsg, 0);
  47.     if (len == 0) return 0; // resource not found
  48.     if (ret != NULL) {
  49.         LoadString(hDllInstance, MsgId, ret, len + 1);
  50.     }
  51.     return len;
  52. #else
  53.     // LoadStringA is either broken or badly documented!
  54.     // The documentation says that you receive a read-only string reference as well as the length as return value if cchBufferMax==0.
  55.     // Reality shows that return value is -1 if cchBufferMax==0.
  56.     // https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/8d8c5382-1867-460a-a18f-70dc425ffe2f/loadstring-not-behaving-as-documented?forum=windowssdk
  57.     // We cannot receive a read-only memory using LoadStringA, because the WinAPI needs to do a Unicode-to-ANSI convertion,
  58.     // so we must define some max limit.
  59.     TCHAR szMsg[4096];
  60.     int len;
  61.     len = LoadString(hDllInstance, MsgId, (LPTSTR)&szMsg, 4096);
  62.     if (len == 0) return 0; // resource not found
  63.     if (ret != NULL) {
  64.         LoadString(hDllInstance, MsgId, ret, len + 1);
  65.     }
  66.     return len;
  67. #endif
  68.  
  69. #else
  70.         Str255 msg;
  71.         GetIndString(msg, 1000, MsgId);
  72.     myp2cstrcpy(ret, msg);
  73. #endif
  74. }
  75.  
  76. // Attention: Requires FF_GetMsg_Free(), otherwise memory is leaked
  77. TCHAR* FF_GetMsg_Cpy(int MsgId) {
  78. #ifdef WIN_ENV
  79.     TCHAR* szMsg;
  80.     int len;
  81.     TCHAR* ret;
  82.     len = FF_GetMsg(NULL, MsgId);
  83.     if (len == 0) return NULL; // resource not found
  84.     ret = (TCHAR*)malloc((len+1) * sizeof(TCHAR));
  85.     if (ret == NULL) return NULL;
  86.     LoadString(hDllInstance, MsgId, ret, len+1);
  87.     return ret;
  88. #else
  89.     Str255 msg;
  90.     TCHAR* ret;
  91.     ret = (TCHAR*)malloc((len + 1) * sizeof(TCHAR));
  92.     GetIndString(msg, 1000, MsgId);
  93.     myp2cstrcpy(ret, msg);
  94.     return ret;
  95. #endif
  96. }
  97.  
  98. void FF_GetMsg_Free(TCHAR* str) {
  99.     free(str);
  100. }