• Jueves 16 de Mayo de 2024, 09:41

Autor Tema:  error 49  (Leído 1401 veces)

johndoe90

  • Nuevo Miembro
  • *
  • Mensajes: 23
    • Ver Perfil
error 49
« en: Lunes 27 de Abril de 2009, 13:15 »
0
Hola, estoy intentando hacer un programa en VB a partir de una dll hecha con C++ en objetos. El programa consiste en introducir el nombre, uso de cpu y memoria de un proceso, y luego mostrarlo, todo va bien hasta que se le da a mostrar, entonces me sale el error 49: "La convencion de llamadas a DLL es incorrecta". Alguien sabria decirme donde esta el fallo?

Gracias.

Adjunto código.

CProcess.h

typedef char Tpalabra [20];

class CProcess
{
private:
   Tpalabra imageName;
   float cpuUsage;
   int memUsage;

public:
   CProcess();
   void pon_imageName(Tpalabra name);
   Tpalabra* dame_imageName();
   void pon_cpuUsage(float cpu);
   float dame_cpuUsage();
   void pon_memUsage(int mem);
   int dame_memUsage();
   float valor_inicial_cpu();
   int valor_inical_mem();
};

CProcess.cpp

#include "CProcess.h"
#include <string.h>

Tpalabra newProc;

CProcess::CProcess()
{
   strcpy(imageName,newProc);
   cpuUsage=0.0;
   memUsage=0;
}

float CProcess::valor_inicial_cpu()
{
   return cpuUsage;
}

int CProcess::valor_inical_mem()
{
   return memUsage;
}


void CProcess::pon_imageName(Tpalabra name)
{
   strcpy(imageName,name);
}

Tpalabra* CProcess::dame_imageName()
{
   return (&imageName);
}

void CProcess::pon_cpuUsage(float cpu)
{
   cpuUsage=cpu;
}

float CProcess::dame_cpuUsage()
{
   return (cpuUsage);
}

void CProcess::pon_memUsage(int mem)
{
   memUsage=mem;
}

int CProcess::dame_memUsage()
{
   return (memUsage);
}

DLLCProcess.cpp

#include "Windows.h"
#include "CProcess.h"

CProcess my_Process;

void FAR PASCAL DLLpon_imageName(Tpalabra name)
{
   my_Process.pon_imageName(name);
}

void FAR PASCAL DLLdame_imageName(Tpalabra name)
{
   strcpy(name,*my_Process.dame_imageName());
}

void FAR PASCAL DLLpon_cpuUsage(float cpu)
{
   my_Process.pon_cpuUsage(cpu);
}

float FAR PASCAL DLLdame_cpuUsage()
{
   return my_Process.dame_cpuUsage();
}

void FAR PASCAL DLLpon_memUsage(int mem)
{
   my_Process.pon_memUsage(mem);
}

int FAR PASCAL DLLdame_memUsage()
{
   return my_Process.dame_memUsage();
}


CProcess.def

LIBRARY CProcess.dll
DESCRIPTION 'Dll CProcess'
HEAPSIZE 4024

EXPORTS
      DLLpon_imageName   @1
      DLLdame_imageName  @2
      DLLpon_cpuUsage    @3
      DLLdame_cpuUsage   @4
      DLLpon_memUsage    @5
      DLLdame_memUsage   @6


VB

Form 1

Option Explicit


Private Sub Command1_Click()
Dim name As String
Dim cpu As Single
Dim mem As Long

name = "                    "
name_in.Text = name
cpu_in.Text = cpu
mem_in.Text = mem

DLLpon_imageName (name)
DLLpon_cpuUsage (cpu)
DLLpon_memUsage (mem)
MsgBox "Datos introducidos correctamente"


End Sub

Private Sub Command2_Click()
Dim palabra As String
Dim cpuUsage As Single
Dim memUsage As Long
palabra = "                  "

DLLdame_imageName palabra
DLLdame_cpuUsage cpuUsage
DLLdame_memUsage memUsage

name_out.Text = palabra
cpu_out.Text = cpuUsage
mem_out.Text = memUsage

End Sub

Module1

Option Explicit

Public Declare Function DLLpon_imageName _
Lib "CProcess.dll" _
(ByVal name As String) _
As Long

Public Declare Function DLLdame_imageName _
Lib "CProcess.dll" _
(ByVal imageName As String) _
As Long

Public Declare Function DLLpon_cpuUsage _
Lib "CProcess.dll" _
(ByVal cpu As Single) _
As Long

Public Declare Function DLLdame_cpuUsage _
Lib "CProcess.dll" _
(ByVal cpuUsage As Single) _
As Long

Public Declare Function DLLpon_memUsage _
Lib "CProcess.dll" _
(ByVal mem As Long) _
As Long

