-
November 6th, 2008, 05:43 PM
#1
FindWindow(NULL,"windowname") using a string variable instead of "windowname"
As the title suggests I am working on a project and
FindWindow(NULL,"windowname") works fine, but for my project, I need to pull the windowname from a string variable, for example String* Hereitis = "temp.pdf - Adobe Reader". My thought was FindWindow(NULL, Hereitis) would work but instead I get the error can't convert second variable from string to lpcstr. I am using .net visual C++. Here is the section of applicable code
String* view = "c:\\scan\\program\\pdfviewer.txt";
FileStream* fsview = new FileStream(view, FileMode::Open);
StreamReader* srview = new StreamReader(fsview);
String* viewpath = "Start";
viewpath = srview->ReadLine();
fsview->Close();
String* closepath = String::Concat("temp.pdf - ",viewpath);
HWND closer = FindWindow(NULL, closepath);
SendMessage(closer,WM_CLOSE,0,0);
-
November 7th, 2008, 09:39 AM
#2
Re: FindWindow(NULL,"windowname") using a string variable instead of "windowname"
Try the (LPCTSTR) or (LPCSTR) operator
Code:
HWND closer = FindWindow(NULL, (LPCSTR) closepath);
Succinct is verbose for terse
-
November 7th, 2008, 10:04 AM
#3
Re: FindWindow(NULL,"windowname") using a string variable instead of "windowname"
I tried both of those and get the same error c2440: 'type cast' : cannot convert from 'System::String_gc* to 'LPCTSTR' or 'LPCSTR' for each.
-
November 7th, 2008, 06:49 PM
#4
Re: FindWindow(NULL,"windowname") using a string variable instead of "windowname"
Are you aware that you're mixing managed (.NET) and native C++ code here ?
If you don't know the difference STOP AND FIND OUT. Otherwise you'll get yourself into heaps of problems.
You need to convert the .NET string (System.String) to a native C++ char array to pass to FindWindow.
See here.
Darwen.
-
November 7th, 2008, 08:10 PM
#5
Re: FindWindow(NULL,"windowname") using a string variable instead of "windowname"
Thanks that did the trick, where or what do you recommend reading to know the difference between the two types.
-
November 7th, 2008, 08:30 PM
#6
Re: FindWindow(NULL,"windowname") using a string variable instead of "windowname"
Get a book on learning native C++ (it's easy to spot - it'll be full of 'std::') and read that.
Then come back to .NET code and see the difference.
Out of interest why aren't you learning C# if you're interested in learning .NET and don't know native C++ ?
Then there's no confusion.
Darwen.
-
November 7th, 2008, 10:27 PM
#7
Re: FindWindow(NULL,"windowname") using a string variable instead of "windowname"
I got a deluxe learning edition a while back of visual c++ .net version 2003 and so have been using it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|