Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 452
  • Last Modified:

simple debugging of a dll/activeX

I have some C++ code that gets compiled into an ActiveX, and run from within a larger program.  My code needs debugging - what is the best way to ouput some logging information?  Is writing to an external file the simplest approach?  How would I do this?

I tried just doing
  ¬†¬†cout << "The 'all' string: " << endl;
but got
D:\My Documents\aa Vc\ts1\CNodeView1.cpp(651) : error C2018: unknown character '0xa0'
D:\My Documents\aa Vc\ts1\CNodeView1.cpp(651) : error C2018: unknown character '0xa0'
D:\My Documents\aa Vc\ts1\CNodeView1.cpp(651) : error C2872: 'cout' : ambiguous symbol

Why these errors?  My includes are
#include "stdafx.h"
#include <iostream>
#include <list>
#include <string>
#include<vector>
#include <ctype.h>
using namespace std;

Its probably better I output to a file anyway.  Or to a console?
I am using VC++6
0
abulka
Asked:
abulka
  • 5
  • 3
  • 2
1 Solution
 
nietodCommented:
>>  My code needs debugging
You aren't at the debugging stage, your code isn't even compiling.  First you have to make it compile, then if it doesn't run right, you have to debug it.  Right now it can'be run because it doesn't compile.

in

cout << "The 'all' string: " << endl;

you can't just have a single quote inside a string.  You must palce a \ character before the quote to signal the compiler that you want a single quote to appear in the string, like

cout << "The \'all\' string: " << endl;

If that doesn't fix the problem, you need to post more of the code.
0
 
abulkaAuthor Commented:
Adjusted points from 20 to 25
0
 
abulkaAuthor Commented:
The cout << .... code was just included as a potential way of generating debug output.  The question is about the best way of doing that given my context.  I'm happy to forget about using cout << ... and get some code which deals with writing to a file, for example.

P.s. Even
  cout << "got to this point" << endl;
doesn't compile e.g.
D:\My Documents\aa Vc\ts1\CNodeView1.cpp(651) : error C2018: unknown character '0xa0'
D:\My Documents\aa Vc\ts1\CNodeView1.cpp(651) : error C2018: unknown character '0xa0'
D:\My Documents\aa Vc\ts1\CNodeView1.cpp(651) : error C2872: 'cout' : ambiguous symbol
Error executing cl.exe.

The point
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
tomkeaneCommented:
You can debug the dll directly.  Go to Project Settings->Debug tab.  In the field "Executable for debug session" put in the path to an executable that loads your dll.  The application can be any executable, it does not have to be a program you have source code to.  Set the breakpoints in your dll where you and hit F5.

HTH,

Tom
0
 
abulkaAuthor Commented:
I'd love to debug 'live' - will this above technique work when my dll is an activeX?  The main app is a delphi app which loads some activeX's which then load my VC++ active X.

0
 
tomkeaneCommented:
I can't think of any reason why it would not work.  It doesn't really matter what the exe is - as long as it loads your dll and makes calls into it.  It doesn't really matter whether it is loading your dll via implicit linking, by using LoadLibrary, or through a call to COM.

Tom
0
 
abulkaAuthor Commented:
tomkeane - it worked - unbelievable.  thanks.  Just one last question before I accept:  When I exit my app I get an exception violation/crash at some address in my dll.  The source code does not come up for me though - so I'm in the dark as to where it is crashing... Any idea on getting the debugger to show me?

thanks
0
 
tomkeaneCommented:
Hmmmmm.  Those can be tough.  The first thing I'd try would be setting breakpoints on functions in your dll that get called right at the end of its life.  For an ActiveX dll you could try any or all of the following: The Release method of your object, your COM object's destructor, your dll's DllCanUnloadNow() function, your dll's DllMain() function.
You also might want to take a look at any static or file scope objects you have, if any.
Is this something that only happens when you run it in the debugger, or does it also happen if you launch the program normally?  If it only happens in the debugger it may be that DevStudio and the Delphi runtime are disagreeing about something....

Tom
0
 
abulkaAuthor Commented:
Thanks.

By the way, I also found a way to do debug logging:

#include <iostream>
#include <fstream>

    std::ofstream  zout("e:/debuglog.txt");
    zout << "Hello, world\n";
    zout << "RectWidth is " << RectWidth << "\n";
    zout << endl;
0
 
nietodCommented:
>> I also found a way to do debug logging:
You might find that using OutputDebugString() is even better for this.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now