General C++ Capability Question

Grab your favourite IDE and tinker with the innards of game engines

General C++ Capability Question

Postby Enraged on Fri Mar 04, 2011 6:37 pm

So I've been programming in C++ for years now but I've never created a program that operated outside of itself without a fully functional API to go through. Now I'm wondering if there is a way to do so, and incase you're confused I'll give you an example.

I have an excel spreadsheet with 5000+ entries in a single column. Each entry is on it's own row. I want to make a program that will copy the contents of the cell into the program, modify the copied mateiral and then paste it back into the program. Lastly it will go down a column and then repeat this on loop.

Now I know that there is an API to do this with Microsoft Excel. This is just an example. I just want to know if there is a way for a C++ program to perform the actions in any program. I have assumed there is since macros have been a constant burden in online games, but I don't know how to do it.

Thanks for reading.
Enraged
Regular
Regular
 
Joined: Fri Jul 25, 2008 9:13 pm

Re: General C++ Capability Question

Postby cheesemoo0 on Fri Mar 04, 2011 8:01 pm

Sure you can do this. I'm not a C++ programmer, but I know you have to use a parser to get the data into a form you can use and then write it back into the excel format once done doing what have you.
User avatar
cheesemoo0
Been Here A While
Been Here A While
 
Joined: Tue Jun 17, 2008 2:38 am
Location: USA

Re: General C++ Capability Question

Postby zombie@computer on Fri Mar 04, 2011 8:16 pm

Not quite sure what you want to do, but lemme give you some random statements about the subject.

1) You can call cpp methods that are exposed in dlls from excel, just link the dll in vba and call the methods.
2) You are better off using dotNet for office related stuff, since office is fully integrated into that. I'm not quite sure how advanced the cpp ->office apis are, but its quite likely these run through managed code somewhere anyway.
In fact, even though cpp is a very cool language, from time to time much fun because its more powerful than a speeding locomotive, c# is waay more advanced, and faster to code as well (plus very similar in sintax, so easy to move over to). Unless you are working on tight corners (eg VERY high performance requirement, C-only environment (eg CUDA) I'd evade c++ like that smelly old man that always digs through the garbage bins at the shopping mall. In fact, even if part of your code is c++, i would advise you to simply generate a c++ api/dll out of that existing code and move over to c#. Of course other languages are possible too, but some are either ridiculously limited or niche'd in their use, while others are limited in their IDE's. I find that dotNet (but also Java) offes basically everything a programmer needs, allowing him to forget about memory management and other ancient terms and focus on the logics themselves.

3) Interaction of proggy a to b:
a) inject into primary messageloop (sendmessage)
b) memory manipulation. Personally ive no experience with this, but as long as you've got some kind of handle to sneak into the other program you can control it entirely. This usually means spitting through tons of documents and/or decompile the other program into assembly (isnt life fun? ..No). Chuck Norris could do it easy, I cant.
c) Copy/pasting through windows ? eg S/GetClipboardData ? Excel by default copies to and from comma seperated values afaik.
d) Easier to do than b, but also something i've never tried: Direct interaction with the form controls. You should be able to simulate any input the user gives with his mouse, mousebuttons and keyboard using a combination of this and a). I suspect it to be rather buggy though.
e) Console programs can be controlled completely using the standardinput stream

edit: and yeah, you can also directly edit the excel files of course.
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: General C++ Capability Question

Postby Unreal_Me on Fri Mar 04, 2011 8:25 pm

cheesemoo0 wrote:Sure you can do this. I'm not a C++ programmer, but I know you have to use a parser to get the data into a form you can use and then write it back into the excel format once done doing what have you.


I think he meant more towards doing it live in the program, as in copy, edit, paste, rather than open, edit, save.

Modifying live data within a program is probably not the best/easiest of things, but it's probably possible.
IIRC, the Win32 API has calls to manage clipboard data. With enough research you could probably get something that works (though from the little that I did, it's a bitch to do. effing global memory and such).

Alternatively, you might be able to get into the really dirty areas of managing memory directly. If you can figure out where/how excel (or whatever program) stores things in memory, you can probably manipulate it assuming windows doesn't shout at you.
However this is mostly theory based on the little bit that I know about C++, as I've never actually done something like this before.

Also a note to above, I think office 2007 onwards uses XML instead of CSV now.
Idk, look it up
User avatar
Unreal_Me
Regular
Regular
 
Joined: Fri Aug 14, 2009 4:14 am
Location: The middle of nowhere, the center of everywhere

Re: General C++ Capability Question

Postby Shrinker on Sat Mar 05, 2011 10:02 pm

C# is not very advanced. C# does not allow to inherit from multiple base classes at once :(
User avatar
Shrinker
Been Here A While
Been Here A While
 
Joined: Fri Nov 09, 2007 5:52 pm
Location: Germany

Re: General C++ Capability Question

Postby hekar on Sun Mar 06, 2011 3:57 am

You can perform this with Dynamic Data Exchange. You can talk directly with Excel without bindings etc. (You can alternatively talk with Excel through COM, but that's another story.)

C++ does not provide operating system specific tasks and cross process communicates is operating system specific. Windows will have a different set of APIs/mechanisms from Linux, Mac, FreeBSD, etc.

That's an example for Excel:
http://support.microsoft.com/kb/279721

If you want to send keyboard/mouse presses, there are lots of programs to do that. You can also send events directly to the window. With FindWindow, SendMessage, etc.

Checkout MSDN for more API calls (Windows has a lot of stuff in its core)
hekar
Dumpling
Dumpling
 
Joined: Thu Dec 09, 2010 2:04 am

Re: General C++ Capability Question

Postby Shrinker on Sun Mar 06, 2011 8:13 am

For faking input events, AHK is nice: http://www.autohotkey.com/
User avatar
Shrinker
Been Here A While
Been Here A While
 
Joined: Fri Nov 09, 2007 5:52 pm
Location: Germany

Return to Programming

Who is online

Users browsing this forum: No registered users