|
plzz help.
how a can i write a program to copy function (as a whole) from one c++ file to another c++ file ,(appending to its end)
the inputs of the programe shoid be source file name,function name and destination file name.
|
|
|
|
|
You want to copy a function, at runtime ? As in, you want to add functionality to a compiled class ? Can't be done.
Or are you asking again a question that has been adequately answered before ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
did it in the following way and it worked.
but the problem is how to add the file header attached with the
function .this comes befeore the function
eg.
///////////////////////////////////////////////////////////////////////////////
//
// history=...........etc
///////////////////////////////////////////////////////////////////////////////
using namespace std;
void main()
{
CStdioFile csf("E:\\lastfunc\\ii.cpp",CFile::modeRead);
CStdioFile csg("e:\\cc.cpp",CFile::modeNoTruncate|CFile::modeCreate|CFile::modeWrite);
csg.SeekToEnd();
CString str;
while(csf.ReadString(str))
{
if (str.Find("SetupTls",0)>=0)
{
int i=0;
cout<<str.getbuffer(str.getlength());
csg.writestring(str+"\n");
do {
if(csf.readstring(str))
{
if(str.find("{")="">=0)
{
i++;
}
if(str.Find("}")>=0)
{
i--;
}
cout<<cout<<str.getbuffer(str.getlength())<<'\n';
csg.writestring(str+"\n");
}
} while(i="">0);
}
}
csf.Close();
csg.Close();
}
|
|
|
|
|
I have just learned how to properly do sockets. And as such am currently experimenting with them. I am doing a kind of chat room type program but it needs to interpret certain commands and perform actions.
I cant decide how I want to route the commands though, do I want to use a big messy if statement block or a for loop that loops through checking aginist a if statement or some kind of hashing.
I am checking the first letter of each command received useing a switch statement so I dont check aginist EVEREY command, just the ones that begin with that letter. But I want this to be a pretty fast server considering I want to assum high client load. So whats the fastest way to run through all the possible commands until one is found?
Thanks.
P.S. Im on FreeBSD5.1r and this code doesnt need to be portable, so if there is something platform specific you want to add, please do.
|
|
|
|
|
I am using ReadDirectoryChangeW API to monitor the folders. I am not able to rename or move or copy a folder which is DIRECTLY under ther target monitoring folder.
For example: i have given 'D:\NewDirectory' has to be monitoried.
I have some subfolders under this 'NewDirectory'.
when this api started monitoring 'NewDirectory', then i am not able to rename the sub folders or filename which is DIRECTLY under this folder.
I have used createfile to get the handle, and passed the handle to ReadDirectoryChangeW.
Please tell me whats may be the problem
|
|
|
|
|
Hi folks!
i need a little help about how to control the height and width of the console when my application(console) is started.
I mean when my simple c++ code(e.g Helo world) starts its execution in the console, the Console is resized to what ever dimension (height & width) i mentioned in my program; plz do tell me how to controll the dimension of my console...
Plz i need simple c++ code i.e. no MFC no Windows programming..
Regards, JinBaba.
Bye.
|
|
|
|
|
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
|
|
|
|
|