I have a C ++ DLL that exports a method like this:
extern "C" __declspec (dllexport) void ConvE(int type, const char* path, int b1, int b2, int b3, int b4, int b5)
{
FFileList file_list;
char temp_path[1024];
if(type == 1)
{
sprintf(temp_path,"%s*",path);
GetFindFileListWin(temp_path,".mrs",file_list);
file_list.RecoveryZipE(b1, b2, b3, b4, b5);
file_list.ConvertNameMRes2Zip();
}
else if(type == 2)
{
sprintf(temp_path,"%s*",path);
GetFindFileListWin(temp_path,".zip",file_list);
file_list.ConvertZipE(b5, b4, b3, b2, b1);
file_list.ConvertNameZip2MRes();
}
}
And I call it in my C # application as follows:
[DllImport("Mrs.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern void ConvE(int type, string path, int b1, int b2, int b3, int b4, int b5);
But every time I run it, it gives me the error "Attempted to read or write protected memory. This often indicates that another memory is damaged"
As far as I read, something is wrong with the way I import the function in C #, but I really don't know how to solve it.
:
Conv(), ConvE, 5 , .
ConvE file_list.RecoveryZipE(), , RecvoeryCharE ( , ), , RecoveryChar(), Conv().
RecoveryChar:
void RecoveryChar(char* pData,int _size)
{
if(!pData) return;
BYTE b,bh,d;
for(int i=0;i<_size;i++) {
b = *pData;
bh = b&0x07;
d = (bh<<5)|(b>>3);
*pData = d ^ 0xff;
pData++;
}
}
RecvoeryCharE:
void RecoveryCharE(char* pData, int _size, int b1, int b2, int b3, int b4, int b5)
{
if(!pData) return;
BYTE b;
for(int i=0;i<_size;i++) {
b = *pData;
b = (((((b >> b1) | (b << 5)) ^ b2) + b3) ^ b4) - b5;
*pData = b;
pData++;
}
}
, #:

: ,
RecoveryCharE( _fileheaderReader , _fileheaderReaderSize, b1, b2, b3, b4, b5 );
- b1 0.
, .
, , , restoreChar() convertChar(), .