View Single Post
Join Date: Oct 2006
Posts: 38
Reputation: asifjavaid is an unknown quantity at this point 
Solved Threads: 0
asifjavaid asifjavaid is offline Offline
Light Poster

Problem in loading VC++ Win32 dll in C#

 
0
  #1
Oct 31st, 2008
Hi sir,


I am making a win32 dll in VC++.NET 2005. I make an add funtion in it and then i call it from C# using System.Runtime.InteropServices;

[DllImport("MXFWrapperMarvel.dll", EntryPoint = "add")]
static extern int add(int a, int b);
  1. ----------------------MXFWrapperMarvel.dll------------without header files---------------
  2. #include "stdafx.h"
  3. #include <AtlConv.h>
  4.  
  5. #ifdef _MANAGED
  6. #pragma managed(push, off)
  7. #endif
  8.  
  9. extern "C" __declspec(dllexport) int APIENTRY add(int a, int b)
  10. {
  11. return a+b;
  12. }
  13.  
  14.  
  15. BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  16. {
  17. return TRUE;
  18. }
  19.  
  20. #ifdef _MANAGED
  21. #pragma managed(pop)
  22. #endif
  23. -------------------------------------------------------------------------------------------------
  24.  
  25. this add function working correctly.
  26.  
  27.  
  28. But I want to include some header files of third party SDK.
  29.  
  30. ---------------------MXFWrapperMarvel.dll-------------with header files-------------------
  31.  
  32. #include "stdafx.h"
  33. #include <AtlConv.h>
  34.  
  35.  
  36. #include "MOG/MXFComponents/EssenceAnalyzer/MPEG/EssenceTypes.h"
  37. #include "MOG/MXFComponents/EssenceAnalyzer/AES3/EssenceTypes.h"
  38. #include "MOG/MXFComponents/EssenceAnalyzer/BWave/EssenceTypes.h"
  39. #include "MOG/MXFComponents/EssenceAnalyzer/AES3/S302M/EssenceTypes.h"
  40.  
  41. #ifdef _MANAGED
  42. #pragma managed(push, off)
  43. #endif
  44.  
  45. extern "C" __declspec(dllexport) int APIENTRY add(int a, int b)
  46. {
  47. return a+b;
  48. }
  49.  
  50.  
  51. BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  52. {
  53. return TRUE;
  54. }
  55.  
  56. #ifdef _MANAGED
  57. #pragma managed(pop)
  58. #endif
  59.  
  60. --------------------------------------------------------------------------------------------------
My code is compiled successfully, no errors and warnings. But when calling the add() function then, a runtime exception is raising while calling add() fuction...

"Unable to load DLL 'MXFWrapperMarvel.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

The dll is also placed on the right path but still raising exception. If I remove the above header files from dll code then my code also compiled successfully as well as add() function is also functioning correctly. But after just including those header files in dll code, it is compiled successfully but raised the above exception at runtime while calling add() function and my code jumps to the catch block .

Please guide me how can I resolve this problem.

--
Regards,
Asif
Reply With Quote