Simple MCode returns null? [BUMP]*reposted Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Simple MCode returns null? [BUMP]*reposted

29 Dec 2018, 12:27

OP was 4 days old...hence the repost/bump.

It's all in the title, i get the feeling it's something to do with my use of a pointer,because even if i bring up the return to before where there's a pointer it returns null,but returns properly if i comment out the pointer & all below it... using https://github.com/joedf/MCode4GCC
Thanks for any insight. :xmas:

Code: Select all

/*
//works fine here...
#include <stdio.h>
#include <time.h>
int main()
{
    printf("%d\n", myLBfunc());

}
*/

/*
#include <time.h>
int myLBfunc()
{
  time_t rawtime;
  struct tm * timeinfo;
  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  int    sec = timeinfo->tm_sec;   //seconds [0,61]
  int    min = timeinfo->tm_min;   //minutes [0,59]
  int    hour = timeinfo->tm_hour;  //hour [0,23]
  int    mday = timeinfo->tm_mday;  //day of month [1,31]
  int    month = timeinfo->tm_mon;   //month of year [0,11]
  int    year = timeinfo->tm_year;  //years since 1900
  int    dweek = timeinfo->tm_wday;  //day of week [0,6] (Sunday = 0)
  int    dyear = timeinfo->tm_yday;  //day of year [0,365]

  if (min % 2 == 0 && sec > 5 && sec < 55){    //if minute is even and second is within specified range... only then return stored value...
    return 123456789;    //decimal encoded password example....
  };
    return -1;
}
*/
;should return something....... but does not....
Msgbox % DllCall(MCode("2,x86:U4PsKI1cJByJHCToAAAAAIkcJOgAAAAA9kAEAYsQdRWD6gaD+jEZwCUWzVsHg+gBg8QoW8O4/////+v0kJCQkA=="),"cdecl UInt64")

dt := "Str,AStr,WStr,Int64,Int,Short,Char,Float,Double,Ptr"		; suffix := "*,P", prefix := "U"
For i,type in StrSplit(dt,",")	;'automated' type checking...
	If ( thisRet := DllCall(MCode("2,x86:U4PsKI1cJByJHCToAAAAAIkcJOgAAAAA9kAEAYsQdRWD6gaD+jEZwCUWzVsHg+gBg8QoW8O4/////+v0kJCQkA=="),"cdecl " type "") )
		Msgbox % thisRet "`n`n" type

MCode(mcode) {
	static e := {1:4, 2:1}, c := (A_PtrSize=8) ? "x64" : "x86"
	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)
}
live ? long & prosper : regards
User avatar
nnnik
Posts: 4475
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Simple MCode returns null? [BUMP]*reposted

29 Dec 2018, 13:02

Yeah it would be good if you read the MCode tutorial I made a while back https://www.autohotkey.com/boards/viewt ... p?f=7&t=32
It should show you why your code won't work the way you are currently writing it.

Also try to check A_LastError.
Recommends AHK Studio
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: Simple MCode returns null? [BUMP]*reposted

29 Dec 2018, 15:02

nnnik wrote:
29 Dec 2018, 13:02
Yeah it would be good if you read the MCode tutorial I made a while back https://www.autohotkey.com/boards/viewt ... p?f=7&t=32
It should show you why your code won't work the way you are currently writing it.

Also try to check A_LastError.

I've read it & yea, i know i need to use pointers for the return value.... I was just a little confused as to whether i was making some stupid mistake or i just needed to do what was suggested in the tutorial... It's too simple a function,... I'll do it that way anyhow, i just wanted to know where the fault lay.

Cheers.
live ? long & prosper : regards
User avatar
nnnik
Posts: 4475
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Simple MCode returns null? [BUMP]*reposted  Topic is solved

30 Dec 2018, 06:08

The issue lies in calling external functions.
Like I said you cannot use functions or includes inside your MCode.
Recommends AHK Studio
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: Simple MCode returns null? [BUMP]*reposted

30 Dec 2018, 08:20

I somehow glossed over that, cheers.
live ? long & prosper : regards

Return to “Ask For Help”

Who is online

Users browsing this forum: c7aesa7r, Google [Bot], mcl, svArtist, TheProdigyC2, WOlfen, zKade and 54 guests