Call and Debug a C++ DLL in C#

  • Thread starter Thread starter Polaris
  • Start date Start date
P

Polaris

Any one can show me the steps to call and debug a C++ DLL inside a C#/.NET
project?

I tried using the PInvoke service with [DllImport
("C:\\Proj\\Bin\\MyCppDll.dll")] and also the prototype of the function I
like to call: public static extern int FuncFromCppDll(); but got error
message:

An unhandled exception of type 'System.EntryPointNotFoundException' occurred
in CSharpProj.exe
Additional information: Unable to find an entry point named FuncFromCppDll
in DLL C:\Proj\Bin\MyCppDll.DLL.

Any help/hint is appreciated.

TIA

PS: Once the call is successful, could I directly debug into the C++ Dll
from within the C# code? How can I inform the C# project as to where to look
for the source code of the C++ Dll?
 
If you have the source code, which you imply you do, and it can be
compiled in a project with Visual Studio .Net, then you can add the C++
project to a solution along with the C# code and be able to debug
either/both of the sets of code. I can't remember if you have to set any
switches or not, but it needs to be able to run the debugger in Native and
in Managed modes.

You can run Dumpbin /Exports on the C++ dll to examine the exported
functions to make sure you're getting what you expect.

Chris A.R.
 
1. Run your application ( no debugger attached )
2. Open the task manager ( press Ctrl+Shift+Esc )
3. Right-click the process to be debugged.
4. Choose Debug.
5. Choose the correct instance of the IDE.
6. A messgae box will popup: set the 'Native' Check-box
7. Press Attach and set your break points.
 
Back
Top