how can i utilize unmanaged delphi7 Dll in C# dot net  
Author Message
Sivanageswar





PostPosted: .NET Base Class Library, how can i utilize unmanaged delphi7 Dll in C# dot net Top

hi,

 i am using a delphi7 dll in C# dotnet ,  the delphi7 dll returns datatype of Tdataset ,

i am assigning the return dataset to dotnet dataset, but at the time of running the application i am

getting an error message of "

Attempted to read or write protected memory. This is often an indication that other memory is corrupt " 

The C# dot net code is

using System;

using System.Collections.Generic;

using System.Data;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

using System.Runtime.InteropServices;

namespace Test

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

[DllImport("D:\\Testing21\\Dllofre\\query.dll")]

private void button1_Click(object sender, EventArgs e)

{

DataSet dts = new DataSet();

dts = GetRecords("ConnectionString", "TableName");

dataGridView1.DataSource= dts;

 

}

}

}

The Delphi Dll is:

function DBConnect(str : Ansistring): boolean;
 begin
   try
     DBCOn := TADOConnection.Create(Nil);
     with DBCOn do
     begin
       Close;
       ConnectionString := Str;
       LoginPrompt := False;
       Open;
       DBConnect := True;
     end;
   except;
     DBConnect := False;
   end;
 end;

 function GetRecords(ConnStr :AnsiString;  TabName : string):TADOQuery ;
 var
  TmpResult : TADoQuery;
  QuryStr : String;
 begin
   if ConnStr = '' then
    ConnStr := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=dbadmin;'+
               'Password=dbadmin;Initial Catalog=R7_29Sep_Lat;Data Source=MIM-SERVER-02'
   else
    ConnStr := ConnStr;
   DBConnect(ConnStr);
       Try
        begin
          TmpResult := TADOQuery.Create(Nil);
          QuryStr := 'SELECT * FROM '+TabName;
          with TmpResult do
          begin
            Connection := DBCOn;
            SQL.Clear ;
            SQL.Add(QuryStr);
            Open;
            Result := TmpResult;
          end;
         end;
       except;
        GetRecords := Nil;
       end;
 end;

 how can i rectify the memory corrupt error while using the delphi7 dll in C# dotnet , it's my project requirement to consume the existed delphi7 dll in C# dotnet

Thanks,

Sivanageswar 




.NET Development26  
 
 
Mattias Sjogren





PostPosted: .NET Base Class Library, how can i utilize unmanaged delphi7 Dll in C# dot net Top

I know very little about Delphi and nothing about the TDataset type, but I'm pretty sure you can't just assign it to a .NET DataSet like that. They are completely different types and you'll have to do the conversion work yourself.

Functions exported from DLLs to be consumed by other programming languages should generally restrict their interfaces to simple types and structures, and not directly return platform or language specific types such as TDataset.