AutoHotkey Community

It is currently May 26th, 2012, 9:31 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 59 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject:
PostPosted: August 8th, 2009, 5:19 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
I will make modifications according to your analyses.

Thank you Lex.

PS:
Quote:
(Also edit: "i.e. 64-bit on 64-bit Windows" was inaccurate.)

I like your kind of precision m8 :D

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 10th, 2009, 10:47 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
2 Lexikos

I have some questions:

1. What happens when 32bit AHK talks to 64 C# ? I guess system will do the marchaling ...

2. Original IPC.cs should work when compiled on 64bit. I realised I started 32bit app on 64 bit system.....

3. Do you think its possible and valuable to have single IPC.cs adjusting to changes in OS, no matter the how you compiled it, similar to what some people done here on AHK forum, when dealing with this stuff - i.e. checking the OS type and using appropriate NumGet. I don't know is there any technique in DotNet for mixing 32b and 64b.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 10th, 2009, 11:51 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
majkinetor wrote:
1. What happens when 32bit AHK talks to 64 C# ? I guess system will do the marchaling ...
Yes, as it does between any two processes.
Quote:
2. Original IPC.cs should work when compiled on 64bit. I realised I started 32bit app on 64 bit system.....
I would think it should be the opposite - assuming the "original" is the version which defines all members of COPYDATASTRUCT as 32-bit, it should only work as a 32-bit app. For instance, compiled as 64-bit the "dwData" and "cbData" C# fields would actually refer to two halves of the real dwData field, and "lpData" would actually refer to cbData.
Quote:
3. Do you think its possible and valuable to have single IPC.cs adjusting to changes in OS, no matter the how you compiled it, similar to what some people done here on AHK forum, when dealing with this stuff - i.e. checking the OS type and using appropriate NumGet.
Do you mean IPC.ahk rather than IPC.cs? There shouldn't be any "adjusting" necessary in .NET, as long as you use the correct system-dependent types (i.e. IntPtr is sized depending on the OS).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 10th, 2009, 2:03 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
I would think it should be the opposite - assuming the "original" is the version which defines all members of COPYDATASTRUCT as 32-bit, it should only work as a 32-bit app

Fields of the structure are not defined as Int32 but as int. Somehow I thought that int is 64bit on 64bit systems....

Quote:
There shouldn't be any "adjusting" necessary in .NET, as long as you use the correct system-dependent types (i.e. IntPtr is sized depending on the OS).

I see. Thanks.

_________________
Image


Last edited by majkinetor on August 10th, 2009, 2:48 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 10th, 2009, 2:41 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
version 2.6
- DotNet class fixes for 64b systems (made by Lexikos).
- Test apps for 32b and 64b systems.
- Docs update.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 10th, 2009, 3:03 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
majkinetor wrote:
Fields of the structure are not defined as Int32 but as int. Somehow I thought that int is 64bit on 64bit systems....
If int were 64-bit, the structure would still be incorrect since the second field is supposed to be 32-bit. I guess you now realise int is always an alias for Int32. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 10th, 2009, 3:15 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Yes :)

This reveals my biggest mind bug: it refuses to think about small details .... Since the devil is in details, it often goes against me... :?

Ty 4 ur patience.

Image

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 19th, 2009, 4:50 am 
Offline

Joined: January 10th, 2009, 1:34 pm
Posts: 135
Location: Virginia
Thank you so much for making this module!

I have been trying to solve a problem with multiple midi inputs.
Unable to solve my problem one way, I have look for alternative.
I found this module. Since all I really need is data values coming back to the main script, I thought this module made sense.

I am trying to send the midi note number from script1 to script2.
Script2.ahk as well as IPC.ahk (from module archive) remain untouched and script2 is running. Once it gets to script2 I will do other stuff with the note number, like trigger keystrokes.


I confirm the following -
1. Edited Script1.ahk successfully sends the edit box to script 2.
2. Midi input is working and midi messages are being split up into bytes.
3. Midi note numbers are correct and show up in script1 gui box.

Can someone please take a look and help me route my data properly?

