Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

literal strings in DLL's

8 views
Skip to first unread message

John Tarbotton

unread,
Jul 13, 1993, 8:32:51 PM7/13/93
to
Is there some rule about using literal strings in DLL's?
I find that literal strings can not be passed to any functions.
I am using Borland C++ ver. 3.1.
Settings are Compact model, assume DS never equal SS,
and word alignment.
If I use resource string tables every thing is fine. Maybe
I should just get some good programming habits and put all my character
strings in the resource file. :-)
Any ideas?

Example:

int FAR PASCAL WSAStartup ()
{
char lhstr[20];
char lnstr[20];

LoadString(hInst,1,prstr,20);
LoadString(hInst,5,lnstr,20);
MessageBox(NULL,"name","WSAStartup",MB_OK); // This doesn't work
MessageBox(NULL,lnstr,prstr,MB_OK); // This works
}

THANX
... johnt ...

David Brabant

unread,
Jul 22, 1993, 3:09:35 AM7/22/93
to
In article <1...@poolhall.win.net> jo...@poolhall.win.net (John Tarbotton) writes:
>From: jo...@poolhall.win.net (John Tarbotton)
>Date: Wed, 14 Jul 1993 00:32:51 GMT
>Subject: literal strings in DLL's

> Is there some rule about using literal strings in DLL's?
>I find that literal strings can not be passed to any functions.
>I am using Borland C++ ver. 3.1.
> Settings are Compact model, assume DS never equal SS,
>and word alignment.
> If I use resource string tables every thing is fine. Maybe
>I should just get some good programming habits and put all my character
>strings in the resource file. :-)
> Any ideas?
>
>Example:
>
>int FAR PASCAL WSAStartup ()
> {
> char lhstr[20];
> char lnstr[20];
>
> LoadString(hInst,1,prstr,20);
> LoadString(hInst,5,lnstr,20);
> MessageBox(NULL,"name","WSAStartup",MB_OK); // This doesn't work

You must do a cast to (LPCSTR) ... So rewrite the above line as this :

MessageBox(NULL, (LPCSTR) "name", (LPCSTR) "WSAStartup", MB_OK);

> MessageBox(NULL,lnstr,prstr,MB_OK); // This works
> }
>
>THANX

David

****************************************************************
* David Brabant * E-MAIL : da...@tintin.csl.sni.be *
* Siemens Nixdorf * *
* Centre Software de Liege * Phone : (041) 20.16.09 *
* 2, rue des Fories * *
* 4020 Liege, Belgium * *
****************************************************************

Kevin Gross

unread,
Jul 26, 1993, 9:08:28 PM7/26/93
to
David Brabant (da...@csl.sni.be) wrote:
: You must do a cast to (LPCSTR) ... So rewrite the above line as this :

: MessageBox(NULL, (LPCSTR) "name", (LPCSTR) "WSAStartup", MB_OK);

as long as windows.h is dutifully #included the prototype for MessageBox()
should clue the compiler in to the need for a cast. there must be
something els going on here.

-kg

Alan Merrell

unread,
Jul 28, 1993, 1:06:25 PM7/28/93
to
This may qualify as a WAG, but I've seen similar problems dealing with
strings and casting in BC++...

The issue is whether or not the prototype declared the input string
as a const. A const parameter can't be changed by the called routine.
The compiler won't automatically deal with the const issue in the same
way it deals with other conversions.

This routinely pops up when using the STRING and stream classes. Both
of these classes allow you to access the string directly, but in
read only (const) mode. If you attempt to reference the string as a
parameter (to say, printf) without casting it to const, then you get
an error message that is very hard to interpret.

(note that const is the difference between LPCSTR and LPSTR). )

Alan

0 new messages