RegisterWindowMessage return different in VB.NET and VC++

L

LamNgo

Hi group,

I have two application that need to communicate with each other, one
written in C++ and the other in VB.NET. To communicate, I use
"SendMessage" API to send message from C++ app to VB.NET app. But I
don't know why the RegisterMessage API return different value for the
same message string in C++ and VB.NET???
This is the code segment:

C++:
UINT nFoo = RegisterWindowMessage(_T("ExtraMessage"))

VB.NET:
Dim nBar As Int32
Private Declare Function RegisterWindowMessage Lib "user32" Alias
"RegisterWindowMessageW" (ByVal lpString As String) As Integer

nBar = RegisterWindowMessage(_T("ExtraMessage"))

But the nBar is alway differ from nFoo!!!

Does anyone know the reason why?
I'm using VS.NET 2003, all apps is compile with unicode.

Thanks,
 
R

rawCoder

Hi LamNgo

One thing that comes in mind is that the declaration should return long
instead on integer... somethign like this
Declare Function RegisterWindowMessage Lib "user32" Alias
"RegisterWindowMessageA" (ByVal lpString As String) As Long

Hope this helps
rawCoder
 
L

LamNgo

Hi,

I follow your guide but the result is stranger. The value of
registered message is too large....and more different from the message
registered by VC++ app.....

Lam
 
K

Ken Tucker [MVP]

Hi,

You are using the wrong version of RegisterWindowMessage meaning use
RegisterWindowMessageA not W. Second the Integer is the correct return
value. The vb6 long is the same as vb.net integer.

Private Declare Function RegisterWindowMessage Lib "user32" Alias
"RegisterWindowMessageA" (ByVal lpString As String) As Integer

Ken
----------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top