Sign in to follow this  
Followers 0
tmakruck

.NET DLL Call Trouble

5 posts in this topic

I have a DLL I created in Microsoft's Visual Studio .NET 2003, called DBInsert.dll

I am trying to use AutoIt's DLLCall () to run one of the func's in the .dll

Here's my simple autoIt Code

$dll = DLLOpen ( "D:\Automation\DBInsert\DBInsert\bin\Release\DBInsert.dll" )
If $dll = -1 then
    MsgBox ( 16 , "AutoIt" , "DLL Open Failed" )
    exit
endIf

$XMLFile = "C:\Documents and Settings\tmakruck\Desktop\04-28-2006 1-26PM.xml"
$Return = DLLCall ( $dll , "str" , "UpdateDatabase" , "str" , $XMLFile )
If @Error then 
    MsgBox ( 16 , "AutoIt" , "DLL Call Failed with Error level " & @Error )
    exit
EndIf

msgbox(0, "", $result[0])  ; Record Number (Returned from UpdateDatabase)
msgbox(0, "", $result[1])  ; Should return the filename in XMLFile

the AutoIt Code runs down to the MsgBox ( 16 , "AutoIt" , "DLL Call Failed with Error level " & @Error ) then exits, as it should since I apparently am not calling the func in the dll correctly.

The reason I'm using the dll, rather than trying to ObjCreate ("ADODB.Connection" ) and continuing on with autoIt commands from there, is that I currently have a .NET GUI that makes a call to that dll and it works fine, and has been for over a year. Currently, AutoIt drives that GUI app.

Now that I finally got approval from the powers that be (management) to use the beta, I figured it should be an easy plug and play solution to just DLLCall the same function in AutoIt.

Here's basically what the func in the dll looks like, in C# code. I've taken some of our code out for your readability, but there should still be enough for you to get the gist

// DBInsert.cs -> Compiled to DBInsert.dll
using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
namespace LaptopConfig
{
  // Trust Me This Code Works. I've been using it for a year.
  public class DatabaseControls
  {
    // Below is the func I'm Calling. UpdateDatabase, with one String Parameter. This is a complete path and filename.
    public static string UpdateDatabase (string xdocName)
    {
      XmlDocument xdoc = new XmlDocument();
      xdoc.Load(xdocName);
      
      string connectionString = "Data Source=SCCLAB14;Initial Catalog=Automation;User ID=LaptopConfig;Password=autotest";
      SqlConnection conn = new SqlConnection(connectionString);
      conn.Open();
      SqlTransaction    tran = conn.BeginTransaction();
      try
      {
        string projectName = xdoc.SelectSingleNode("/FullReport/MachineSummary/projectname").InnerText;
        string appName = xdoc.SelectSingleNode("/FullReport/MachineSummary/testname").InnerText;
        string machineName = xdoc.SelectSingleNode("/FullReport/MachineSummary/machinename").InnerText;
        string testDuration = xdoc.SelectSingleNode("/FullReport/MachineSummary/duration").InnerText;
        string testResult = xdoc.SelectSingleNode("/FullReport/MachineSummary/finalresult").InnerText;
        string testSteps = xdoc.SelectSingleNode("/FullReport/MachineSummary/automatedsteps").InnerText;
        string testDateTime = xdoc.SelectSingleNode("/FullReport/MachineSummary/testdatetime").InnerText;
        string testStepsFailed = xdoc.SelectSingleNode("/FullReport/MachineSummary/numstepsfailed").InnerText;
        string testerID = xdoc.SelectSingleNode("/FullReport/MachineSummary/testerid").InnerText;
        string ClaimNumber = xdoc.SelectSingleNode("/FullReport/MachineSummary/claimnumber").InnerText;
        string PullDuration = xdoc.SelectSingleNode("/FullReport/MachineSummary/pullduration").InnerText;//.InnerText;
        if (PullDuration==null) PullDuration = "";
        string sql = "INSERT INTO dtLaptopTestSummary "
          +"(ProjectName, ApplicationName, MachineName, TestDateTime, "
          +"TestResult, TestDuration, TestSteps, TestStepsFailed, "
          +"TesterID, ClaimNumber, PullDuration) "
          +"values "
          +"(@ProjectName, @AppName, @MachineName, @TestDateTime, "
          +"@TestResult, @TestDuration, @TestSteps, @TestStepsFailed, "
          +"@TesterID, @ClaimNumber, @PullDuration)"
          +"; SELECT @@IDENTITY";
        SqlCommand cmd = new SqlCommand(sql, conn, tran);
        // Use cmd2.Parameters.Add(....) to finish building the SQL. TRUST ME IT WORKS with my .NET GUI
        // continue making parameters for all @'s
        //cmd.ExecuteNonQuery();
        int testId = decimal.ToInt32((decimal)cmd.ExecuteScalar());
        
        foreach (XmlNode detailNode in xdoc.SelectNodes("/FullReport/teststeps/Record"))
        {
          string conditionNumber = detailNode.SelectSingleNode("tcnumber").InnerText;
          string conditionAction = detailNode.SelectSingleNode("action").InnerText;
          string conditionResult = detailNode.SelectSingleNode("result").InnerText;
          string conditionResultDetail = detailNode.SelectSingleNode("description").InnerText;
          
          // get the other sub nodes
          string sql2 = "insert into dtLaptopTestDetail (TestID, ConditionNumber, ConditionAction, ConditionResult, ConditionResultDetail) values (@TestID, @ConditionNumber, @ConditionAction, @ConditionResult, @ConditionResultDetail)";
          SqlCommand cmd2 = new SqlCommand(sql2, conn, tran);
          // Use cmd2.Parameters.Add(....) to finish building the SQL. TRUST ME IT WORKS with my .NET GUI
          // continue making parameters for all @'s
          cmd2.ExecuteNonQuery();
        }
        tran.Commit();
        conn.Close();
        return testId.ToString();
      }
      catch (Exception e)
      {
        tran.Rollback();
        conn.Close();
        return (e.Message + Environment.NewLine + e.StackTrace);
      }
    }
  }
}

