我有一个用 VB5 编写的旧程序。这个程序调用一个用 c++ 编写的 DLL。我想从 VB5 转换为 C#。这是原始代码:
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>
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>
这是我在 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);
}
我应该收到:
在“ppeso”中我应该收到一个数字(例如:195)
在“pcant”中我应该收到一个数字(例如:8)
在“rasgos”中我应该收到一个字符串(例如:MA;170|MI;195|AI; 190|A;210|
目前我收到此错误:
System.BadImageFormatException: 'Se ha intentado cargar un programa con un formato wrongo. (Excepción de HRESULT: 0x8007000B)' (英文:尝试加载格式错误(不正确)的程序)