Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC++
Hi all ,
 
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 ....
 
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 :
 
extern "C" _declspec(dllexport) int extractCompressedFile( TCHAR* _szFilePath, TCHAR* _extractPath, TCHAR** _errorText )
 

Calling in C#.Net
 
IntPtr BackupDLL = NativeMethods.LoadLibrary(somepath);
IntPtr procaddr = NativeMethods.GetProcAddress(BackupDLL, "extractCompressedFile");
C_ExtractFiles 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 9-Oct-12 20:43pm
Edited 10-Oct-12 0:02am
v4
Comments
Sergey Alexandrovich Kryukov at 10-Oct-12 2:50am
   
Isn't it obvious that you provide not enough information, by far?!
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

That is a problem of Marshalling: the .Net data types need some kind of conversion for use in the C++ dll. Hence, show us the signature of the C++ function and your DllImport statement, then we will be able to provide further hints.
  Permalink  
Comments
iampradeepsharma at 10-Oct-12 4:30am
   
Now I have provided some more information ,may be would help you to guide me in some direction.
Bernhard Hiller at 10-Oct-12 5:07am
   
And the definition of C_ExtractFiles, please....
Adn why the difference between C_ExtractPxlFiles and C_ExtractFiles?

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

  Print Answers RSS
0 Kornfeld Eliyahu Peter 420
1 OriginalGriff 303
2 Yogesh Kumar Tyagi 230
3 Gihan Liyanage 99
4 sankarsan parida 90


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 10 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100