RSS Forums RSS

Problem in loading VC++ Win32 dll in C#

Please support our C++ advertiser: Programming Forums
Reply
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#

  #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);
----------------------MXFWrapperMarvel.dll------------without header files---------------
#include "stdafx.h"
#include <AtlConv.h>

#ifdef _MANAGED
#pragma managed(push, off)
#endif

extern "C" __declspec(dllexport) int APIENTRY add(int a, int b)
{
    return a+b;
}


BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    return TRUE;
}

#ifdef _MANAGED
#pragma managed(pop)
#endif
-------------------------------------------------------------------------------------------------

this add function working correctly.


But I want to include some header files of third party SDK.

---------------------MXFWrapperMarvel.dll-------------with header files-------------------

#include "stdafx.h"
#include <AtlConv.h>


#include "MOG/MXFComponents/EssenceAnalyzer/MPEG/EssenceTypes.h"
#include "MOG/MXFComponents/EssenceAnalyzer/AES3/EssenceTypes.h"
#include "MOG/MXFComponents/EssenceAnalyzer/BWave/EssenceTypes.h"
#include "MOG/MXFComponents/EssenceAnalyzer/AES3/S302M/EssenceTypes.h"

#ifdef _MANAGED
#pragma managed(push, off)
#endif

extern "C" __declspec(dllexport) int APIENTRY add(int a, int b)
{
    return a+b;
}


BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    return TRUE;
}

#ifdef _MANAGED
#pragma managed(pop)
#endif

--------------------------------------------------------------------------------------------------
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
AddThis Social Bookmark Button
Reply With Quote  
Posts: 314
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 61
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

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

  #2  
Oct 31st, 2008
  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. //...
  7.  
.:-cikara21-:.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C++ Forum
Views: 1210 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:30 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC