Jump to content
Sign in to follow this  
basel1998

using dllcall

Recommended Posts

basel1998

hello

ive tried to use this autoit code

$dll = @ScriptDir & "\dll.dll"
MsgBox(64,"dll",$dll)
$one = dllcall($dll,"str","Test","test","teeest")
MsgBox(64,"dll",$one)

but its always returning 0

dll written in vb.net

Public Class Test
    Public Function test(ByVal Value1 As String)
        MsgBox(Value1, MsgBoxStyle.AbortRetryIgnore, "test")
        Return "Test"
    End Function
End Class

Share this post


Link to post
Share on other sites
Starstar

What is your purpose?  Describe it a bit more......


Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
basel1998

What is your purpose?  Describe it a bit more......

i want to run function using dllcall

and the dll is compiled in vs2010

Share this post


Link to post
Share on other sites
trancexx

You should read documentation for DllCall function. You will see that @error is set in case of failure. Based on that value you can then see why you got 0.

DllCall is function for advanced users, so if you aren't one the problems you experience are very much expected.

Are you experienced with VB at least? Is your function really exported function?


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Mobius

Hi basel1998,

$one = dllcall($dll,"str","test","str","teeest")

IF @ERROR THEN

MsgBox(16,"dll",@ERROR)

ELSE

MsgBox(64,"dll",$one[0])

ENDIF

Typed on my phone so sorry if incorrect.

The return value from dllcall is an array, as mentioned you should check @Error after the call.

The name of the dll function is case sensitive, so Test is not the same as test, plus you put the string test where you should have declared the function parameter type as str.

Vlad

Share this post


Link to post
Share on other sites
basel1998

and

$one = dllcall($dll,"str","test","str","teeest")

returns 2

same vb.net code

Edited by basel1998

Share this post


Link to post
Share on other sites
basel1998

Come now thats easy if you read the manual or even what I posted.

The error value 3 means the function name was not found, why?

Because you are still using an uppercase T in the function name when the exported function in vb is test.

 

$dll = @ScriptDir & "\86.dll"
MsgBox(64,"dll",$dll)
$one = dllcall($dll,"str","test","str","teeest")
IF @ERROR THEN
MsgBox(16,"dll",@ERROR)
ELSE
MsgBox(64,"dll",$one[0])
ENDIF

still gives 3

Share this post


Link to post
Share on other sites
Viktor1703

libraries created by means of VB.NET and C# aren't dynamically connected and are used only in NET Framework similar languages, for this purpose it is necessary to edit dll and edit dll

Edited by Viktor1703

Share this post


Link to post
Share on other sites
basel1998

libraries created by means of VB.NET and C# aren't dynamically connected and are used only in NET Framework similar languages, for this purpose it is necessary to edit dll and edit dll

thanks its working now

Edited by basel1998

Share this post


Link to post
Share on other sites
basel1998

and now does not returning any error but also not running

Imports System.IO
Public Class Test
    Public Function MyTest(ByVal Value1 As String)
        MkDir("C:\realygoooooooooooooooood")
        Return "Test"
    End Function
End Class

not macking dir and not completing au3 script

Edited by basel1998

Share this post


Link to post
Share on other sites
Viktor1703

Imports System.IO
Public Class Test
    Public Function MyTestForYou(ByVal Value1 As String) As String
        MkDir("C:\realygoooooooooooooooood") ' Demand the administrator in AutoIt a script!???
        Return "Test"
    End Function
End Class

Edited by Viktor1703

Share this post


Link to post
Share on other sites
basel1998
Imports System.IO
Public Class Test
    Public Function MyTestForYou(ByVal Value1 As String) As String
        MkDir("C:\realygoooooooooooooooood") ' Demand the administrator in AutoIt a script!???
        Return "Test"
    End Function
End Class

yes

#RequireAdmin
$dll = @ScriptDir & "\Test.dll"
MsgBox(64,"dll",$dll)
$one = dllcall($dll,"str","MyTest","str","teeest")
IF @ERROR THEN
MsgBox(16,"dll",@ERROR)
ELSE
MsgBox(64,"dll",$one[0])
ENDIF
Edited by basel1998

Share this post


Link to post
Share on other sites
Viktor1703

You correctly edited an IL code of your Dll?

Share this post


Link to post
Share on other sites
basel1998

You correctly edited an IL code of your Dll?

yes

Share this post


Link to post
Share on other sites
Viktor1703

Really doesn't work, I can only advise to write on something another as this option extremely not reliable and will work under control of NET Framework if it isn't present, Dll won't be started

For an example

Pure С
C++
Delphi
PureBasic
etc.
 

It seems I made, for me works (Windows 8 x64)

Code C#
 

using System.IO;

public class Test
{
    public static string MyTestForYou(string Value1)
    {
        Directory.CreateDirectory("C:\\realygoooooooooooooooood");
        return "Test";
    }
}

