Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

SendMessage ANSI from a Unicode AHK?


  • Please log in to reply
4 replies to this topic
gllen
  • Members
  • 20 posts
  • Last active: Nov 02 2011 03:32 AM
  • Joined: 22 Nov 2006
Hi,

I recently started using the unicode version of AHK.

I have an older (ANSI) compiled script that I send data to with SendMessage. After moving to unicode the old ansi script no longer receives data from the new unicode scripts.

I'm pretty sure the function below needs to be changed to send ANSI instead of unicode. I'm completely lost though. Would someone be able to tell me how to modify this function to send ANSI?


Send_WM_COPYDATA(ByRef StringToSend, ByRef TargetScriptTitle)
  {
  VarSetCapacity(CopyDataStruct, 3*A_PtrSize, 0)
  SizeInBytes := (StrLen(StringToSend) + 1) * (A_IsUnicode ? 2 : 1)
  NumPut(SizeInBytes, CopyDataStruct, A_PtrSize)
  NumPut(&StringToSend, CopyDataStruct, 2*A_PtrSize)
  Prev_DetectHiddenWindows := A_DetectHiddenWindows
  Prev_TitleMatchMode := A_TitleMatchMode
  DetectHiddenWindows On
  SetTitleMatchMode 2
  SendMessage, 0x4a, 0, &CopyDataStruct,, %TargetScriptTitle%
  DetectHiddenWindows %Prev_DetectHiddenWindows%
  SetTitleMatchMode %Prev_TitleMatchMode%
  return ErrorLevel
  }


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Copy StrPutVar into your script, then make the following change:
[color=red]-[/color]  SizeInBytes := (StrLen(StringToSend) + 1) * (A_IsUnicode ? 2 : 1)
[color=green]+[/color]  SizeInBytes := StrPutVar(StringToSend, StringToSend, "cp0")
Untested.

gllen
  • Members
  • 20 posts
  • Last active: Nov 02 2011 03:32 AM
  • Joined: 22 Nov 2006
Woohoo! That worked perfectly, thank you so much! :D

closed
  • Members
  • 509 posts
  • Last active: Jan 14 2012 06:14 PM
  • Joined: 07 Feb 2008
Thanks Lexikos !!I spent some time on it but gave up and reversed back to ahk basic. :shock:

glenz10
  • Members
  • 2 posts
  • Last active: Aug 25 2011 05:21 AM
  • Joined: 24 Aug 2011
is this a quick message? i mean can send a message in a seconds? maybe this code will help in doing with my warcraft III hotkey