|
Hi folks,
I am relatively new to c++. Currently I am trying my best to create a MS Word document out of my c++ program. I found a few tutorials on Word automation which gave me good initial results (like opening a document, writing plain text, saving documents etc).
However, my goal is to insert more complex things like a table of content, headlines, footers and so on and I couldn't find any usable information about that.
Therefor I have 2 questions:
1. Is office automation really the best way to achieve such a goal? (the official Microsoft support page seems a little outdated on that topic).
2. Most articles I found are about MS Excel. Unfortunately, I need to work with MS Word. Can somebody point me towards a comprehensive c++ -> MS Word article?
Thanks for your time & help
|
|
|
|
|
|
Thank you! Those were the tutorials I used so far. They recommend to use the macro codes in MS Word to find the desired functions. However, I have trouble converting the macro code in c++.
For example: To create a headline, the makro shows this code:
Sub Makro()
Selection.Style = ActiveDocument.Styles("Überschrift 1")
End Sub
("Überschrift 1" means "Headline 1").
Any ideas?
|
|
|
|
|
I'm not sure I understand what you're aiming to accomplish.
If you want to write a C++ program that constructs a Word program, the first response might besomewhat helpful.
If you want to produce a Word dcument that contains your program code with some added formatting a table of contents, and maybe some useful internal links, you might want to take a look at Doxygen: Main Page[^]
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
When breaked at debugging, I can press F10, line by line to view the current execution of the source code. Suppose my program has 1000 lines of code,
I don't want to press F10 1000 times to watch all the 1000 line in the order of execution.
I wish output whole 1000 lines of code in execution order.
surce code like below:
id fun(int* piVal)
{
*piVal = 0;
}
main()
{
int iTemp = 0;
fun();
iTemp = 1;
}
I need a text file after running the program. The contents of the file are like below:
int iTemp = 0;
*piVal = 0;
iTemp = 1;
text file has 3 line, It exact save the three lines of execution.
|
|
|
|
|
Member 13081369 wrote: I need a text file after running the program. The contents of the file are like below:
int iTemp = 0;
*piVal = 0;
iTemp = 1;
text file has 3 line, It exact save the three lines of execution.
And what are you going to do with such an output?
|
|
|
|
|
If the code like below:
if(iVal < 10)
{
FunA();
}
else
{
FunB();
}
When first run, iVal=1. So the first.txt Should be:
if(iVal < 10)
FunA();
And second run, iVal=20. The second.txt Should be:
if(iVal < 10)
FunB();
I could compared two file(first.txt and second.txt) to find code execution difference.
I need it, because my codes very very larged. when iVal differeced every times, the differece appeard at after hundreds lines between first.txt and second.txt.
|
|
|
|
|
It's hard to understand your question. I think there are many better ways of solving the problem which might include restructuring the program, especially to make that section into smaller modules or to create your own debugging interface and pass parameters through it so you have a functional means of tracking program states. If you could tighten up input validation and narrow the scope of acceptable input it may help detect bugs.
The way you want to do it printing code is not even remotely a standard functionality or common practice so it is a very oversized foot you are trying to shoehorn into a small shoe and the result will likely be as comfortable.
If you want to pursue it anyway it's hard to imagine without knowing your code. You could set up a custom table of watch variables and or expressions and use the stringizing operator in a macro, similar to an assert() style.
#define record_str (a) (fprintf(debug, "%s : %s", #a, a))
#define record_int(a) (fprintf(debug, "%s : %s", #a, itoa(a)))
Combine it with __LINE__ and or FILE or TIME
C/C++ line number - Stack Overflow[^]
Hope this helps
|
|
|
|
|
|
You can try using "run to cursor" to see if that helps.
|
|
|
|
|
Thanks, I known how to "using run to cursor",but the problem is I need to pressed F10 button hundreds, for execution whole program.
I need to view "execution whole program line by line" exacts
|
|
|
|
|
Well good luck, but I don't think you are going to find it.
|
|
|
|
|
Neither 'Run to cursor' nor 'step over' (F10) are suitable functions for your problems. Either set a breakpoint within the code of the right if/else branch, or set a data breakpoint that stops execution the moment iVal changes its value: How to: Set a Data Breakpoint (Native Only) | Microsoft Docs[^]
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
A line by line code execution logger doesn't make any sense. The sheer amount of data that would produce for any kind of meaningful program will swiftly exceed any storage capacity that you can throw at it. Not to mention that it would increase computation time by a factor of 100-1000 due to the required IO operations.
Much better you learn to use the debugger: simply place a break point at the branch(es) you're interested in and let the debugger run until it hits one of your break points.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Thanks,but I sure "
A line by line code execution logger does make sense for me
I have very large storage capacity, and I can wait for long time to output.
|
|
|
|
|
No it doesn't. You don't understand what you're asking for. Even if it would kind of work out for the very simple program you are looking at right now, it won't help you beyond that: the next time you're trying to understand some code, it won't be good enough, and you will eventually realize that you wasted a lot of time with a tool that, in the end, doesn't really help.
Please take the advice from people who have spent decades on programming and using tools. The debugger is the second tool I learned to use after the editor, and it is still the most helpful tool I use today. Without it, large scale applications wouldn't be possible, and smaller ones would cost orders of magnitude more money and time to develop.
With a debugger you can do the inspection you're asking for at runtime, and a lot more. You won't need to write one yourself, nyou won't have to wait for it's output to be written, and you won't waste ludicrous amouunts of storage space. It's better in any way you can think of.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Member 13081369 wrote: I don't want to press F10 1000 times to watch all the 1000 line in the order of execution. Have you considered setting a breakpoint (that only breaks when a condition is met)?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Or a watchpoint that only triggers when a variable changes value? Otherwise, go through and add printf() or cout at "interesting" points. You should be able to wrap those in #ifdef _DEBUG macros so you don't have to pull them out in Release version. A really smart cookie might figure out how to use variadic marcros, #ifdefs, etc so you could do something like
int main()
{
DEBUG_LOG("starting main\n");
int i = 0, j = 0;
DEBUG_LOG("i = %d, j = %d\n");
int n = foo(i,j);
DEBUG_LOG("foo(%d,%d) returned %d\n", i, j, n);
DEBUG_LOG("main exits\n");
}
If you're using straight C, then vprintf() might help. C++ might need the use of variadic templaytes (C++11 and later - see c++ - How to make a variadic macro for std::cout? - Stack Overflow
|
|
|
|
|
Perhaps you meant this reply for the OP?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Thanks, but I want to find a way that don't add any code like DEBUG_LOG(), to print source code.
because the source code too many. I wouldn't be do this otherwise.
|
|
|
|
|
This response shows that you have really no understanding of what a debugger does, and how to use it. A debugger does not require you to add anything to your code at all. There's no need for a debugger to print code, nor to add any code to your program.
You really should read this up before continuing to refuse the only sensible advice any experienced programmer can offer you on this problem: Debugger - Wikipedia[^]
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
The problem is I don't know where are the "condition is met".
Whether input's iVal is 1 or 2, first hundreds line code execution are equals. I want to find first diffence between 1 and 2 (iVal), and I sured the diffence appeared after "execution long line codes ago".
|
|
|
|
|
Hi,
You could use the Debug Interface Access SDK to get the exact line of 'source code' associated with any instruction offset in the executable. This is how WinDbg and Visual Studio knows where the line of source code is located.
Using your sample:
main()
{
int iTemp = 0; __asm int 3
fun()
iTemp = 1
}
Then add an exception hander for STATUS_BREAKPOINT (0x80000003) and call into DIA and pass the exception offset to get the source line.
It's actually quite simple.
However if you are looking to perform instrumentation at the instruction level then have a look at DynamoRIO and specifically the instrace_x86 sample.
Best Wishes,
-David Delaune
|
|
|
|
|
Using your method, I need add “__asm int 3;” for every line of code?
|
|
|
|
|
Member 13081369 wrote: Using your method, I need add “__asm int 3;” for every line of code?
No,
You could set the hardware breakpoints at DR0-DR7 and automate every single-step through your entire program printing out each line of source code as it is executed by querying the PDB file associated with the executable via DIA.
What you are asking is absolutely possible but it's a lot of work. Are you sure that you need to do this?
Best Wishes,
-David Delaune
|
|
|
|