Convert a call to old DLL from vb5 to c# - System.BadImageFormatException


I have an old program writed in VB5. This program call a DLL writed in c++. I want to made conversion from VB5 to C#. This is the original code:

Declaration in VB5:

Option Explicit <br>
Private Declare Sub GENRAS _ <br>
  Lib "C:\WINNT\system\genras32.dll" _ <br>
  (ByVal pmarca_de_input As String, _ <br>
  pcant_rasgo As Long, _ <br>
  ppeso_rasgo As Long, _ <br>
  ByVal ptab_rasgos As String) <br>

The call in VB5:

Private Sub Command1_Click() <br>
Dim pmarca_de_input As String * 201 <br>
Dim pcant_rasgo As Long <br>
Dim ppeso_rasgo As Long <br>
Dim ptab_rasgos As String * 1400 <br> 
Dim sPeso As String <br>
Dim sRasgo As String <br>
Dim sBuffer As String <br>
Dim i As Integer <br>
ptab_rasgos = String(Len(ptab_rasgos), Chr(0)) <br>
pmarca_de_input = UCase(Text1.Text) <br>
Call GENRAS(pmarca_de_input, pcant_rasgo, ppeso_rasgo, ptab_rasgos) <br>

This is the conversion I tried in c#

[DllImport(@"C:\Users\Victor Herrera\Documents\visual studio 2017\Projects\Test_1_genras\Test_1_genras\genras32.dll", CharSet = CharSet.Unicode)]
public static extern void GENRAS(string pmarca_de_input,ref long  pcant_rasgo,ref long ppeso_rasgo,ref string ptab_rasgos);

private void button1_Click(object sender, EventArgs e)
        long pcant_rasgo=0;
        long ppeso_rasgo=0;
        string rasgos = "";
        GENRAS("maria",ref pcant_rasgo,ref ppeso_rasgo,ref rasgos);

I should receive:

In "ppeso" I should receive a number (example: 195)
In "pcant" I should receive a number (example: 8)
In "rasgos" I should receive a string (example: MA;170|MI;195|AI;190|A;210|

Currently I receive this error:

System.BadImageFormatException: 'Se ha intentado cargar un programa con un formato incorrecto. (Excepci├│n de HRESULT: 0x8007000B)' (In english: Try to load a program with a bad (incorrect) format)

asked on Stack Overflow Dec 12, 2017 by VictorHerrera • edited Dec 13, 2017 by DaveInCaz

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0