IL code Dll

//  Microsoft (R) .NET Framework IL Disassembler.  Version 4.0.30319.1




// Metadata version: v2.0.50727
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 2:0:0:0
}
.assembly Test
{
  .custom instance void [mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01 00 04 54 65 73 74 00 00 )                      // ...Test..
  .custom instance void [mscorlib]System.Reflection.AssemblyDescriptionAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Reflection.AssemblyProductAttribute::.ctor(string) = ( 01 00 04 54 65 73 74 00 00 )                      // ...Test..
  .custom instance void [mscorlib]System.Reflection.AssemblyCopyrightAttribute::.ctor(string) = ( 01 00 12 43 6F 70 79 72 69 67 68 74 20 C2 A9 20   // ...Copyright .. 
                                                                                                  20 32 30 31 34 00 00 )                            //  2014..
  .custom instance void [mscorlib]System.Reflection.AssemblyTrademarkAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Runtime.InteropServices.ComVisibleAttribute::.ctor(bool) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 34 30 62 30 33 35 62 62 2D 32 63 38 30   // ..$40b035bb-2c80
                                                                                                  2D 34 30 37 62 2D 38 63 66 36 2D 63 66 38 64 32   // -407b-8cf6-cf8d2
                                                                                                  34 37 31 31 65 38 34 00 00 )                      // 4711e84..
  .custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 31 2E 30 2E 30 2E 30 00 00 )             // ...1.0.0.0..

  // --- ‘«Ґ¤гойЁ© ­ бва Ёў Ґ¬л©  ваЁЎгв ¤®Ў ў«Ґ­  ўв®¬ вЁзҐбЄЁ, ­Ґ б«Ґ¤гҐв ®в¬Ґ­пвм ЇаҐ®Ўа §®ў ­ЁҐ ў Є®¬¬Ґ­в аЁ© -------
  //  .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) 

  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx
                                                                                                             63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.
  .hash algorithm 0x00008004
  .ver 1:0:0:0
}
.module Test.dll
// MVID: {2DE6A6E5-507A-4D0B-B56F-59E6CDE17752}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000002    //  ILONLY
// Image base: 0x02830000
.vtfixup [1] int32 fromunmanaged at VT_01
.data VT_01 = int32(0)

// =============== CLASS MEMBERS DECLARATION ===================

.class public auto ansi beforefieldinit Test extends [mscorlib]System.Object
{
  .method public hidebysig static string MyTestForYou(string Value1) cil managed
  {
    // ђ §¬Ґа Є®¤ :       22 (0x16)
    .vtentry 1 : 1
    .export [1] as MyTestForYou
    .maxstack  1
    .locals init ([0] string CS$1$0000)
    IL_0000:  nop
    IL_0001:  ldstr      "C:\\realygoooooooooooooooood"
    IL_0006:  call       class [mscorlib]System.IO.DirectoryInfo [mscorlib]System.IO.Directory::CreateDirectory(string)
    IL_000b:  pop
    IL_000c:  ldstr      "Test"
    IL_0011:  stloc.0
    IL_0012:  br.s       IL_0014

    IL_0014:  ldloc.0
    IL_0015:  ret
  } // end of method Test::MyTestForYou

  .method public hidebysig specialname rtspecialname 
          instance void  .ctor() cil managed
  {
    // ђ §¬Ґа Є®¤ :       7 (0x7)
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
    IL_0006:  ret
  } // end of method Test::.ctor

} // end of class Test


// =============================================================

// *********** „€‡Ђ‘‘…ЊЃ‹€ђЋ‚ЂЌ€… ‡Ђ‚…ђ…ЌЋ ***********************
// ‚Ќ€ЊЂЌ€…: ᮧ¤ ­ д ©« аҐбгаб®ў Win32 Test.res

AutoIt Code
 

#RequireAdmin

$sDll = @ScriptDir & "\Test.dll"

$sRet = DllCall($sDll, 'str', 'MyTestForYou', 'str', 'teeest')
If @error Then
    MsgBox(16, 'Dll', @error)
Else
    MsgBox(0, 'Result', $sRet[0])
EndIf

Try to compile it

Imports System.IO
Public Class Test
    Public Shared Function MyTestForYou(ByVal Value1 As String) As String
        MkDir("C:\realygoooooooooooooooood")
        Return "Test"
    End Function
End Class
Edited by Viktor1703

Share this post


Link to post
Share on other sites
basel1998

Really doesn't work, I can only advise to write on something another as this option extremely not reliable and will work under control of NET Framework if it isn't present, Dll won't be started

For an example

Pure С

C++

Delphi

PureBasic

etc.

 

nothing to make dll work???

Share this post


Link to post
Share on other sites
basel1998

 

Really doesn't work, I can only advise to write on something another as this option extremely not reliable and will work under control of NET Framework if it isn't present, Dll won't be started

