View previous topic :: View next topic |
Author |
Message |
hacksign23 Master Cheater
Reputation: 0
Joined: 26 Nov 2006 Posts: 404
|
Posted: Fri Nov 28, 2008 5:51 pm Post subject: FindWindow Help C++ |
|
|
Well I'm using VC++ Team System 2008 and it gives me a linking error:
C++ linker wrote: |
Error 1 error LNK2028: unresolved token (0A00000F) "extern "C" struct HWND__ * __stdcall FindWindowA(char const *,char const *)" (?FindWindowA@@$$J18YGPAUHWND__@@PBD0@Z) referenced in function "private: void __clrcall minez::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@minez@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) minez.obj minez
Error 2 error LNK2019: unresolved external symbol "extern "C" struct HWND__ * __stdcall FindWindowA(char const *,char const *)" (?FindWindowA@@$$J18YGPAUHWND__@@PBD0@Z) referenced in function "private: void __clrcall minez::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@minez@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) minez.obj minez
Error 3 fatal error LNK1120: 2 unresolved externals F:\Michael's Magical Folder Of Hippos\programming\C++\minez\Debug\minez.exe 1 minez
|
and i used
Code: |
FindWindow(NULL, (LPCSTR)"Untitled - Notepad");
|
thanks.
_________________
|
|
Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Fri Nov 28, 2008 6:03 pm Post subject: |
|
|
I'm not entirely sure how API calls work within managed C++, but I want to say that you're just missing the include.
|
|
Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
|
Back to top |
|
 |
BirdsEye Advanced Cheater
Reputation: 0
Joined: 05 Apr 2008 Posts: 94
|
Posted: Fri Nov 28, 2008 6:13 pm Post subject: |
|
|
Ugh... Please stop using managed C++. I think you have to declare the function just like in VB.NET and C#. Here
|
|
Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Fri Nov 28, 2008 6:41 pm Post subject: |
|
|
Linking error?
|
|
Back to top |
|
 |
hacksign23 Master Cheater
Reputation: 0
Joined: 26 Nov 2006 Posts: 404
|
Posted: Fri Nov 28, 2008 11:10 pm Post subject: |
|
|
?? o_o well is there an alternative way to get a hwnd? And when i say hwnd, not anything else like process or handle. thanks
PS: all the other functions work like WPM,RPM, etc
_________________
|
|
Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Sat Nov 29, 2008 3:59 am Post subject: |
|
|
Code: | #include <windows.h>
#pragma comment(lib, "user32.lib") |
Code: | HWND hWnd;
if (IsWindow(hWnd = FindWindowA(NULL, "Untitled - Notepad")))
{
MessageBoxA(NULL, "Found Notepad!", "Test", 0);
} |
Didn't realise how easy it is to use native code within managed c++, link to user32.lib and your project should build correctly.
ps. abandon c++.net
|
|
Back to top |
|
 |
BirdsEye Advanced Cheater
Reputation: 0
Joined: 05 Apr 2008 Posts: 94
|
Posted: Sat Nov 29, 2008 9:33 am Post subject: |
|
|
Oh yea, he's right. I've never used C++.NET so beware... I'm not sure if this is the correct method or anything. If you include your headers and link against the USER32 library, it still would give you an ambigious symbol error. HOWEVER, (I got this from messin' around) if you type: it will give you a list of alot of Win32 API and they function right. See:
Code: |
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if(!::FindWindow(TEXT("Notepad"), NULL))
::MessageBox(0, TEXT("Error!"), TEXT("Error!"), MB_OK);
else
::MessageBox(0, TEXT("Found!"), TEXT("Found!"), MB_OK);
}
};
}
|
|
|
Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Sat Nov 29, 2008 10:48 am Post subject: |
|
|
Yea, you can avoid the ambiguity by using MessageBoxA, will save you from using the TEXT() macro too.
|
|
Back to top |
|
 |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Sat Nov 29, 2008 12:28 pm Post subject: |
|
|
sloppy wrote: | Yea, you can avoid the ambiguity by using MessageBoxA, will save you from using the TEXT() macro too. |
Never specify A or W. Use MessageBox because the tchar.h header will correctly change it to A or W depending on whether UNICODE is defined. The TEXT() is part of tchar. It adds a L infront of the string if UNICODE is defined. This makes it so that you can change from Unicode to ANSI with a simple change in the project settings.
|
|
Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Sun Nov 30, 2008 3:42 am Post subject: |
|
|
Good advice, excuse my sloppy coding practices.
|
|
Back to top |
|
 |
hacksign23 Master Cheater
Reputation: 0
Joined: 26 Nov 2006 Posts: 404
|
Posted: Sun Nov 30, 2008 7:38 pm Post subject: |
|
|
wowawea it is working now. thanks! oh one more thing:
Code: |
LPCWSTR windowtextaa = NULL;
//finds windowtextb(before)
windowtexta=windownameTextbox->Text;//puts text into windowtexta
windowtextaa = (LPCWSTR)(Marshal::StringToHGlobalAnsi(windowtexta).ToPointer());//windowtexta
MessageBox::Show(windowtexta);
if (!SetWindowText(mineHwnd,windowtextaa)) {
MessageBox::Show("fail D:","D:");
}
Marshal::FreeHGlobal((IntPtr((void*)windowtextaa)));
|
I'm using that to convert it to the LPCWSTR crap, but when i put text into the text box, the window name turns into chinese crap o_o
for example:
i put in "aaa" and it comes out whatever is in the screen shot. I don't know what it is. any help?
Description: |
|
Filesize: |
1.85 KB |
Viewed: |
7387 Time(s) |

|
|
|
Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Sun Nov 30, 2008 8:51 pm Post subject: |
|
|
Marshal::StringToHGlobalUni(..)
|
|
Back to top |
|
 |
hacksign23 Master Cheater
Reputation: 0
Joined: 26 Nov 2006 Posts: 404
|
Posted: Sun Nov 30, 2008 9:41 pm Post subject: |
|
|
sloppy wrote: | Marshal::StringToHGlobalUni(..) |
thanks
_________________
|
|
Back to top |
|
 |
|