Jump to content

Very basic question howto use dllcall() correctly.


Recommended Posts

Hi.

I need to use a dotNET 4.8 DLL to drop one single file to a (private) cloud server. This DLL is the "interface" to use the cloud server's API

 

The Programmer of that DLL passed the following information to me, how to use his DLL:

Method:
public static string UploadZipFile(string zipFilePath, string fileName)

return values:
 - URL when upload was successful
 - error TEXT, when upload failed for any reason
   -> always starting with "ERROR", followed by the point in the code the upload failed, eg. "ERROR - Login" or "ERROR - Upload"

 

This code is giving me @error=3 due to help file this means function not found in the DLL file:

$DLL="c:\temp\fileCloud\GoepfertFileCloudLibrary.dll"
$FPFN="H:\DATEN\Bestellung-QS\2021-12-28-um-12-33-44-Uhr--Bestellung-291629--sg-WX-0061.zip"
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $FPFN = ' & $FPFN & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$FN=StringTrimLeft($FPFN,StringInStr($FPFN,"\",0,-1))
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $FN = ' & $FN & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console



$URL=DllCall($DLL,"STR","UploadZipFile","STR",$FPFN,"STR",$FN)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $URL = ' & $URL & @CRLF & '>Error code: ' & @error & @CRLF & "VarType = " & VarGetType($URL)& @CRLF) ;### Debug Console

SciTE output:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\temp\FileCloud\GoepfertFileCloudLibrary-Test.au3" /UserParams    
+>15:21:44 Starting AutoIt3Wrapper v.18.708.1148.0 SciTE v.4.1.0.0   Keyboard:00000407  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0407)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\admin.AD\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\admin.AD\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\temp\FileCloud\GoepfertFileCloudLibrary-Test.au3
+>15:21:44 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\temp\FileCloud\GoepfertFileCloudLibrary-Test.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
@@ Debug(4) : $FPFN = H:\DATEN\Bestellung-QS\2021-12-28-um-12-33-44-Uhr--Bestellung-291629--sg-WX-0061.zip
>Error code: 0
@@ Debug(6) : $FN = 2021-12-28-um-12-33-44-Uhr--Bestellung-291629--sg-WX-0061.zip
>Error code: 0
@@ Debug(11) : $URL = 0
>Error code: 3
VarType = Int32
+>15:21:44 AutoIt3.exe ended.rc:0
+>15:21:44 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.7231

 

 

I've found this topic on DotNet and downloaded the DotNet.7z, for DotNet_Start() I don't get any errors, the results are the same:

#include "dotnet.au3"



$DLL="c:\temp\fileCloud\GoepfertFileCloudLibrary.dll"
$FPFN="H:\DATEN\Bestellung-QS\2021-12-28-um-12-33-44-Uhr--Bestellung-291629--sg-WX-0061.zip"
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $FPFN = ' & $FPFN & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$FN=StringTrimLeft($FPFN,StringInStr($FPFN,"\",0,-1))
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $FN = ' & $FN & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console


 DotNet_Start()
 if @error Then
     MsgBox(0, '', "DotNet_Start Error = " & @error)
     Else
    $URL=DllCall($DLL,"STR","UploadZipFile","STR",$FPFN,"STR",$FN)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $URL = ' & $URL & @CRLF & '>Error code: ' & @error & @CRLF & "VarType = " & VarGetType($URL)& @CRLF) ;### Debug Console
EndIf
>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\temp\FileCloud\GoepfertFileCloudLibrary-Test.au3" /UserParams    
+>15:34:11 Starting AutoIt3Wrapper v.18.708.1148.0 SciTE v.4.1.0.0   Keyboard:00000407  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0407)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\admin.AD\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\admin.AD\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\temp\FileCloud\GoepfertFileCloudLibrary-Test.au3
+>15:34:11 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\temp\FileCloud\GoepfertFileCloudLibrary-Test.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
@@ Debug(7) : $FPFN = H:\DATEN\Bestellung-QS\2021-12-28-um-12-33-44-Uhr--Bestellung-291629--sg-WX-0061.zip
>Error code: 0
@@ Debug(9) : $FN = 2021-12-28-um-12-33-44-Uhr--Bestellung-291629--sg-WX-0061.zip
>Error code: 0
@@ Debug(17) : $URL = 0
>Error code: 3
VarType = Int32
+>15:34:11 AutoIt3.exe ended.rc:0
+>15:34:11 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.7513

What do I miss?

 

Any suggestions appreciated,

 

Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

You are absolutely right -- unfortunately  😕

The 7zip archive also has several example scripts -- well, that's (currently) faaaaar beyond my skills using objects.

 

