views:

1593

answers:

3

I have a vb project which calls functions in a dll. The dll is created in a separate vs project (portaudio), which is written in c.

The dll c project compiles clean and builds the required dll, which I am currently dropping in c:\windows\system to vb runtime can see it.

VB Project lives in c:\devprojects\vbtest

C Project lives in c:\devprojects\portaudio with the project file in c:\devprojects\portaudio\build\msvc. Dll created in Win32\debug under this msvc directory.

When I call the dll function, is it possible for the vs debugger to step through the c function in the dll - I have all the code etc, but I don't know if VS2005 supports this kind of mixed language debugging.

If this is possible, could you advise how I should set up my Visual Studio to achieve this.

Many thanks David

A: 

Create a solution with both projects, add the reference in VB project to C project using 'Add Reference..' dialog -> Project and build them all in debug mode.

How do you calls C dll from VB?

abatishchev
in vb, I declare the dll functions like this: Private Declare Function Pa_GetVersionText Lib "portaudio_x86.dll" () As Stringfor example.Is this a problem ?
WaveyDavey
Note - when I select add reference -> Project, no porjects are listed and there's no navigation buttons or [...] buttons to go hunting for it.
WaveyDavey
What is the type of C++ project? I just have created VB.NET WinApp and C++ Win32 Dll. WinApp -> Add Reference -> Project -> here I have that C++ Dll project
abatishchev
Project Properties -> Configuration Properties -> Project Defaults : Configuration Type:Dynamic Library (.dll)Use of MFC: Use Standard Windows LibrariesUse of ATL: Not using ATLDoes this help ?
WaveyDavey
Sorry! I'm wrong! The reference was added but on build I got 'The project 'CppLibrary' cannot be referenced. This is not a .NET assembly.'.
abatishchev
So, am I stuck then ? Is is impossible to debug the c function when called from the vb app ? Seems a great shame that MS can't offer this functionality - it would be hugely useful.
WaveyDavey
A: 

If its VB.NET then this is very easy, just set up a solution with both projects under it, set up their dependencies and ensure that on build the debug version of the VB project links to the debug lib/dll produced from your C++ project. Visual Studio does the rest.

I've done this before a couple of times with C# applications calling a C++ dll. I didn't intend to set this up, but tried stepping through whilst debugging assuming I would get the assembly listing and could at least work out somethig of what was going wrong with my code... however it loaded the correct .cpp file and allowed me to continue stepping through that code.

jheriko
+4  A: 

It is not necessary to have both projects in the same solution, but you should compile both projects with debug symbols enabled.

Now in your VB net solution Project/Properties, in the Debug tab make sure that "Enable unmanaged code debugging" is checked.

Also make sure that the dll loaded is in the same place where it was compiled, else it may not found the pdb where the debug symbols are stored.

Ismael
This will do it. Removing my answer.
Binary Worrier
Super - it works a charm. Not exactly sure *why*, but let's do this thing !
WaveyDavey