943,907 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3049
  • C++ RSS
Oct 31st, 2008
0

Problem in loading VC++ Win32 dll in C#

Expand Post »
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);
C++ Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
asifjavaid is offline Offline
40 posts
since Oct 2006
Oct 31st, 2008
0

Re: Problem in loading VC++ Win32 dll in C#

c++ Syntax (Toggle Plain Text)
  1.  
  2. //...maybe this impl. can help
  3.  
  4. [DllImport("./MXFWrapperMarvel.dll", EntryPoint = "add")]
  5. static extern int APIENTRY add(int a, int b);
  6. //...
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Having trouble with a else... else if loop (For a class)
Next Thread in C++ Forum Timeline: A problem with classes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC