1

Topic: To open a file. With ++ Builder

AnsiString open_file = Dir_gr + "\\hintgrdostupa.txt";
ShellExecute (Handle, "open", open_file.c_str (), NULL, NULL, SW_SHOWDEFAULT);
Error:
[bcc32 Error] Unit1_RightEndDoor.cpp (596): E2034 Cannot convert ' char const [5] ' to ' const wchar_t *'
Full parser context
Unit1_RightEndDoor.cpp (593): parsing: void _fastcall TMF_RightEndDoor:: Label47Click (TObject *)

2

Re: To open a file. With ++ Builder

Well what odd fellow will try to feed ANSI a line there where want UNICODE?.

3

Re: To open a file. With ++ Builder

On thought directs?
[spoiler] SHSTDAPI _ (HINSTANCE) ShellExecuteA (HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters;
LPCSTR lpDirectory, INT nShowCmd);
SHSTDAPI _ (HINSTANCE) ShellExecuteW (HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile, LPCWSTR lpParameters;
LPCWSTR lpDirectory, INT nShowCmd);
#ifdef UNICODE
#define ShellExecute ShellExecuteW
#else
#define ShellExecute ShellExecuteA
#endif
[/spoiler]

4

Re: To open a file. With ++ Builder

It is possible to correct simply the code, without odd fellows...
I understood by mistake that business in data type, but I will not catch up as correctly.
Tried instead of AnsiString wchar_t, all the same it did not turn out, how there should be the correct construction of conversion in the given example?

const wchar_t open_file = Dir_gr + "\\hintgrdostupa.txt";
ShellExecute (Handle, "open", open_file.c_str (), NULL, NULL, SW_SHOWDEFAULT);

5

Re: To open a file. With ++ Builder

Correctly m. Differently.
Try so in a head post
UnicodeString (open_file.c_str ())
Then you will tell.

6

Re: To open a file. With ++ Builder

//AnsiString open_file = Dir_gr + "\\hintgrdostupa.txt";
//UnicodeString (open_file.c_str ());
//ShellExecute (Handle, "open", open_file.c_str (), NULL, NULL, SW_SHOWDEFAULT);
[bcc32 Error] Unit1_RightEndDoor.cpp (626): E2034 Cannot convert ' char const [5] ' to ' const wchar_t *'
Full parser context
Unit1_RightEndDoor.cpp (621): parsing: void _fastcall TMF_RightEndDoor:: Label47Click (TObject *)

7

Re: To open a file. With ++ Builder

Oh, my God... c it starts to be confused and it can be finished easily...
B it is simple
ShellExecute (.......... open_file.c_str ()
Deliver there conversion:
UnicodeString (open_file.c_str ())

8

Re: To open a file. With ++ Builder

In general, all right, only now I have no time to look.
It is told above: the parameter expects such type. This type there means and it is necessary to deliver.
I do not know your adjustments and what there for type such at Dir_gr? Dig from it
//AnsiString open_file = Dir_gr + "\\hintgrdostupa.txt";
wchar_t *pathChar = UnicodeString (path).w_str ();
//ShellExecute (Handle, "open", pathChar, NULL, NULL, SW_SHOWDEFAULT);

9

Re: To open a file. With ++ Builder

exp98 wrote:

wchar_t *pathChar = UnicodeString (path).w_str ();

Also we receive the pointer on already released storage. A charming rake.

10

Re: To open a file. With ++ Builder

Anatoliy S. wrote:

AnsiString open_file = Dir_gr + "\\hintgrdostupa.txt";
ShellExecute (Handle, "open", open_file.c_str (), NULL, NULL, SW_SHOWDEFAULT);
Error:
[bcc32 Error] Unit1_RightEndDoor.cpp (596): E2034 Cannot convert ' char const [5] ' to ' const wchar_t *'
Full parser context
Unit1_RightEndDoor.cpp (593): parsing: void _fastcall TMF_RightEndDoor:: Label47Click (TObject *)

From this that is resulted in the text under type char const [5] approaches "open",  the version, then _T ("open") probably there is expected.
Well and at the same time that two times not to run, is visible not AnsiString, and  the version, presumably WideString.

11

Re: To open a file. With ++ Builder

Dimitry Sibiryakov wrote:

the Charming rake

Uups, is a jamb. And on that and a pike in the sea... I think, the HARDWARE already thinks (as it is possible without a rake.
By the way, I for the first time so wrote (and without malicious intention).

12

Re: To open a file. With ++ Builder

It turned out so:

UnicodeString open_file = "D: \\hintgrdostupa.txt";
ShellExecute (Handle, L "open", open_file.w_str (), NULL, NULL, SW_RESTORE);

Here so errors are not present, but the file does not open.

UnicodeString open_file = "D: \\hintgrdostupa.txt";
ShellExecute (Handle, (const wchar_t *) "open", (const wchar_t *) open_file.c_str (), NULL, NULL, SW_SHOWDEFAULT);

13

Re: To open a file. With ++ Builder

Anatoliy S. wrote:

here so errors are not present, but the file does not open.

And it is correct, for "(const wchar_t *)" open "" it is crazy delirium. You should study as
Computers that such bits, bytes and as they are interpreted work.

14

Re: To open a file. With ++ Builder

wrote:

You should study as

I think it agree....

wrote:

And it is correct, for "(const wchar_t *)" open "" it is crazy delirium.

I do purely by examples, without pressing in constructions and assignment.
P.S.
I remember some years ago (10).
In 5  all worked dataless transfers.
And it was written on With ++ Builder5 on sensation with Builder 10.2 easier. Truth wrote not long year / ones and a half.
Then departed from the PC generally. Well and experience of that time small ended couple of years, only institute. There was an euphoria and reading it was easier new.
Would buy the book on RAD Studio now, yes is not present. Books Arkhangelsk Earlier were pleasant.