Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all ,
Question has already been posted by was not with much information .
Now here the one with little more information of the problem.


I have a function in mfc(which is a dll type project) which extracts a zip file and creates folder which ultimately show up the files ,now this is used in C#.Net project so when I call this method from dll in the C#.net project not all files are extracted and shows up the error an AccessViolationExceptions occurs .

I guess this buffer which takes the extracted files there at the .net project is not able to allocate that much amount of memory..
I need advice on it ....

C++
BYTE *buffer;
buffer = new BYTE[oFileData.lActualSize];
if( buffer == 0 )
{
    _tcscpy((*_errorText), szFilesFolder.GetBuffer() );
    szFilesFolder.ReleaseBuffer();
    CoTaskMemFree((*_errorText));

    return FAILTOALLMEM;
}


SIGNATURE of the function in mfc :

C++
extern "C" _declspec(dllexport) int extractCompressedFile( TCHAR* _szFilePath, TCHAR* _extractPath, TCHAR** _errorText )


Calling in C#.Net

C#
IntPtr BackupDLL = NativeMethods.LoadLibrary(somepath);
IntPtr procaddr = NativeMethods.GetProcAddress(BackupDLL, "extractCompressedFile");
C_ExtractPxlFiles func = (C_ExtractFiles)Marshal.GetDelegateForFunctionPointer(procaddr,typeof(C_ExtractFiles));
res = func(Program.ptc_SourFilePath, ptc_DestinationFilePath, ref errtext);
Program.strResult = res.ToString();
 

 
static class ExtNativeMethods
{
    [DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
    public static extern IntPtr GetProcAddress(IntPtr hModule, [In][MarshalAsAttribute(UnmanagedType.LPStr)] string procedureName);
}
Posted
Updated 9-Oct-12 23:01pm
v2
Comments
Legor 10-Oct-12 5:02am    
You could have just updated your first question with the new information instead of posting a new one.
Richard MacCutchan 10-Oct-12 5:31am    
Not that it helps much.
Pablo Aliskevicius 10-Oct-12 8:00am    
Sounds like an ANSI/Unicode issue. I'd suggest you add a few TRACE statements at the beginning of your unmanaged methods.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900