C功能:
int _declspec(dllexport) Compresspacket(unsigned char *buff,int offset,int len);
C#功能:
[Dllimport("HuffCompress.dll")] private static extern unsafe int HuffCompress(ref byte[] buff,int len); ... private unsafe byte[] Compresspacket(byte[] packet) { int len = HuffCompress(ref packet,12,packet.Length-12); byte[] compressed = new byte[len]; for (int i = 0; i < len; i++) compressed[i] = packet[i]; return compressed; }
什么时候
int len = HuffCompress(ref packet,packet.Length-12);
运行,我得到一个BadImageFormatException
由于C#编辑器是VSC#Express,它不能编译64位程序,所以我不确定这个问题
任何想法都会很棒
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DeBUG|Anycpu' ">
并添加此行:
<PlatformTarget>x86</PlatformTarget>
重复下面的Release配置组.
你的下一个问题是函数的名称,如果你用C编译它就会被装饰.声明如下:
extern "C" __declspec(dllexport) int __stdcall HuffCompress(unsigned char *buff,int len);
并且您的C#声明是错误的,将ref关键字放在第一个参数上.
总结以上是内存溢出为你收集整理的c# – BadImageFormatException全部内容,希望文章能够帮你解决c# – BadImageFormatException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)