Script1.ahk edited as follows including the midi input.
Code:
;#SingleInstance, off   ;allow multiple instances
   target := "Script2"
   stress := 1000,   x:=300
   ;========================

   Gui, +LastFound     +AlwaysOnTop
   hScript := WinExist() + 0

   Gui, Font, s10

   Gui, Add, Edit,      vMyMsg  w200 , midiMsg
   
   Gui, Add, Edit,  x+0 vMyPort w50, 100

   Gui, Font, s8
   Gui, Add, Button, x+5   gOnSend        , Send
   Gui, Add, Button, x+5   gOnSendBinary , Send Binary
   Gui, Add, Button, x+5   gOnStress     , Stress

   Gui, Add, ListBox,xm w440 h300 vMyLB,
   Gui, Show, x%x%   AutoSize
   
   GuiControl, , MyLB, This script HWND: %hScript%
   IPC_SetHandler("OnData")

; --------   inserted code ----------
/*
   I am trying to get the midi note number input passed to script 2.
   I currently have it showing the note number pressed in this scripts window
   Script1.
   
*/
; SET THIS DEVICEiD TO YOUR MIDI INPUT PORT, 0 IS THE FIRST MIDI PORT,
; most of this code written by orbik.

DeviceID := 1 ; hardware keyboard
CALLBACK_WINDOW := 0x10000

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#Persistent

Gui, +LastFound
hWnd := WinExist()

OpenCloseMidiAPI()
OnExit, Sub_Exit

hMidiIn =
VarSetCapacity(hMidiIn, 4, 0)

result := DllCall("winmm.dll\midiInOpen", UInt,&hMidiIn, UInt,DeviceID, UInt,hWnd, UInt,0, UInt,CALLBACK_WINDOW, "UInt")

   If result
   {
      MsgBox, error, midiInOpen returned %result%`n
      GoSub, sub_exit
   }

hMidiIn := NumGet(hMidiIn) ; because midiInOpen writes the value in 32 bit binary number, AHK stores it as a string

result := DllCall("winmm.dll\midiInStart", UInt,hMidiIn)

If result
   {
      MsgBox, error, midiInStart returned %result%`n
      GoSub, sub_exit
   }

; for reference only
; #define MM_MIM_OPEN 0x3C1 /* MIDI input */
; #define MM_MIM_CLOSE 0x3C2
; #define MM_MIM_DATA 0x3C3
; #define MM_MIM_LONGDATA 0x3C4
; #define MM_MIM_ERROR 0x3C5
; #define MM_MIM_LONGERROR 0x3C6

OnMessage(0x3C1, "midiInHandler") ; calling the function below
OnMessage(0x3C2, "midiInHandler")
OnMessage(0x3C3, "midiInHandler")
OnMessage(0x3C4, "midiInHandler")
OnMessage(0x3C5, "midiInHandler")
OnMessage(0x3C6, "midiInHandler")

return

;--------End of auto-execute section-----

OpenCloseMidiAPI() ; calls the winmm.dll to close midi port
   {
      Static hModule
      If hModule
      DllCall("FreeLibrary", UInt,hModule), hModule := ""
      If (0 = hModule := DllCall("LoadLibrary",Str,"winmm.dll"))
      {
         MsgBox Cannot load library winmm.dll
         ExitApp
      }
   }

midiInHandler(hInput, midiMsg, wMsg) ; THIS IS THE MIDI IN FUNCTION WHERE THE MIDI MESSAGE IS BROKEN UP
   {
      statusbyte    :=  midiMsg & 0xFF         ; EXTRACT THE STATUS BYTE (WHAT KIND OF MIDI MESSAGE IS IT)
      chan       := (statusbyte & 0x0f) + 1   ; WHAT MIDI CHANNEL IS THE MESSAGE ON?
      byte1       := (midiMsg >> 8) & 0xFF   ; THIS IS DATA1 VALUE = NOTE NUMBER OR CC NUMBER
      byte2       := (midiMsg >> 16) & 0xFF   ; DATA2 VALUE IS NOTE VELEOCITY OR CC VALUE

    IfEqual, statusbyte, 144 ; test for noteOn message
      {

; how do I get byte1 "note number" sent to script2?

         Data := byte1 ; set var to the byte1 Midi note number
         OnData(Hwnd, Data, Port, Size)
         ;IPC_Send( WinExist( target ), %byte1%, MyPort)
         ;gosub, OnSend
        }
   Else
       {
       }
   }
;------ end of inserted code ---
return

OnData(Hwnd, Data, Port, Size)    
   {
      global myLB

      if Size =
          s = %Port%      Hwnd: %hwnd%      Message: %Data%
      else
      {       
           x := NumGet(Data+0), y := NumGet(Data+4)
           s = %Port%     Hwnd: %HWND%      Binary Data: POINT (%x%, %y%)      DataSize: %Size%
      }   
      GuiControl, , MyLB, %s%
   }