For an example

Pure С

C++

Delphi

PureBasic

etc.

 

It seems I made, for me works (Windows 8 x64)

Code C#

 

using System.IO;

public class Test
{
    public static string MyTestForYou(string Value1)
    {
        Directory.CreateDirectory("C:\\realygoooooooooooooooood");
        return "Test";
    }
}

IL code Dll

//  Microsoft (R) .NET Framework IL Disassembler.  Version 4.0.30319.1




// Metadata version: v2.0.50727
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 2:0:0:0
}
.assembly Test
{
  .custom instance void [mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01 00 04 54 65 73 74 00 00 )                      // ...Test..
  .custom instance void [mscorlib]System.Reflection.AssemblyDescriptionAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Reflection.AssemblyProductAttribute::.ctor(string) = ( 01 00 04 54 65 73 74 00 00 )                      // ...Test..
  .custom instance void [mscorlib]System.Reflection.AssemblyCopyrightAttribute::.ctor(string) = ( 01 00 12 43 6F 70 79 72 69 67 68 74 20 C2 A9 20   // ...Copyright .. 
                                                                                                  20 32 30 31 34 00 00 )                            //  2014..
  .custom instance void [mscorlib]System.Reflection.AssemblyTrademarkAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Runtime.InteropServices.ComVisibleAttribute::.ctor(bool) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 34 30 62 30 33 35 62 62 2D 32 63 38 30   // ..$40b035bb-2c80
                                                                                                  2D 34 30 37 62 2D 38 63 66 36 2D 63 66 38 64 32   // -407b-8cf6-cf8d2
                                                                                                  34 37 31 31 65 38 34 00 00 )                      // 4711e84..
  .custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 31 2E 30 2E 30 2E 30 00 00 )             // ...1.0.0.0..

  // --- ‘«Ґ¤гойЁ© ­ бва Ёў Ґ¬л©  ваЁЎгв ¤®Ў ў«Ґ­  ўв®¬ вЁзҐбЄЁ, ­Ґ б«Ґ¤гҐв ®в¬Ґ­пвм ЇаҐ®Ўа §®ў ­ЁҐ ў Є®¬¬Ґ­в аЁ© -------
  //  .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) 

  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx
                                                                                                             63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.
  .hash algorithm 0x00008004
  .ver 1:0:0:0
}
.module Test.dll
// MVID: {2DE6A6E5-507A-4D0B-B56F-59E6CDE17752}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000002    //  ILONLY
// Image base: 0x02830000
.vtfixup [1] int32 fromunmanaged at VT_01
.data VT_01 = int32(0)

// =============== CLASS MEMBERS DECLARATION ===================

.class public auto ansi beforefieldinit Test extends [mscorlib]System.Object
{
  .method public hidebysig static string MyTestForYou(string Value1) cil managed
  {
    // ђ §¬Ґа Є®¤ :       22 (0x16)
    .vtentry 1 : 1
    .export [1] as MyTestForYou
    .maxstack  1
    .locals init ([0] string CS$1$0000)
    IL_0000:  nop
    IL_0001:  ldstr      "C:\\realygoooooooooooooooood"
    IL_0006:  call       class [mscorlib]System.IO.DirectoryInfo [mscorlib]System.IO.Directory::CreateDirectory(string)
    IL_000b:  pop
    IL_000c:  ldstr      "Test"
    IL_0011:  stloc.0
    IL_0012:  br.s       IL_0014

    IL_0014:  ldloc.0
    IL_0015:  ret
  } // end of method Test::MyTestForYou

  .method public hidebysig specialname rtspecialname 
          instance void  .ctor() cil managed
  {
    // ђ §¬Ґа Є®¤ :       7 (0x7)
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
    IL_0006:  ret
  } // end of method Test::.ctor

} // end of class Test


// =============================================================

// *********** „€‡Ђ‘‘…ЊЃ‹€ђЋ‚ЂЌ€… ‡Ђ‚…ђ…ЌЋ ***********************
// ‚Ќ€ЊЂЌ€…: ᮧ¤ ­ д ©« аҐбгаб®ў Win32 Test.res

AutoIt Code

 

#RequireAdmin

$sDll = @ScriptDir & "\Test.dll"

$sRet = DllCall($sDll, 'str', 'MyTestForYou', 'str', 'teeest')
If @error Then
    MsgBox(16, 'Dll', @error)
Else
    MsgBox(0, 'Result', $sRet[0])
EndIf

Try to compile it

Imports System.IO
Public Class Test
    Public Shared Function MyTestForYou(ByVal Value1 As String) As String
        MkDir("C:\realygoooooooooooooooood")
        Return "Test"
    End Function
End Class

thanks it works

maybe the problem with vb.net itself

and here is convernter

http://converter.telerik.com/

Edited by basel1998

Share this post


Link to post
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
Sign in to follow this  

×