Jump to content

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

MCode function + onlinegenerator (x86 and x64)


  • Please log in to reply
33 replies to this topic
Relayer
  • Members
  • 122 posts
  • Last active: Jun 22 2015 09:21 PM
  • Joined: 24 Nov 2008

Bentschi,

 

Previously you posted a link to the .ahk file.  Is that pointing to your most recent changes?  I like to see the underlying code.

 

Relayer



guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011

Update:
- fixed parse-errors in the generator (thanks guest3456 and Lexicos)
- Added Optimization "None" and "Default" in the generator
 
i've removed index2.php and replaced index.php with it.
Now the working generator is at http://bentschi.no-ip.org/mcode/ like before

thanks Bentschi, i ran a few quick tests with different C code inputs and it looks like it works. if i find any more problems, i'll let you know.

also

i've modified the new Mcode function to work with AHK_Basic as well as AHK_L, in case anyone needs it. i think i've done it correctly
;// new MCode function, modified to work with both AHK_L and AHK_Basic
;// http://www.autohotkey.com/board/topic/89283-mcode-function-onlinegenerator-x86-and-x64

MCode(mcode)
{
  static e1 := 4, e2 := 1
  static c
  c := (A_PtrSize=8) ? "x64" : "x86"
  ptr := A_PtrSize ? "Ptr" : "UInt"
  
  if (!regexmatch(mcode, "^([0-9]+),(" c ":|.*?," c ":)([^,]+)", m))
    return
  if (!DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", 0, "uint", e%m1%, ptr, 0, "uint*", s, ptr, 0, ptr, 0))
    return
  p := DllCall("GlobalAlloc", "uint", 0, ptr, s, ptr)
  if (c="x64")
    DllCall("VirtualProtect", ptr, p, ptr, s, "uint", 0x40, "uint*", op)
  if (DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", 0, "uint", e%m1%, ptr, p, "uint*", s, ptr, 0, ptr, 0))
    return p
  DllCall("GlobalFree", ptr, p)
}
edit/
^^ i'm not sure how reliable that is, it may or may not work

Bentschi
  • Moderators
  • 120 posts
  • Last active: Sep 05 2014 02:12 AM
  • Joined: 26 Nov 2008

Bentschi,

 

Previously you posted a link to the .ahk file.  Is that pointing to your most recent changes?  I like to see the underlying code.

 

Relayer

The actual code can be found here: http://bentschi.no-i...e/mcodegen2.ahk

 

BTW: 542 MCodes are generated since the first post wink.png



Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Does the generator support includes? I am working on a function that used a CDC object. When I simply use, #include "afkwin.h" The generated output gets all garbled. Example:

 

Spoiler

 

Generated output:

Spoiler

 

A DllCall on either function will return A_Blank


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011
pretty sure you cannot use includes for MCode. i think this was true of the old MCode func as well

MCode is supposed to be used for fast math calcs

Bentschi
  • Moderators
  • 120 posts
  • Last active: Sep 05 2014 02:12 AM
  • Joined: 26 Nov 2008

Like guest3456 said, it's more or less only for fast math calcs.

You cannot create a whole MFC app using this generator, but you can use allmost all WinAPI functions if the required DLLs are loaded.

If you compile your code, you get an error in the log.

I have no idea how to get this to work.

 

Edit: Statistics: 1053 codes are generated with the generator since the first post



MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

BTW, I'd like to thank you Bentschi for such great work.

I suppose I have myself generated ~50 codes. hehe happy.png


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio Fran├ža -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


Bentschi
  • Moderators
  • 120 posts
  • Last active: Sep 05 2014 02:12 AM
  • Joined: 26 Nov 2008

Thank you, but i have to say, that the generator would not be what it is without...

http://www.autohotke...ode-into-mcode/

...and all who helped (also in this thread).



Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Like guest3456 said, it's more or less only for fast math calcs.

You cannot create a whole MFC app using this generator, but you can use allmost all WinAPI functions if the required DLLs are loaded.

If you compile your code, you get an error in the log.

I have no idea how to get this to work.

 

Edit: Statistics: 1053 codes are generated with the generator since the first post

 

Understood. Thanks for the help, and great work!


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010

Something odd is going on here...

 

I'm entering this C code into the generator and it outputs results different from when I run it through my offline generator (the one you based this off). They're using identical switches but the output's different.

 

C code:

int Gdip_PixelSearch(int * Foundx, int * Foundy, unsigned char * hScan, unsigned char * NeedleColors, int NumColors, int hStride, int sx1, int sy1, int sx2, int sy2, int v, int sd)
{
    int y1, x1, idxH, idxColor, idxN;
    if ( sd == 1 ) { // [default] top->left->right->bottom (vertical preference)
        for (y1 = sy1; y1 < sy2; y1++) {
            for (x1 = sx1; x1 < sx2; x1++) {
                idxH = (4*x1)+(y1*hStride); // haystack index offset
                for (idxColor = 0; idxColor < NumColors; idxColor++) {
                    idxN = idxColor * 4;
                    if ( (  NeedleColors[idxN+2] <= hScan[idxH+2]+v
                    &&      NeedleColors[idxN+2] >= hScan[idxH+2]-v
                    &&      NeedleColors[idxN+1] <= hScan[idxH+1]+v
                    &&      NeedleColors[idxN+1] >= hScan[idxH+1]-v
                    &&      NeedleColors[idxN+0] <= hScan[idxH+0]+v
                    &&      NeedleColors[idxN+0] >= hScan[idxH+0]-v ) )
                    {
                        Foundx[0] = x1; Foundy[0] = y1;
                        return 0;
                    }
                }
            }
        }
    }
    Foundx[0] = -1; Foundy[0] = -1;
    return -7001;
}

It wouldn't let me add it but this is the results from the online/offline generation: https://ahknet.autoh...om/paste/trsu4d



guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011
RSeding, are you sure the optimization switches are correct in your offline generator? when i tried to use your offline generator the /O switches were broken, i mentioned it in a post here:
http://www.autohotke...mcode/?p=572690

if i remember correctly, your generator always used /Ox switch regardless of which radio was chosen. and i believe /Ox corresponds to 'Default' optimization on the online generator. whereas /O1 and /O2 are for size and speed respectively (but in some cases, those switches over-optimize for me and result in non working code)

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010

RSeding, are you sure the optimization switches are correct in your offline generator? when i tried to use your offline generator the /O switches were broken, i mentioned it in a post here:
http://www.autohotke...mcode/?p=572690

if i remember correctly, your generator always used /Ox switch regardless of which radio was chosen. and i believe /Ox corresponds to 'Default' optimization on the online generator. whereas /O1 and /O2 are for size and speed respectively (but in some cases, those switches over-optimize for me and result in non working code)

 

Yeah I used the default optimization for the online one as well as the offline one.



guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011
what i'm saying is that the optimizations for the offline one were broken iirc

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010

what i'm saying is that the optimizations for the offline one were broken iirc

 

It's hardcoded to default "/Ox". It's still not the same as the online one when set to default (/Ox).



guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011
if you try /O1 or /O2 do they match?