|
hi,
I'm student.But I can not much.I have to make a c++ programm to search and to return some values from a Textfile. The Textfile looks like:
proxy_name="musterman"
Proxy_pass="123123"
name="James Bond"
pass="123aa123"
the program must be written in c++. I have already done something, but it is to
so is it, what I wrote:
LoadConfigFile::ParseConfigFile(const std::String & obj){
std::string line;
std::String s="";
if (obj.length <= 0)
return false;
ifstream dat(obj.c_str());// Konfigurationsdatei
if (!dat){
cout<<"Die Datei konnte nicht geöffnet werden.";
return false;
}
getline(dat,line);
????????????????????
thank you for your help
|
|
|
|
|
Use getline to read a line at a time from the file. As you're using Managed C++, I'd recommend using regular expressions to parse the name/value pairs. Be aware, you're not writing C++ code, but a mixture of C++ and Microsoft specific .NET code.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
try using pcre library (perl compatible regular expressions); beware learning how to use it. is tricky
|
|
|
|
|
Hi, is there sample code to stop another mfc dialog application (.exe) from an mfc application ? THANKS !
|
|
|
|
|
Hi, I am writing a program in MC++ (using VS .NET -- thus this post is very VS .NET specific) and am having a problem getting my main form's Icon to display properly... My application is crashing, based on the follow process:
1 - I made a custom icon for the form (myIcon.ico)
2 - Right Click on the form (in the [design]), click "Properties", then click the "..." button of the "Window Style"->Icon field...
3 - choose "myIcon.ico" from the file chooser
4 - VS .NET then produces the following relevant code (which executes inside the form's constructor):
void InitializeComponent(void)<br />
{<br />
System::Resources::ResourceManager *resources = new System::Resources::ResourceManager(__typeof(myNameSpace::Form1));<br />
...<br />
...<br />
this->Icon = (__try_cast< System::Drawing::Icon * >(resources->GetObject(S"$this.Icon")));<br />
...<br />
If I run the program in debug mode, it will crash when attempting the this->Icon = ... line... If I insert the following code after InitializeComponents() executes, it works fine.
this->set_Icon(new System::Drawing::Icon(new String("app.ico") ) )
However, this now has the side-effect of requiring the myIcon.ico file to be in the same directory as the executable... As I need to release this code to customers, I don't want to trust that they won't accidentally delete the icon file... Thus, I would like icon "compiled into" the executable...
So my questions are:
1) Will it get "compiled into" the executable assuming the generated code ever works correctly...???
2) Why is it crashing...???
3) Does it have anything to do with making the icon into a resource (.rc) file...???
4) Anyone know how I can fix this issue...???
TIA,
istrasci
|
|
|
|
|
I too has similar problems tring to embed image resources into a .NET assembly. I have the standard 2003 version of Visual C++ .NET, and in the documentation they tell you put the Icon or image file into the same directory as the executable. This works, but, as you have noted, is prone to user error.
The Chris Sells book: "Windows Forms Programming in C#", he describes in great detail several methods for embedding image resources into the binary. These methods do not work in Visual C++ .NET. I did, however, find this information from a sample chapter of a book by Richard Grimes, "Developing Applications with Visual Studio.NET".
8.3.4 Managed C++ and Resources
Managed C++ projects allow you to add resources through the Solution Explorer or Class View window, but these will be Win32 resources. If you want to add your own .NET resources, you need to edit the project settings. Here are the steps: First you need to add an XML file to your project. To do this you should use the Add New Item dialog of Solution Explorer, and ensure that the extension of the file is .resx (the resgen utility insists that XML resource files have this extension). If you forget to give the file this extension, you will have to remove the file from the project, rename it using Windows Explorer, and add the renamed file to the project with Add Existing Item from the C++ Solution Explorer context menu. The reason is that the C++ Solution Explorer (unlike the C# Solution Explorer) does not allow you to rename a file that has been added to a project.
Once you have added the .resx file to the project, you should add the bare minimum of resource file contents: the <root> node and the three <res-header> nodes I mentioned earlier: ResMimeType, Reader, and Writer. After that it makes sense to add at least one node (essentially as a template), and then you can edit the resource file using the XML designer.
The next task is to add the .resx file to the build. To do this you should select properties of this file from the Solution Explorer context menu by selecting General Configuration Properties and making sure that the Tool property option selected is Custom Build Tool. You can then set the tools command line through the Custom Build Step option (Table 8.2).
Table 8.2 Custom Build Step properties for an .resx file
Property
Value
Command Line
resgen $(InputFileName)
$(OutDir)\$(InputName).resources
Description
Building .NET resources
Outputs
$(OutDir)\$(InputName).resources
Choosing Custom Build Step will allow you to build the resource; however, you also need to embed the resource in the assembly, and to do this you need to edit the linker options. You select the properties of the project through the Solution Explorer window, and then in the Property Pages dialog you select the Linker node and then the Input node. Within the grid you'll see a property called Embed Managed Resource File; you change the value of this property as follows:
$(OutDir)\$(InputName).resources This parameter assumes that the name of the .resx file that was compiled had the same name as the project. Once you have made these changes, you should be able to add string resources to the project through the .resx file.
Image files are not so easy; the problem is that you have to encode image files into a format that can be put in an XML file. A utility called resxgen will allow you to do this; it is supplied as an example in the .NET Framework Samples folder. However, the problem with this tool is that it will generate an entire .resx file from a single binary file. You cannot use it to add a binary resource to an existing .resx file.
|
|
|
|
|
Hi All,
To demonstrate my problem,Have put in a small piece of code below :
Iam putting some strings into my list & while iterating the list,want to remove a particular element from the list.The following code crashes when I iterate further.
I know that I have to refresh my iterator somehow but how?.
How could I get around this problem?
Thanks..
list<string> pool;
pool.push_back("PageType1");
pool.push_back("PageType2");
pool.push_back("PageType3");
pool.push_back("PageType4");
list<string>::iterator iter = pool.begin();
while(iter!=pool.end())
{
long size = pool.size();
if(*iter=="PageType2")
pool.remove("PageType2");
iter++;
}
|
|
|
|
|
What you need to do is build a list of items to remove, then remove them all in another loop. You can't remove items from a list, because that item contains the pointer to the next item.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
Hi all,
I need to convert a System::Drawing::Rectangle __gc * to System::Drawing::Rectangle. Is this possible and how would I do it?
Thanks in advance.
The problem is I'm trying to set the bounds of a form by passing it a rectangle. The rectangle, however, is a managed rectangle but form->Bounds takes an unmanaged rectangle.
|
|
|
|
|
Well, I doubt very much that an operator exists, but surely it's just a case of creating a new Rectangle using the data in the old one ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How do I create an unmanaged Rectangle in a managed class? I'm trying,
Rectangle r2 = __nogc new Rectangle ( 0, 0, 0, 0 );
but this just gives me an error.
|
|
|
|
|
I'm sorry, that I don't know. But it's definately the case that you need to create one, there won't be a conversion.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Try making an unmanaged proxy function such as:
void SetBounds(int x, int y, int w, int h) {
Form->bounds = New Rectangle(x, y, w, h);
}
And call it from your managed function.
It's been a while since I used C++, but you get the idea.
|
|
|
|
|
Thanks guys.
Sorted the problem by passing each element individually into the bounds property like so,
<br />
System::Drawing::Rectangle* r1;
form1->Bounds = Rectangle ( r1->X, r1->Y, r1->Width, r1->Height );<br />
or somethng along those lines. Seems to work.
|
|
|
|
|
How?
I try do this:
case WM_NOTIFY:
switch(LOWORD(wParam))
{
case IDC_LIST:
pThis->EditLabel(hWnd, lParam);
}
break;
void IMyIEExtention::EditLabel(HWND hWnd, LPARAM lParam)
{
TVITEM tvi;
tvi.mask = TVIF_TEXT;
tvi.cchTextMax=256;
memset(&tvi,0,sizeof(tvi));
LRESULT lr;
// tvi.cchTextMax = sizeof(tvi.pszText)/sizeof(tvi.pszText[0]);
if(((LPNMHDR)lParam)->code == TVN_BEGINLABELEDIT)
{
// MessageBox(NULL, "tv", NULL, MB_OKCANCEL);
hEdit=TreeView_GetEditControl(m_hList);
}
if(((LPNMHDR)lParam)->code == TVN_ENDLABELEDIT)
{
char Text[256]="";
tvi.hItem=TreeView_GetSelection(m_hList);
SendDlgItemMessage(hWnd,IDC_LIST,TVM_GETITEM,0,(WPARAM)&tvi);
GetWindowText(hEdit, Text, sizeof(Text));
tvi.pszText=Text;
lr = SendDlgItemMessage(hWnd,IDC_LIST,TVM_SETITEM,0,(WPARAM)&tvi);
}
}
This code doesn't work. Why?
|
|
|
|
|
Hello,
i need to insert a .NET Form into an MFC application using Visual Studio 2003, is it possible in some way? I've found some articles about doing it with Visual Studio 2005 but nothing more. Is possible is use the form as ActiveX control or what?
Thank you,
Gianmaria
|
|
|
|
|
|
Thank you very much, i'll try the source code provided
|
|
|
|
|
Hi!
How can i code to open a web page in a new IE windows instead of in the same IE windows like Response.Redirect? And i want the just opened web page get the authentication of the web page opening it (so doesn't need to login again)
Thanks!
|
|
|
|
|
Launch a new process (in .NET, that's System.Diagnostics.Process). The Windows Shell understands the IExplore command, therefore, to launch a new IE instance:
iexplore www.google.com
Here you've specified the iexplore (IE) process to launch with the argument www.google.com, making the new IE instance navigate to google. Is this what you wanted?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
Yes, it is But if we open a web page this way, does it need to login again if it need to authenticate ? Because i need the just opened web page get the authentication of the web page opening it
Thanks your reply
|
|
|
|
|
I need to get buddy lists from each of AOL Instant Messenger, Yahoo Messenger, and MSN Messenger and be able to send them a one line Instant message.
Any ideas on how to do this?
|
|
|
|
|
Each messenger will be different; you may need to use proprietary protocols to interoperate with each. Maybe the GAIM[^] project will help you get started?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
Hi all,
quick question. I've built a small project and I want to add a splash screen to my application. Does .net provide any splash screen components to make life easier or do I have to write from scratch?
Thanks in adavnce.
Rich
|
|
|
|
|