Thanks!

Todd

Share this post


Link to post
Share on other sites



I don't know if this will fix or help you with your problem, but this is what I found when I created a .Net control for use with the ObjCreate AutoIt function:

.Net does not support COM, unless special COM classes are added in, or a COM compatible project is created. Search through the MSDN help for COM and you will find more info. I found it easier to create a new project with built in COM support.

I still could not get .Net events to work with the control, so I created a VB6 control that acted as a wrapper for the .Net control. This way I cound pass through the data easily. Not the best solution, but it worked.

Hope this helps somewhat. I did this about 6 months ago, so it is a bit faded from my memory now.

Checkout the Debugger link in my sig for that actual VB6/.Net/AutoIt project that I worked on. The source is on my website.


“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

I don't know if this will fix or help you with your problem, but this is what I found when I created a .Net control for use with the ObjCreate AutoIt function:

.Net does not support COM, unless special COM classes are added in, or a COM compatible project is created. Search through the MSDN help for COM and you will find more info. I found it easier to create a new project with built in COM support.

I still could not get .Net events to work with the control, so I created a VB6 control that acted as a wrapper for the .Net control. This way I cound pass through the data easily. Not the best solution, but it worked.

Hope this helps somewhat. I did this about 6 months ago, so it is a bit faded from my memory now.

Checkout the Debugger link in my sig for that actual VB6/.Net/AutoIt project that I worked on. The source is on my website.

i'd love to see your sorce, but i'm getting a 404 not found when i click the link in your other post...

Share this post


Link to post
Share on other sites

i'd love to see your sorce, but i'm getting a 404 not found when i click the link in your other post...

Try it now. Changed web hosts and it appears that it is now case sensitive!


“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

Try it now. Changed web hosts and it appears that it is now case sensitive!

Grrr @ Corporate Download Blocking of ZIP files, executables, etc..! I'll have to look at it at home.

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  
Followers 0