我使用汇编程序dll编写程序,并试图从汇编程序添加函数到我的c#程序,它将从c#返回字符串中的字符数量。c#汇编程序dll
C#程序:
[DllImport("bibliotekaASM.dll", CallingConvention = CallingConvention.StdCall)]
private static extern int zlicz(string tab);
private void button4_Click(object sender, EventArgs e)
{
int pom=0;
string tab = "1111111fdgsdgdgd";
pom = zlicz(tab);
}
和我的汇编代码:
myprocedure proc
push ebp
mov ebp, esp
mov ebx, [ebp+8] ; begin of char array
xor eax, eax
check:
cmp byte ptr[ebx],0 ; if end of array
je endprocedure
inc ebx
inc eax
jmp check
endprocedure:
pop ebp
ret
myprocedure endp
,但它仅适用于字符串超过100个元素例如7元这个程序有错误而崩溃:
在GUI.exe中发生未处理的“System.ExecutionEngineException”类型异常
有人可以帮助我解决这个问题,因为我想使用少于100个元素的字符串。
坦率地说,我不知道它是如何工作在*所有*。您的组合代码似乎期待C字符串(以空字符结尾的ASCII字节数组),而不是C#/ .Net“字符串”对象类型。看这里:https://msdn.microsoft.com/en-us/library/22e4dash.aspx – paulsm4