gilad111397
asked on
Resource Dll in Borland
When working with several languages (using resource dll
for each) how can I set one of them in run time ?
for each) how can I set one of them in run time ?
Borland is not really "resource dll" friendly - one of the primary reasons I moved to VC++ about a year ago.
If you have VC++ you can place all resources into one DLL and make it work - with BC++ you must have several DLL's - one for each language
The following function allocates a resource buffer - then retrieves the string associated with the value passed
//======================== ========== ========== ========== ========== =========
// Name: GetBuff
// Purpose: This is the buffer allocator. Each time it's called, it returns
// a pointer to a 256-byte temporary buffer. As a convenience to
// the caller, the first byte of the buffer is set to zero.
//======================== ========== ========== ========== ========== =========
LPSTR PASCAL GetBuff (void)
{
typedef char Buffer [MAXSTRSIZE]; // define our string buffer
LPSTR p;
HANDLE hBuff;
static int BufNum = 0;
static Buffer far * szBuffer = NULL;
// If this is the first call, then allocate the buffer
if (szBuffer == NULL)
{
hBuff = GlobalAlloc (GHND, sizeof (Buffer) * NUMBUFFERS);
if (hBuff == NULL); // Now's the time to panic !
szBuffer = (Buffer far *) GlobalLock (hBuff);
}
p = szBuffer [BufNum++];
if (BufNum >= NUMBUFFERS) BufNum = 0;
*p = '\0';
return p;
}
//======================== ========== ========== ========== ========== =========
// Name: GetResStr
// Purpose: This new version of GetResStr uses GetBuff to get a temporary
// buffer for holding the returned string.
//======================== ========== ========== ========== ========== =========
LPSTR PASCAL GetResStr (WORD id)
{
LPSTR p;
LoadString (hInstance, id, p = GetBuff(), MAXSTRSIZE - 1);
return p;
}
Example :
/* Set the WIndow Title */
SetWindowText(hDlg, GetResStr (IDS_LD_TITLE));
Let me know if you need more
Darrin
If you have VC++ you can place all resources into one DLL and make it work - with BC++ you must have several DLL's - one for each language
The following function allocates a resource buffer - then retrieves the string associated with the value passed
//========================
// Name: GetBuff
// Purpose: This is the buffer allocator. Each time it's called, it returns
// a pointer to a 256-byte temporary buffer. As a convenience to
// the caller, the first byte of the buffer is set to zero.
//========================
LPSTR PASCAL GetBuff (void)
{
typedef char Buffer [MAXSTRSIZE]; // define our string buffer
LPSTR p;
HANDLE hBuff;
static int BufNum = 0;
static Buffer far * szBuffer = NULL;
// If this is the first call, then allocate the buffer
if (szBuffer == NULL)
{
hBuff = GlobalAlloc (GHND, sizeof (Buffer) * NUMBUFFERS);
if (hBuff == NULL); // Now's the time to panic !
szBuffer = (Buffer far *) GlobalLock (hBuff);
}
p = szBuffer [BufNum++];
if (BufNum >= NUMBUFFERS) BufNum = 0;
*p = '\0';
return p;
}
//========================
// Name: GetResStr
// Purpose: This new version of GetResStr uses GetBuff to get a temporary
// buffer for holding the returned string.
//========================
LPSTR PASCAL GetResStr (WORD id)
{
LPSTR p;
LoadString (hInstance, id, p = GetBuff(), MAXSTRSIZE - 1);
return p;
}
Example :
/* Set the WIndow Title */
SetWindowText(hDlg, GetResStr (IDS_LD_TITLE));
Let me know if you need more
Darrin
>>Borland is not really "resource dll" >>friendly
I shouldn't say that.
I have not met any such problem when I used the Borland compiler before.
I moved to VCC by another reasons.
I shouldn't say that.
I have not met any such problem when I used the Borland compiler before.
I moved to VCC by another reasons.
What I really meant to say was that in VC++ you can add strings which are only loaded dependant upon the country setting you choose - in BC++ (5.01) you cant do this - BC++ wont compile several different languages in the same resource file.
DarrinE
DarrinE
No problem, at least with my Borland 5.02
LANGUAGE LANG_GERMAN, LANG_NEUTRAL
STRINGTABLE
{
1,"Ya"
}
LANGUAGE LANG_ENGLISH, LANG_NEUTRAL
STRINGTABLE
{
1,"Yes"
}
LANGUAGE LANG_GERMAN, LANG_NEUTRAL
STRINGTABLE
{
1,"Ya"
}
LANGUAGE LANG_ENGLISH, LANG_NEUTRAL
STRINGTABLE
{
1,"Yes"
}
And no problem with my Borland 5.01
ASKER
In VC++ you use afxSetResourceHandler with the HANDLE you got from the LoadLibrary and everything is ok. Is there an equivavlent api to that in Borland ?
NickRepin changed the proposed answer to a comment
ASKER
send the close form.
I am not good expert in MFC , but seems
me that TModule class make all functions,
as afxSetResourceHandler :
example from my project:
TModule resModule = new TModule(szNameDll);
....
cdBitmap[nIcon1].hGraph = resModule->LoadBitmap(IDB_ SHPS + ind);
...
Or
return resModule->LoadString(code ,buff, 80) - 1;
....
Class TModule encapsuleted all Functions
for work with Resoureces. See BC Doc and
BorlandC examples for more Information.
Alex
me that TModule class make all functions,
as afxSetResourceHandler :
example from my project:
TModule resModule = new TModule(szNameDll);
....
cdBitmap[nIcon1].hGraph = resModule->LoadBitmap(IDB_
...
Or
return resModule->LoadString(code
....
Class TModule encapsuleted all Functions
for work with Resoureces. See BC Doc and
BorlandC examples for more Information.
Alex
ASKER
You should have explained about the resource wizard and the richedit sample that the help reference to.
Gilad, may be i don't understand something? You ask about Api/Class for
working with Resource Dll, right?
Now you ask something other.
Roule of EE: only one question in you Q! And, sorry, what wrong in my reply?
TModule does not works? Or something
else?
working with Resource Dll, right?
Now you ask something other.
Roule of EE: only one question in you Q! And, sorry, what wrong in my reply?
TModule does not works? Or something
else?
ASKER
It was the same question. I didn't check your sujestion, cause I read about the other idea (with the wizard), but I guess you may be right and since you may be right I assume you deserve the points so send the form again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you placed all languages into the same dll, the Windows must choose appropriate resources itself.
Alternatively, you can use FindResourceEx/LoadResourc