C++ Hello World + Debugging with Visual Studio

Thomas wrote on 7/29/2008, 12:00 PM
Hi vegas scripting newbies,

thought it could be a good idea to share this brief Hello World C++ sample. While I found some samples for C#, I failed to find some for C++ or Visual C++ in particular. Nevertheless, Visual C++ was the only environment capable of attaching the running vegas process to get into debugging in its free version. So, I worried a bit with my abilities...
and here is the sample.

Have fun,
Thomas


************ IMPLEMENTATION ************

launch Visual C++ 2008 Express Edition
File -> New Project
- Template: class library
- Name: VegasCppHelloWorld

Project -> Properties
- new reference to Sony.Vegas (on the file system search tab to be choosen from within Vegas install folder: sony.vegas.dll)
- new reference to System.Windows.Forms (on the .NET tab)

Replace the template body of VegasCppHelloWorld.h with:

// VegasCppHelloWorld.h

#pragma once

using namespace System::Windows::Forms;
using namespace Sony::Vegas;

public ref class EntryPoint
{
public:
void FromVegas(Vegas vegas) {

MessageBox::Show("hello world");
}
};


Hit F7 (make)

create a link from the VegasCppHelloWorld.dll and store it in the vegas Script Menu folder
launch vegas and execute the dll
:-)

************ DEBUGGING ************
Extras (english wording?) -> Attach Process
- select vegas70.exe

set a breakpoint on the MessageBox call

run the script

debugger stops at the breakpoint
:-)

Comments

Bob Denny wrote on 8/7/2008, 2:58 PM
The free version of Visual Studio and C# doesn't have debugging? I thought it did (I have the full VS2005). If it does, you can do the same thing within C# by enabling unmanaged debugging and attaching the Vegas process as you described (very useful hint, thanks for that!).
Thomas wrote on 8/8/2008, 1:31 PM
Bob: from the free versions only Visual Studio C++ 2008 allows for attaching (the vegas) process. Cost me quite some time to find out ;-). Neither VB nor VC# supports attaching.
Bob Denny wrote on 8/8/2008, 8:06 PM
Oh, OK. I didn't know. Thanks for the tip!
Teetow wrote on 8/9/2008, 12:43 PM
By the way, you can start Vegas from VS directly, which will attach the debugger for you. Just input the path to vegas80.exe in the Project Properties >> Configuration Properties >> Debugging >> Command field.

You'll find this is easier once you get into developing CustomCommands, which require a restart of Vegas to be reloaded. You might also wanna switch Debugger Type to "Managed Only," since you're not actually debugging Vegas itself.

Now, every time you press F5, your scripts will build and Vegas will launch. This usually goes well together with having Vegas load a small testing project on startup, as well as adding -SCRIPT:"myscript.dll" to its Command Arguments in the property page I mentioned above. Note that there is no space between -SCRIPT: and the path, this is to not confuse Vegas into trying to load the dll as a project file.
Bob Denny wrote on 8/12/2008, 1:38 PM
That's a useful trick, but then you have to wait for Vegas to start each time. By attaching and detaching, you can leave Vegas running (unless you crash it with some bug in your extension, ha ha).
Teetow wrote on 8/18/2008, 10:25 AM
Well, it starts in under a second so I can't say that has been an issue. Your mileage may vary, of course.

Also, like I said, custom commands have to be reloaded at startup so you can in fact not leave Vegas running.