Re: SendMessage crashing

Tech-Archive recommends: Fix windows errors by optimizing your registry



Tom,

It seems the reasons for the receiving end crashing is the CopyMemory() in
the ReadLatestMessage sub.

If I change...

Call CopyMemory(NewInMessage, ByVal MyDataStruct.lpData,
MyDataStruct.cbData)

to this

Call CopyMemory(NewInMessage, ByVal MyDataStruct.lpData,
Len(MyDataStruct.cbData))

It will not crash.

However there is something going wrong somewhere because it seems it's only
returning the first two
values from the transmitted data.

The data it should pass is:

BedNumber As Integer
BedOnOff As Boolean
HeartOnOff As Boolean
BreathingOnOff As Boolean
BloodPressureOnOff As Boolean
TimeStamp As String

But it only sends the right data for

BedNumber As Integer
BedOnOff As Boolean

The remaining 4 are all False even though they should be true/false
(according to how I set them in the sending app).

It seems to me it's only reading the first 2 Bool values (however many bits
this is) and not the rest of the sub.

It's got to be some small bug somewhere hard to trace as I glare at the code
and it just looks "OK".

Adam

"Tom Esh" <tjeshGibberish@xxxxxxxxxx> wrote in message
news:nqa871likm2k2l27n97876q2r1eub2j0ip@xxxxxxxxxx
> On Sun, 1 May 2005 00:24:37 +0100, "Adam Honek"
> <AdamHonek@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>>Thanks a lot, so it's back to pointers then....makes sense now as lngParam
>>is only
>>32bits hence we couldn't pass much data over anyway.
>>
>>I've changed my code and it compiles but on the receiving app I don't get
>>any
>>data displayed. I'm putting it into a listbox just for testing purposes.
>>
>>Are my subs now correct?
>
>>...
>> MyDataStruct.cbData = 3
>> MyDataStruct.dwData = Len(OutMessage)
>> MyDataStruct.lpData = VarPtr(OutMessage)
>
> Looks Ok except you're using cbData and dwData backwards there.
> cbData specifies the size / length of lpData. dwData is just 4 bytes
> for whatever you want to cram into it (except a pointer of course).
>
> Should be...
> MyDataStruct.cbData = Len(OutMessage)
> MyDataStruct.dwData = 3
> MyDataStruct.lpData = VarPtr(OutMessage)
>>...
>>As I understand it the process is as follows:
>>1) Any of our data gets fed into a COPYDATASTRUCT type variable
>>2) We process sendmessage with WM_COPYDATA
>>3) We pick up the WM_COPYDATA new mesage in the other process in
>>WindowProc() etc.
>>4) We copy the lngParam parameter back into a COPYDATASTRUCT type variable
>>5) We copy the COPYDATASTRUCT type variable back into our own user type
>>variable (i.e. IN_MESSAGE)
>>6) We can now use the data we've passed between processes
>>
>>Anything I've overlooking?
>
> Yep, that's about it.
>
>
> -Tom
> MVP - Visual Basic
> (please post replies to the newsgroup)


.



Relevant Pages

  • Re: A little challenge for relativists.
    ... The Moon is 1.2 light seconds from Earth, ... > Dim redfirst As Boolean, bluefirst As Boolean, bluesecond As ... > Private Sub Command1_Click ...
    (sci.physics.relativity)
  • Re: Sorting a System.Collections.ObjectModel.Collection
    ... Public Sub Dispose() Implements System.IDisposable.Dispose ... Private m_SupportsSorting As Boolean = True ... Protected Overrides ReadOnly Property SupportsSortingCoreAs Boolean ... Dim m_SortList As New ArrayList ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Sorting a System.Collections.ObjectModel.Collection
    ... Public Sub Dispose() Implements System.IDisposable.Dispose ... Private m_SupportsSorting As Boolean = True ... Protected Overrides ReadOnly Property SupportsSortingCoreAs Boolean ... Dim m_SortList As New ArrayList ...
    (microsoft.public.dotnet.languages.vb)
  • Re: COM+, CRMs and Stuff
    ... Public Shared StartPath As String ... Public Sub New ... Dim _aRecord As New aRecord ... Function PrepareRecordAs Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: A little challenge for relativists.
    ... The Moon is 1.2 light seconds from Earth, ... > Dim redfirst As Boolean, bluefirst As Boolean, bluesecond As Boolean, ... > Private Sub Command1_Click ...
    (sci.physics.relativity)