Link to home
Start Free TrialLog in
Avatar of khampton
khampton

asked on

Hex Value

I'm not thinking correctly---so please help me see an oversight.

I have written a C++ std .dll to do some specific subclassing.  It works great.  It allows 2 VB apps on different threads to send a message code to each other.

I have defined this message code as:
const UINT TARGETMSG = 0x8001;  //msg we are trying to detect.

The communication is made via the PostMessage routine:

BOOL APIENTRY PostResult(HWND hwnd, long lResultCode)
//This function will post a message based on the lResultCode.
{
   long ret;
   //loop until we get a non-zero return or we max out --
   for (long i=0; i<MAXRETRIES; i++)
   {    
     ret=PostMessage(hwnd,TARGETMSG,lResultCode,0);
     if (ret != 0) return VB_TRUE;
   }
   return FALSE;
}

The Proc in the VB App that receives this result is:

...
Public Const MYUSERMSG AS LONG = &H8001
...
Public Function SubstWinProc1(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Dim ret
  Select Case uMsg
    Case MYUSERMSG
        If wParam = 0 Then ret = "SUCCESSFUL" Else ret = "FAILURE"
        Form1.txtMsgProcesser = ret
        SubstWinProc1 = False 'return a false to prevent further processing of this uMsg.
    Case Else
        'Tell the DLL to handle the message
        SubstWinProc1 = True
  End Select
End Function

MY PROBLEM IS THAT THE uMsg HAS A VALUE OF 32769 BUT THE VALUE OF MYUSERMSG = -32767


ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jhance
jhance

Hmmm, forget that last part.  I was in a hurry and wasn't thinking straight....

I'm sure someone else will explain it.

Later.  Gotta go.....
I think this might be what you are looking for:

http://support.microsoft.com/support/kb/articles/q189/3/23.asp
I'm not sure if this will solve your problem or not (since I'm not a big user of VB), but it's obvious that VB is interpreting (casting first?) your &H8001 as a short (2 bytes) rather than a long (4 bytes).  This could be because you are only specifying two bytes in the declaration.

Try this instead and see if it works:

Public Const MYUSERMSG AS LONG = &H00008001

Good luck!
Avatar of khampton

ASKER

I wish "The Master" solution worked.  Unfortunatly, the IDE converts &H00008001 TO &H8001 as you type it.  So no go on this suggestion.

LoungeLizard was able to point me to some articles that explained problems with UINT and API calls.  

But the most helpful was jhance's reminder that:
 32769 (base 10) = 0x8001 in hex
-32767 (base 10) = 0x8001 also in hex

This led me to the solution of declaring the constant as:

  Public Const MYUSERMSG AS LONG = 32769
instead of:
  Public Const MYUSERMSG AS LONG = &H8001

That is why I am awarding him the points.  

Thanks to all for your suggestions!

Thanks for reminding me of hex to base10 conversion problems.  By the way, there is no UINT type in VB.