Board index » cppbuilder » int WParam = (char *) error (BCB6)

int WParam = (char *) error (BCB6)


2005-09-15 11:19:31 PM
cppbuilder58
Is there a technique that will let me send characters or a memory address as
part of a TMessage parameter? I have been trying to assign the memory
address to an integer, but I keep getting errors.
For example:
char FileInfo[] = "This text will be passed in SendMessage()";
TMessage msg;
msg.Msg = MYMESSAGEFLAG;
msg.LParam = 0;
msg.WParam = FileInfo; // this is not allowed
msg.Result = SendMessage(hForm, msg.Msg, msg.WParam, msg.LParam);
if (msg.Result != msg.Msg) {
MessageLog("Unexpected Messaging result from FTP WorkBegin.");
}
msg.Msg = 0;
Spits out the error: "E2034 Cannot convert 'char*' to 'int'". I've tried
typecasting FileInfo to a (void*), but that produced another E2034 error.
Is there a correct way to do this, or is this restricted for a reason?
--
Joe Pool
 
 

Re:int WParam = (char *) error (BCB6)

"Joe Pool" < XXXX@XXXXX.COM >wrote:
Quote

[...] I have been trying to assign the memory address to an
integer, but I keep getting errors. [...]

msg.WParam = FileInfo; // this is not allowed
That should be:
msg.WParam = &FileInfo;
However, I would do it more like:
int Result = ::SendMessage( hForm, MYMESSAGEFLAG, (WPARAM)&FileInfo, 0 );
This also presumes that hForm is the form's Handle, that
you're handler for MYMESSAGEFLAG returns a value *and* that
the receiver of the message does not cross application
boundries.
If you are sending the message to another application, then it
won't work because the address of FileInfo is only meaningful
within the context of the first application. In the second
application, that address may or may not be valid but in
either case, it certainly won't be pointing to what you want
it to be pointing it to.
If you want to send it to a second application, look in the
win32.hlp file under WM_COPYDATA.
~ JD
 

Re:int WParam = (char *) error (BCB6)

Thanks JD. I used:
msg.Result = SendMessage( hForm, msg.Msg, (WPARAM)&FileInfo, msg.LParam);
and that took care of it. I'll now read up on WM_COPYDATA.
"JD" < XXXX@XXXXX.COM >wrote in message
Quote

However, I would do it more like:

int Result = ::SendMessage( hForm, MYMESSAGEFLAG, (WPARAM)&FileInfo,
0 );

If you want to send it to a second application, look in the
win32.hlp file under WM_COPYDATA.

~ JD

 

{smallsort}

Re:int WParam = (char *) error (BCB6)

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
That should be:

msg.WParam = &FileInfo;
That is wrong. See my other reply.
JD, I'm really starting to get anoyed at how often I have to correct you all
the time. If you are not going to post accurate information, then please do
not post at all. Posting inaccurate answers is not helpful.
Gambit
 

Re:int WParam = (char *) error (BCB6)

"Joe Pool" < XXXX@XXXXX.COM >wrote in message
Quote
msg.WParam = FileInfo; // this is not allowed
Use the reinterpret_cast operato, ie:
msg.WParam = reinterpret_cast<int>(FileInfo);
//...
char *pFileInfo = reinterpret_cast<char*>(msg.WParam);
Quote
msg.Result = SendMessage(hForm, msg.Msg, msg.WParam, msg.LParam);
There is no need to use TMessage if you use SendMessage():
char FileInfo[] = "This text will be passed in SendMessage()";
int Result = SendMessage(hForm, MYMESSAGEFLAG,
reinterpret_cast<WPARAM>(FileInfo), 0);
Quote
if (msg.Result != msg.Msg) {
That is not correct. SendMessage() does not return the message that was
sent.
Gambit
 

Re:int WParam = (char *) error (BCB6)

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

>That should be:
>
>msg.WParam = &FileInfo;

That is wrong.
You are wrong. That is correct. Try this simple test:
//-------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char stuff[] = "Some string";
::SendMessage( Handle, WM_USER + 100, (WPARAM)&stuff, 0 );
}
//-------------------------------------------------------------
void __fastcall TForm1::WndProc( TMessage &Message )
{
if( Message.Msg == WM_USER + 100 )
{
AnsiString S = (char *) Message.WParam;
ShowMessage( S );
}
TForm::WndProc( Message );
}
//-------------------------------------------------------------
Quote
See my other reply.
While your other reply may be more acceptable in terms of
using C++ casting, it does not make my reply wrong. In fact,
considering that this group is for students, I intentionally
kept my reply more in line with old C-style casting because
that's what most students are more comfortable with.
Quote
JD, I'm really starting to get anoyed at how often I have to
correct you all the time.
I see no need to correct your spelling and grammer but I do
think that your annoyance, while exaggerated and misplaced
and probably pathological, is only fair because I have been
annoyed with your arrogance for almost 2 years. You take
pleasure in pointing out mistakes made by others but lack the
ability to admit mistakes made by yourself.
Even worse, you tend to berate the OP and when the OP (or
another) shows that you were mistaken, not only can't you
admit to your mistake, you most certainly can't apologize
when an apology is called for. Case in point:
tinyurl.com/9w3qw
As for "how often [you] have to correct [me] all the time",
I wouldn't call stating your opinion regarding a method that
you prefered over my choice a correction (this thread case in
point).
While we're on the subject of correcting, allow me to point
out to you 2 recent mistakes that you made in responding to
posts of mine:
tinyurl.com/a94ql
I can return *any* int that I want even though you said not.
True, it produces a compiler warning but it works.
tinyurl.com/72f68
You said that I couldn't Theme a TStringGrid because XP does
type checking when it does not. If I had listened to you, I'd
have never written a Themed grid - something that many people
would like to have and something that I'll be sharing shortly.
Quote
If you are not going to post accurate information, then
please do not post at all. Posting inaccurate answers is
not helpful.
Pot, Kettle ... Kettle, Pot. In all 3 of the above (recent)
examples, you assumed certain things to be the case and posted
based on those assumptions and you were wrong ... just like
you're wrong this time as well. I challange you to find 4
mistakes made by myself in the same time frame.
You owe me an apology you arrogant ass.
~ JD