I don't see any connection of the code that you shared with what you have asked. There is no attempt whatsoever of dealing with the query that you posted. Also i see a lot of issues with your code as such
- You query the IDocument interface twice, and then check if the document is open or not. This will surely lead to a crash a runtime with no document open
- Secondly i see that you are trying to use JS for getting the image and wordcount, i don't get the reason why you would do so in a C++ plugin, anyhow what is the variable myDocumentAction i don't see it defined anywhere in your script
Now my question is do you want to do this in C++ or JS as you have done already(tried). If it's JS, then i would suggest to use ExtendScript of VSCode to write and debug the code first and then intgrate it into the C++ plugin once you find it working.
If it's C++ then i suggest you first brush up your C++ skills, i see no structure in code, no checks for nill pointers etc. This is disaster waiting to happen, at this point diving into SDK would only confuse you.
To complete the answer is would point you to the interfaces and boss classes that might help you do this in C++, once you are comfortable with C++ in general and basics of InDesign SDK
- Document boss class i.e. kDocBoss has an interfaces ILinksManager, that has the method GetLinkCount. This might be the one you should look at
- Text a.k.a. stories are a bit complex to handle, i am myself not too hands on with this part of the sdk. However you will have to get the storylist from kDocBoss class, then iterate over each story to get the ITextModel interface. This interface has a method QueryStrand, using which you can get the strand that represents the content of the story i.e. kTextDataStrandBoss. Beyond this you will have to investigate yourself.
I hope you put in serious effort to learn the language and sdk, this is something that takes years to understand so its surely not a cakewalk or a quickfix thing that can be resolved by just asking and copying the code.
-Manan