Hola que tal, aqui de nuevo solictando su apoyo para lo siguiente:
Estoy intentando crear una DLL con Vb6.0 y utilizarla en c#.net. Pero me topo con el siguiente problema al utilizar funciones API, el mensaje de error al utilizar el dll en C# es la siguiente:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Código utilizado:
Código:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
[System.Runtime.InteropServices.DllImport("Prueba.dll")]
private static extern double Suma(double n1, double n2);
[DllImport("Prueba.dll", CharSet = CharSet.Unicode)]
private static extern string Saludo();
[System.Runtime.InteropServices.DllImport("Prueba.dll")]
private static extern long ActiveWindows();
[STAThread]
static void Main(string[] args)
{
double n1, n2;
n1 = 23.45;
n2 = 748.125;
double n3 = Suma(n1, n2);
long handle = ActiveWindows();
Console.WriteLine("La suma de {0} + {1} = {2}", n1, n2, n3);
string s = Saludo();
Console.WriteLine("s.Length = {0}", s.Length);
Console.WriteLine("'{0}'", s);
Console.Write("\nPulsa INTRO para terminar ");
Console.ReadLine();
}
}
}
codigo vb6.0 para la dll
Código:
Option Explicit
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Function Saludo() As String
Saludo = "Hola desde la DLL Prueba"
End Function
Public Function Suma(ByVal n1 As Double, ByVal n2 As Double) As Double
Suma = n1 + n2
End Function
Public Function ActiveWindows() As Long
ActiveWindows = GetDesktopWindow
End Function
Las funciones saludos() y Suma, funcionan correctamente.
Fuente:
Crear una DLL
Saludos!! De antemano gracias por su apoyo.