Jump to content

Use Autoit(DotNet_LoadCScode) call dll result correct but Autoit self DllCallAddress crash,need help.


konya
 Share

Recommended Posts

I have found the solution is to mix C# but I want to use pure Autoit .

 

Use Autoit  ->  DotNet_LoadCScode  call dll result correct,but I'm use Autoit  dllcall result crash,please give me some advice.

I have test as below :

Autoit -> Transfer function PTR  to C# -> DotNet_LoadCScode (CS code ) -> result correct.

Autoit -> Transfer Struct PTR  to C# -> DotNet_LoadCScode (CS code ) -> result correct.

But Autoit self execute will crash.

 

Autoit Code: (Crash)

(1)

DllCallAddress("bool" , $FunctionPTR.pfnSetParam ,"bool", true ,"word",3,"word",0,"word",0,"str","c:\" ) 

 

(2)

$tag = DllStructCreate("struct;bool a;word b;word c;word d;char e[260];endstruct")
$tag.a = True
$tag.b = 3
$tag.c = 0
$tag.d = 0
$tag.e = "c:\"

DllCallAddress("bool" , $FunctionPTR.pfnSetParam ,"ptr",DllStructGetPtr($tag) ) 

 

 

CS Code : (Result correct return)

 

Autoit call CS   $CTRL.SetParam()   

public delegate Boolean pfnSetParam(Test_PARAM Param);

public pfnSetParam m_pfnSetParam = null;

 m_pfnSetParam = (pfnSetParam)GetAddress(m_test, Function.SETPARAM, typeof(pfnSetParam));

[StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct Test_PARAM
    {
         public Boolean btest;
         public UInt16  wtesta;
         public UInt16  wtestb;
         public UInt16  wtestc;        
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 260)]
        public char[] szSaveFolder;
    }

 

public Boolean SetParam()

{

           Test_PARAM Param;

            Param.wtesta = 3;
            Param.wtestb = 0;
            Param.wtestc = 0;
            Param.btest = true;
            Param.szSaveFolder = "c:\";

m_pfnSetParam(Param);

}

Link to comment
Share on other sites

To use the DllCall or DllCallAddress functions, the header in the dll-file must be in one of the formats Portable Executable (PE) or Common Object File Format (COFF). These files are usually coded in C/C++. But that's not the case for a C# dll-file. And that's the cause of the error.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...