OnSend:
   Gui, Submit, NoHide
   if !IPC_Send( WinExist( target ), MyMsg, MyPort)
      MsgBox Sending failed
return

OnStress:
   Gui, Submit, NoHide
   if !(h := WinExist( target ))
      MsgBox Host doesn't exist
   loop, %stress%
      IPC_Send(h, MyMsg " : " A_Index, MyPort)
return

OnSendBinary:
   Gui, Submit, NoHide
   VarSetCapacity(POINT, 8), NumPut(2000, POINT), NumPut(8000, POINT, 4)
   if !IPC_Send( WinExist( target ), &POINT, MyPort, 8)
      MsgBox Sending failed
return

GuiClose:
   ExitApp
return


; =============== this will exit the app when esc is pushed
Esc::GoSub, sub_exit

sub_exit:

   If (hMidiIn)
   DllCall("winmm.dll\midiInClose", UInt,hMidiIn)
   OpenCloseMidiAPI()
   ExitApp

#include ..\IPC.ahk


Thank you for looking!

_________________
KeyMce/GenMce - mackie emulator for pc keyboard/Convert your controller to mackie.
Midi I/O - Want to play with midi/ahk?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 4:42 pm 
Offline

Joined: November 15th, 2009, 10:21 pm
Posts: 21
Location: London, UK
When I read post like this I feel that I still have much to learn...

I found this webpage about IPC:

http://www.cs.cmu.edu/~IPC/

Does have anything to do with this script?

By the way... Well done script! I always appreciate look at the digital art of coding.

_________________
Image

http://www.autohotkey.net/~FirstToyLab/


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 5:45 pm 
Offline

Joined: January 10th, 2009, 1:34 pm
Posts: 135
Location: Virginia
First Toy Labs wrote:
When I read post like this I feel that I still have much to learn...

I found this webpage about IPC:

http://www.cs.cmu.edu/~IPC/

Does have anything to do with this script?

By the way... Well done script! I always appreciate look at the digital art of coding.



The IPC stuff is all majkinetor's code.
The midi in stuff is all orbik's code.


I am just a I guy who stumbled on some parts and employed a weak assembling force, to minimal success.

I have a lot to learn as well, I know just enough to get myself into trouble!
Like here.

_________________
KeyMce/GenMce - mackie emulator for pc keyboard/Convert your controller to mackie.
Midi I/O - Want to play with midi/ahk?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 7:23 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
I found this webpage about IPC:

http://www.cs.cmu.edu/~IPC/

Does have anything to do with this script?

No.
That system uses TCP connections.
IPC uses WM_COPYDATA message (so its local only unlike TCP). The best way to learn about it is MSDN.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 9th, 2010, 3:25 pm 
Hi, all
I found on my Win XP which is a Chinese version, and the default encoding is in unicode (code page 936 for Chinese).

To let Script1.ahk and Script2.ahk run correctly, I have to change the following line in IPC.ahk

DataSize := StrLen(Data)+1, pData := &Data, Port := -Port
==>
DataSize := StrLen(Data)*2+2, pData := &Data, Port := -Port

Cheer!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2010, 11:39 pm 
Offline

Joined: January 8th, 2007, 1:14 pm
Posts: 83
Jabobian wrote:
DataSize := StrLen(Data)+1, pData := &Data, Port := -Port
==>
DataSize := StrLen(Data)*2+2, pData := &Data, Port := -Port


Thanks for this, also you can use something like this to support both ANSI and Unicode builds (for Autohotkey_L).

Code:
DataSize := A_IsUnicode ? StrLen(Data)*2+2 : StrLen(Data)+1


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 30th, 2010, 12:18 am 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Code:
DataSize := (StrLen(Data)+1) * (!!A_IsUnicode + 1)

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 31st, 2010, 3:23 am 
Offline

Joined: January 8th, 2007, 1:14 pm
Posts: 83
There might be possible "bug" in the DotNet code. When the WM_COPYDATA is received it should return TRUE, which the AHK code appears to be doing but the DotNet one does not (test executables). I might be wrong but something i noticed different when testing.

fincs wrote:
Code:
DataSize := (StrLen(Data)+1) * (!!A_IsUnicode + 1)


Yoink! :P


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 59 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: MSN [Bot] and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group