.\Examples\1) DotNet_Start\1) DotNet_Start().au3
.\Examples\1) DotNet_Start\2) DotNet_Start( 'v2.0.50727' ).au3
.\Examples\1) DotNet_Start\3) DotNet_Start( 'v3.0' ) - Error.au3
.\Examples\1) DotNet_Start\4) DotNet_Start( 'x' ) - Error.au3
.\Examples\2) DotNet_StartDomain\1) DotNet_StartDomain.au3
.\Examples\2) DotNet_StartDomain\2) DotNet_StartDomain (compile me).au3
.\Examples\2) DotNet_StartDomain\3) DotNet_StartDomain.au3
.\Examples\3) DotNet_StopDomain\1) DotNet_StopDomain.au3
.\Examples\4) DotNet_LoadAssembly\1) DotNet_LoadAssembly (default domain).au3
.\Examples\4) DotNet_LoadAssembly\2) DotNet_LoadAssembly (compile me).au3
.\Examples\4) DotNet_LoadAssembly\3) DotNet_LoadAssembly (user domain).au3
.\Examples\5) DotNet_LoadCScode\1) DotNet_LoadCScode.au3
.\Examples\5) DotNet_LoadCScode\2) DotNet_LoadCScode (assembly error).au3
.\Examples\5) DotNet_LoadCScode\3) DotNet_LoadCScode (C# syntax error).au3
.\Examples\6) DotNet_LoadVBcode\1) DotNet_LoadVBcode.au3
.\Examples\6) DotNet_LoadVBcode\2) DotNet_LoadVBcode (method error).au3
.\Examples\7) DotNet_CreateObject\1) DotNet_CreateObject.au3

Propably I'll beg for an EXE wrapper that will pass the required parameters to that particular DLL 🙈

Even though I didn't make use of calling DLLs so far, I came across DLLCALL() in the help file a few times and expected, that "a dll is a dll is a dll"  -- well, obviously that's not true.

 

It's quite surprising to me, that DotNet DLLs are that hard to use

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Hello @abberration

thanks for your reply. Corona took me down for the last week, so sorry for the late reply.

The Nirsoft DLL Export viewer simply doesn't present anything, when opening that DLL.

 

I'll get in touch with the DLL's programmer to ask for further details. (that's not a public available DLL, I'll ask, if I may PM a download link to you...)

CU, Rudi.

 

 

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

@abberration

Back at my desk today I contacted the programmer of this DOTnet 4.8 DLL and he presented me, how he get's the DLL presented, when he makes use of it in a Visual Studio C# procect:

image.png.3ef4558756ecda9753c0482bc5d7c799.png

 

This is the autocomplete dialog, when selecting "functions" within the DLL:

 

image.png.df176096f603109357bd1e62e8229890.png

 

a "blank" DLL (all URL / U / P content taken out) is attached to this posting.

 

He also was so kind to check quite a lot of other self coded DOTnet 4.8 DLLs with Nirsoft DLL export viewer and told me, that this tool is presenting a "blank result" for all of them.

Any suggestions appreciated, that might help to make use of especially this (and in future other DOTnet 4.8 DLLs) of this type.

 

Regards, Rudi.

 

 

Goepfert.FileCloudLibrary.dll

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

To use DllCall() correctly, be aware of the following: The AutoIt DllCall() function can only be used to execute functions in dll-files implemented in unmanaged languages such as C, C++ and Pascal. The DllCall() function cannot be used to execute functions in .NET assembly dll-files implemented in managed languages such as C#, F# or VB.NET.

Note that this isn't an AutoIt limitation or a limitation in the DllCall() function. It's a very general limitation when trying to mix any unmanaged programming language with managed code. AutoIt is an unmanaged programming language.

Fortunately, there are methods to integrate unmanaged and managed code. This also applies to AutoIt and C# code.

With an AutoIt background, the DotNetAll.au3 UDF as implemented in Using C# and VB.NET Code is by far the easiest way to execute C# (or VB.NET) code directly within an AutoIt script.

With this technique you have eg. no need for a C# (or VB.NET) IDE, but can handle all code in SciTE. See bottom of this post for a complete list of the benefits of the technique.

But this method works best if the C# (or VB.NET) code only depends on internal .NET assembly dll-files or relatively simple external .NET assembly dll-files.

In your case it seems to be a slightly more advanced external .NET assembly dll-file. To be sure to get the code working in AutoIt, use the technique briefly demonstrated in this post.

This method requires an IDE to compile the C# code into a .NET assembly dll-file and it requires the dll-file to be registered with RegAsm.exe.

Why is more C# code needed when a .NET assembly dll file already exists and contains the actual UploadZipFile() method?

In your case with the UploadZipFile() method, it is necessary to add a bit more C# code to use the method in AutoIt. The problem is that UploadZipFile() is a static method, and a static method cannot be executed in AutoIt.

In the C# code, you must include the .NET assembly dll file and you must write a small wrapper method that works in AutoIt. The wrapper method must be a simple public method as shown in the example in the link and the method must of course call the static UploadZipFile() method.

Depending on your experience with AutoIt objects and C# code, getting the code to work isn't necessarily a completely trivial task.

Link to comment
Share on other sites

@LarsJ

 

Thank you really very much for your detailed explanations on .NET DLL constraints! 👏:graduated:👍

 

I'll go through the content you pointed out for learning purposes.

 

To get this problem solved fast, I will ask the DLL programmer to write for me a C# EXE that will work as a wrapper, to forward the two required command line parameters to the DLL, and to return the result (the download URL string / EXITCODE) to my script.

 

<cite>

Depending on your experience with AutoIt objects and C# code, getting the code to work isn't necessarily a completely trivial task.

</cite>

Well, currently I believe this is far beyond my skills regarding objects and C# 🙄

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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...