Subversion Repositories filter_foundry

Rev

Rev 521 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
492 daniel-mar 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
 
495 daniel-mar 23
void strcpy_advance_id(TCHAR** str, int msgid) {
522 daniel-mar 24
    int len = FF_GetMsg(*str, msgid);
521 daniel-mar 25
    *str += len;
495 daniel-mar 26
}
27
 
492 daniel-mar 28
// Attention: No bounds checking!
521 daniel-mar 29
int FF_GetMsg(TCHAR* ret, int MsgId) {
492 daniel-mar 30
#ifdef WIN_ENV
521 daniel-mar 31
 
32
#ifdef UNICODE
33
    TCHAR* szMsg;
492 daniel-mar 34
    int len;
35
    len = LoadString(hDllInstance, MsgId, (LPTSTR)&szMsg, 0);
521 daniel-mar 36
    if (len == 0) return 0; // resource not found
37
    if (ret != NULL) {
38
        LoadString(hDllInstance, MsgId, ret, len + 1);
39
    }
40
    return len;
492 daniel-mar 41
#else
521 daniel-mar 42
    // LoadStringA is either broken or badly documented!
43
    // The documentation says that you receive a read-only string reference as well as the length as return value if cchBufferMax==0.
44
    // Reality shows that return value is -1 if cchBufferMax==0.
45
    // https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/8d8c5382-1867-460a-a18f-70dc425ffe2f/loadstring-not-behaving-as-documented?forum=windowssdk
46
    // We cannot receive a read-only memory using LoadStringA, because the WinAPI needs to do a Unicode-to-ANSI convertion,
47
    // so we must define some max limit.
48
    TCHAR szMsg[4096];
49
    int len;
50
    len = LoadString(hDllInstance, MsgId, (LPTSTR)&szMsg, 4096);
51
    if (len == 0) return 0; // resource not found
52
    if (ret != NULL) {
53
        LoadString(hDllInstance, MsgId, ret, len + 1);
54
    }
55
    return len;
56
#endif
57
 
58
#else
492 daniel-mar 59
        Str255 msg;
60
        GetIndString(msg, 1000, MsgId);
61
    myp2cstrcpy(ret, msg);
62
#endif
63
}
64
 
496 daniel-mar 65
// Attention: Requires FF_GetMsg_Free(), otherwise memory is leaked
492 daniel-mar 66
TCHAR* FF_GetMsg_Cpy(int MsgId) {
493 daniel-mar 67
#ifdef WIN_ENV
492 daniel-mar 68
    int len;
69
    TCHAR* ret;
521 daniel-mar 70
    len = FF_GetMsg(NULL, MsgId);
71
    if (len == 0) return NULL; // resource not found
496 daniel-mar 72
    ret = (TCHAR*)malloc((len+1) * sizeof(TCHAR));
492 daniel-mar 73
    if (ret == NULL) return NULL;
493 daniel-mar 74
    LoadString(hDllInstance, MsgId, ret, len+1);
492 daniel-mar 75
    return ret;
493 daniel-mar 76
#else
77
    Str255 msg;
78
    TCHAR* ret;
496 daniel-mar 79
    ret = (TCHAR*)malloc((len + 1) * sizeof(TCHAR));
493 daniel-mar 80
    GetIndString(msg, 1000, MsgId);
81
    myp2cstrcpy(ret, msg);
82
    return ret;
83
#endif
496 daniel-mar 84
}
85
 
86
void FF_GetMsg_Free(TCHAR* str) {
87
    free(str);
492 daniel-mar 88
}