Article View: borland.public.cppbuilder.nativeapi
Article #4268Re: Mutex troubles?
From: Remy Lebeau (TeamB)
Date: Mon, 27 Feb 2006 20:44
Date: Mon, 27 Feb 2006 20:44
63 lines
2810 bytes
2810 bytes
"Nate Lockwood" <RNLockwoodREMOVE@attglobal.net> wrote in message
news:43ffba42$1@newsgroups.borland.com...
> I'd like to pass a StringList, too
You won't be able to do that. Not directly, anyway. You will have to make
a copy of the TStringList data and send it in full from one process to
another. One way to do that is to use the WM_COPYDATA message. You can use
the TStringList's Text property to get the data, ie:
if( hWnd )
{
AnsiString sData = MyStringList->Text;
COPYDATASTRUCT cds = {0};
cds.dwData = WM_MYMSG;
cds.cbData = s.Length();
cds.lpData = sData.c_str();
::SendMessage(hWnd, WM_COPYDATA, 0, reinterpret_cast<LPARAM>(&cds));
}
//...
__fastcall TFormMail::TFormMain(TComponent *Owner)
: TForm(Owner)
{
Application->HookMainWindow(AppMessageHook);
}
__fastcall TFormMail::~TFormMain()
{
Application->UnhookMainWindow(AppMessageHook);
}
bool __fastcall TFormMain::AppMessageHook(TMessage &Message)
{
if( Message.Msg == WM_INITDIALOG )
return true;
if( Message.Msg == WM_COPYDATA )
{
LPCOPYDATASTRUCT lpcds =
reinterpret_cast<LPCOPYDATASTRUCT>(Message.LParam);
if( (lpcds->dwData == WM_MYMSG) && (WM_MYMSG != 0) )
{
MyStringList->Text =
AnsiString(static_cast<char*>(lpcds->lpData), lpcds->cbData);
return true;
}
}
return false;
}
> do I understand correctly that I can create a StringList
> in the heap, pass its address in one of the parameters?
No. Different processes, even when launched from the same executable file,
have different address spaces from each other. A memory address in one
process is not a valid address in another process.
Gambit
Technical Details
Message-ID:
<4403647d@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<43ff726e$1@newsgroups.borland.com> <43ff96a0$1@newsgroups.borland.com> <43ffba42$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,7b6bdf1fac3d7d96 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <43ff726e$1@newsgroups.borland.com> <43ff96a0$1@newsgroups.borland.com> <43ffba42$1@newsgroups.borland.com> Subject: Re: Mutex troubles? Date: Mon, 27 Feb 2006 12:44:32 -0800 Lines: 65 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <4403647d@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1141073021 68.69.17.41 (27 Feb 2006 12:43:41 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail