PDA

View Full Version : Changing allocated virtual memory allowed in MVC++


cameronlanni
08-07-2006, 08:59 AM
Does anyone know off hand how to alter the limit for "internal heap"? I am receiving this error:




fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit
Error executing cl.exe.









My other question is, is it possible to use C++ to alter text fields in a internet browser window if the browser is running at the same time as the console? If so, how can I do it?

Thanks all,
Cameron

oracleguy
08-07-2006, 05:54 PM
You filled up the heap? I've never seen somone do that before. What are you doing that is filling the heap up?

To make it bigger, you might as do what it suggests. If cl isn't the name of your program, it is probably a compiler option.

As for you second question, probably not, it would probably depend on exactly what you are trying to do. What are you trying to do?

cameronlanni
08-07-2006, 06:26 PM
First off - I am only coding a simple console program that if copied to notepad would only be about 250kb. So eiher a setting is messed up or I did something wrong, and I cant seem to alter the maximum amount of heap allocation.

Second - My second question has to do with a completely different program I am making. I manage a cingular wireless store, and we use a piece of software called "POS II" to look up customer's account, activate new phones, etc. The program is actually a website, but the problem is it is very difficult to use for my new employees. I decided to try to create a program to run along side POS II to make things easier. All would be easy if I could somehow point to various text boxes with the C++ console. For example, in POS II it asks for the customer's wireless number to look up their account. In my program, I to would ask for the wireless number, and then enter it into the box in POS II, so technically all the program would be is like a fascade for POS II. Is this possible? If not with C++, then what language could I use?

Thanks again,
Cameron

paulq
08-07-2006, 06:38 PM
First, cl.exe is Microsoft's VC++ Compiler, not a compiler option. Second, anything is possible. Yes, you could do it. No, I don't know how. I would assume that you'd be working with interprocess communication and hooks and such. Since each Windows program runs in its own virtual memory space, you might have to use some serious low level coding to alter POS II's program memory. Then again it might be as easy as just sending a WM_SETTEXT message to the edit control you wish to alter. Who knows. Sorry I am not more helpful, I haven't worked with Windows hooks since high school. My point is that it can be done, it's just a matter of difficulty and research. Good luck. If I come across anything I'll let you know.

paulq
08-07-2006, 07:01 PM
Did a little research. Haven't tried it, but it may be quite simple.

Try using the windows API FindWindow() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/findwindow.asp) to get a handle to the window that has the control you want to set the text to.

Use a "resource hacker" to find the identifier of the control you want to edit.

Use GetDlgItem() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/WindowsUserInterface/Windowing/DialogBoxes/DialogBoxReference/DialogBoxFunctions/GetDlgItem.asp) (or something similar) to get a handle to the control which you want to set the text.

Use SetWindowText() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setwindowtext.asp) to set the text.

Might be that simple. Try it on your own VC++ program first just for simplicity sake. Then give it a try on the real POS II! Let me know how it works.

cameronlanni
08-07-2006, 07:10 PM
Awesome, I'll give this a whirl and let you know.

Thank you

paulq
08-07-2006, 07:22 PM
Here, this link (http://www.codeproject.com/dll/PasswordSPY.asp) might be helpful too. This guy uses a mouseover technique to find the handle of a control. Once you have the handle you can try doing a SetWindowText on it and see how it works. Good luck and keep us posted on your progress! :thumbsup:

cameronlanni
08-07-2006, 08:11 PM
Hmmmm, I'm still having trouble referencing the browser window. I use the "PasswordSpy++" program, but still a little unsure what to do with the information after I gather it, how to implement it. Is the reference target address similar to JavaScript (document.loginForm.userName.value)? If not, how do I do it? This is what I have so far, and I'm sure it is wrong in many ways, but thanks for bearing with me:




HWND IE;
IE = FindWindowEx("Cingular Wireless", NULL, "document.loginForm.userName.value", "");
SetWindowText(IE, "Testing 1234");
IE = 0;


Thanks,
Cameron

paulq
08-07-2006, 08:27 PM
Ok, as I said before all you need to do is find the handle (HWND) to the control which you want to set the text of. First try using PasswordSpy++ to find that handle on the text box of IE. Then Copy and Paste that into your program's SetWindowText() function, just to test if that works.

For example say PasswordSpy++ says that the handle is 0x112233, then just try (while keeping that IE window open and untouched) running your program that has the SetWindowText function that looks like this:


HWND hWnd = 0x112233;
bool result = SetWindowText(hWnd, "Set this text, baby!");

If that works THEN you can use code to find the handle without manually using PasswordSpy++ like so:

1. Find the window handle using FindWindow.
2. Find the control handle using GetDlgItem(windowHandle, controlID);
3. SetWindowText(controlHandle, "Text");

document.loginForm.userName.value

Looks like a bit javascript code to me. You won't find the control handle that way. The only way I can remember how is to use a resource hacker, open the EXE in it and find the control ID and hard code that in your program.

paulq
08-07-2006, 08:36 PM
Looks like this MSDN article (http://msdn.microsoft.com/msdnmag/issues/01/08/c/) will take care of it all for you. You'd do the same as getting the text, instead you'd send a WM_SETTEXT (as I originally said in my first post) message to the program. Good luck!

cameronlanni
08-07-2006, 08:38 PM
In simply coding: (0x80242 is the Handle)


HWND hWnd = 0x80242;
bool result = SetWindowText(hWnd, "Set this text, baby!");



I get these errors:

C:\Documents and Settings\Owner\Desktop\Moonlighter\Text1.cpp(24) : error C2440: 'initializing' : cannot convert from 'const int' to 'struct HWND__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast


C:\Documents and Settings\Owner\Desktop\Moonlighter\Text1.cpp(25) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
Error executing cl.exe.

paulq
08-07-2006, 08:52 PM
Sorry, that method won't work, scratch that.

According to MSDN
To set the text of a control in another process, send the WM_SETTEXT message directly instead of calling SetWindowText.

So try looking into that. Use the code in the link from my previous post.
CWnd* pWnd = GetOtherAppWindow();
TCHAR buf[512];
pWnd->SendMessage(WM_SETTEXT,
sizeof(buf)/sizeof(TCHAR),
(LPARAM)(void*)buf);

Using this (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowmessages/wm_settext.asp) as your reference.

Sorry about that, my mistake.

cameronlanni
08-07-2006, 08:54 PM
Already tried that as well, I think I'm implementing it wrong. Where do I put the handle id?

oracleguy
08-07-2006, 08:56 PM
First, cl.exe is Microsoft's VC++ Compiler, not a compiler option. Second, anything is possible.

I didn't make myself clear enough, I ment the /Zm was a compiler option if cl wasn't his program. I didn't know the actual filename of the compiler, I've never used it directly.

cameronlanni
08-07-2006, 09:02 PM
When I simply uses this code:





HWND* pWnd = GetOtherAppWindow();
TCHAR buf[512];
pWnd->SendMessage(WM_SETTEXT,
sizeof(buf)/sizeof(TCHAR),
(LPARAM)(void*)buf);




I receive the following errors:

C:\Documents and Settings\Owner\Desktop\Moonlighter\Text1.cpp(24) : error C2065: 'GetOtherAppWindow' : undeclared identifier

C:\Documents and Settings\Owner\Desktop\Moonlighter\Text1.cpp(24) : error C2440: 'initializing' : cannot convert from 'int' to 'struct HWND__ ** '
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

C:\Documents and Settings\Owner\Desktop\Moonlighter\Text1.cpp(26) : error C2227: left of '->SendMessageA' must point to class/struct/union
Error executing cl.exe.

paulq
08-07-2006, 09:38 PM
Here you go, here's working code I just wrote:

#include "windows.h"

void main()
{
HWND hWnd;
hWnd = (HWND)0x103CC;
char string[100] = "Text you want to set to!";
SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)string);
}

Full program, compiles and runs with MSVStudio 2003. 0x103CC is your handle to your control you want to set. You need to find this programatically each time. We'll figure that out next ;)

cameronlanni
08-07-2006, 09:54 PM
Awesome, thank you so much.