Foros del Web » Programación para mayores de 30 ;) » .NET »

Dll vb6.0 en C#.

Estas en el tema de Dll vb6.0 en C#. en el foro de .NET en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 09/12/2009, 12:27
 
Fecha de Ingreso: julio-2008
Mensajes: 116
Antigüedad: 15 años, 9 meses
Puntos: 1
Pregunta Dll vb6.0 en C#.

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.

Última edición por Aioros-jms; 09/12/2009 a las 13:09
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:25.