VB.NET ERR: 0x8007000B (Bad Image Format Exception) -
__declspec(dllexport) void __cdecl memcopy(void *pdst, const void *psrc, unsigned int nsize) { __asm { mov esi, psrc mov edi, pdst mov ecx, nsize $l1: movq mm7, [esi] add esi, 8 movq [edi], mm7 add edi, 8 dec ecx jne $l1 }; }
this code copyblit8x8.dll
i imported .dll c++ console application , copied string 'hello world' char * a, char * b. echoed b succesfully showing 'hello world'.
then, generic memory copy routine accepts 2 pointers perform copy, did below;
the picture said post title ~ bad image format exception. err code: 0x8007000b.
this generic error little information applies variety of scenarios. but, can safely assume, pointers.
what want fast asm module perform generic memory copies,but vb.net images.
any tips, stack overflow!
a badimageformatexception thrown when try load assembly or dll compiled under different bitness application. instance if try load 32-bit dll in 64-bit application (or vice versa).
make sure dll compiled in same bitness application. if application compiled anycpu
either force x86
or x64
, or compile 2 dlls using each bitness, import each function (but different names) , call correct 1 after checking environment.is64bitprocess
property.
this example of anycpu
solution:
'32-bit dll <dllimport("copyblit8x8.dll")> _ public shared function memcopy(<insert parameters here>) end function '64-bit dll <dllimport("copyblit8x8_x64.dll")> _ public shared function memcopy64(<insert parameters here>) end function public sub dostuff() if environment.is64bitprocess = true memcopy64(...) 'call 64-bit dll else memcopy(...) 'call 32-bit dll end if end sub
edit:
according hans passant, asm mmx instructions can't used in x64, solution above not work you. i'm leaving there because works dlls compiled using native c/c++ code.
Comments
Post a Comment