PC Review


Reply
Thread Tools Rate Thread

Access Violation calling C++ dll method

 
 
sklett
Guest
Posts: n/a
 
      25th Feb 2007
I've create a simple MFC dll to wrap some more complex C++ code that was
supplied to me. I want to call the methods in my MFC wrapper dll from my C#
app.

I have a very simple case where this problem happens.

Here is the C++ code:
Code:
class CBTPreviewLibApp : public CWinApp

{

public:

CBTPreviewLibApp();




virtual BOOL InitInstance();



__declspec(dllexport) HANDLE GetPreview();



DECLARE_MESSAGE_MAP()

};



__declspec(dllexport) HANDLE CBTPreviewLibApp::GetPreview()

{

return (HANDLE)9;

}


Here is the c# code:
Code:
[DllImport("BTPreviewLib.dll")]

public static extern int GetPreview();



try

{

int handle = GetPreview();

}

catch(Exception ee)

{

Console.WriteLine(e.ToString());

}
The code executes without any errors, but when I exit the c# application I
get the following error:
---------------------------
BTPreviewDemo.vshost.exe - Application Error
---------------------------
The instruction at "0x045d2c00" referenced memory at "0x04a82290". The
memory could not be "read".


I have no idea what could be causing this, I'm not *doing* anything in the
DLL with this function call, just returning 9. I've never tried to call
unmanaged code from C# before, so this is all very new. I'm also unable to
step into the call to GetPreview() even though both the C++ dll and c#
WinForms app are in the same solution.

Anyone have any ideas for me? Anything I can try? I have checked the
exports of the MFC dll and the names aren't mangled (I'm using a DEF file)

Thanks for any help or suggestions,
Steve






 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CLI and calling the base method from the derived method DaTurk Microsoft VC .NET 2 11th Jul 2007 11:29 PM
Calling Web Services from a Web Form throws CAS violation =?Utf-8?B?anVjaHl0aWw=?= Microsoft Dot NET Framework Forms 1 25th Apr 2005 02:29 PM
calling a Access Outputto method from VB6 and passing a filter =?Utf-8?B?amVmZg==?= Microsoft Access VBA Modules 1 7th Jan 2005 03:02 AM
Re: Access Violation when calling unmanaged C++ from managed C++ S. Han Microsoft VC .NET 6 30th Apr 2004 09:29 AM
Calling protected method from interface that doesn't include method Jon Shemitz Microsoft C# .NET 2 25th Nov 2003 11:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:43 PM.