Public Declare Function DLLdame_memUsage _
Lib "CProcess.dll" _
(ByVal memUsage As Long) _
As Long



PD: Hay alguna manera de no meter un codigo tan largo en un post? Comprimirlo o algo asi?

Eternal Idol

  • Moderador
  • ******
  • Mensajes: 4696
  • Nacionalidad: ar
    • Ver Perfil
Re: error 49
« Respuesta #1 en: Lunes 27 de Abril de 2009, 13:39 »
0
Podes usar la etiqueta CODE (entre corchetes []).

Como no decis exactamente en que LINEA se produce el error te dejo ese recurso:
http://www.recursosvisualbasic.com.ar/h ... ic-c++.htm

Nacional y Popular En mi país la bandera de Eva es inmortal.


Queremos una Argentina socialmente justa, económicamente libre y  políticamente soberana.
¡Perón cumple, Evita dignifica!


La mano invisible del mercado me robo la billetera.

johndoe90

  • Nuevo Miembro
  • *
  • Mensajes: 23
    • Ver Perfil
Re: error 49
« Respuesta #2 en: Lunes 11 de Mayo de 2009, 16:26 »
0
Lo he arreglado un poco más, pero me sigue dando el mismo error, te subrayo en negrita donde me lo da

La etiqueta [CODE] donde va exactamente?

Y bueno, ya que esto es una mezcla de C++ y VB, no se si ponerlo en este foro de C++ o en el de VB, ya que el error es en VB lo postearé en el otro foro.

typedef char Tpalabra [20];

class CProcess
{
private:
   Tpalabra imageName;
   float cpuUsage;
   int memUsage;

public:
   void pon_imageName(Tpalabra name);
   Tpalabra* dame_imageName();
   void pon_cpuUsage(float cpu);
   float dame_cpuUsage();
   void pon_memUsage(int mem);
   int dame_memUsage();
   float valor_inicial_cpu();
   int valor_inical_mem();
};

#include "CProcess.h"
#include <string.h>

float CProcess::valor_inicial_cpu()
{
   return cpuUsage;
}

int CProcess::valor_inical_mem()
{
   return memUsage;
}


void CProcess::pon_imageName(Tpalabra name)
{
   strcpy(imageName,name);
}

Tpalabra* CProcess::dame_imageName()
{
   return (&imageName);
}

void CProcess::pon_cpuUsage(float cpu)
{
   cpuUsage=cpu;
}

float CProcess::dame_cpuUsage()
{
   return (cpuUsage);
}

void CProcess::pon_memUsage(int mem)
{
   memUsage=mem;
}

int CProcess::dame_memUsage()
{
   return (memUsage);
}

#include "Windows.h"
#include "CProcess.h"

CProcess my_Process;

void FAR PASCAL DLLpon_imageName(Tpalabra name)
{
   my_Process.pon_imageName(name);
}

void FAR PASCAL DLLdame_imageName(Tpalabra name)
{
   strcpy(name,*my_Process.dame_imageName());
}

void FAR PASCAL DLLpon_cpuUsage(float cpu)
{
   my_Process.pon_cpuUsage(cpu);
}

float FAR PASCAL DLLdame_cpuUsage()
{
   return my_Process.dame_cpuUsage();
}

void FAR PASCAL DLLpon_memUsage(int mem)
{
   my_Process.pon_memUsage(mem);
}

int FAR PASCAL DLLdame_memUsage()
{
   return my_Process.dame_memUsage();
}


LIBRARY CProcess.dll
DESCRIPTION 'Dll CProcess'
HEAPSIZE 4024

EXPORTS
      DLLpon_imageName   @1
      DLLdame_imageName  @2
      DLLpon_cpuUsage    @3
      DLLdame_cpuUsage   @4
      DLLpon_memUsage    @5
      DLLdame_memUsage   @6

Option Explicit


Private Sub Command1_Click()
Dim name As String
Dim cpu As Single
Dim mem As Long

name = "                    "
name_in.Text = name
cpu_in.Text = cpu
mem_in.Text = mem

DLLpon_imageName (name)
DLLpon_cpuUsage (cpu)
DLLpon_memUsage (mem)
MsgBox "Datos introducidos correctamente"


End Sub

Private Sub Command2_Click()
Dim palabra As String
Dim cpuUsage As Single
Dim memUsage As Long
palabra = "                  "

DLLdame_imageName (palabra)
DLLdame_cpuUsage (cpuUsage)
DLLdame_memUsage (memUsage)

name_out.Text = palabra
cpu_out.Text = cpuUsage
mem_out.Text = memUsage

End Sub

johndoe90

  • Nuevo Miembro
  • *
  • Mensajes: 23
    • Ver Perfil
Re: error 49
« Respuesta #3 en: Lunes 18 de Mayo de 2009, 15:52 »
0
Solucionado.