|
Nothing wrong with that, it keeps the code readable. There are lots of reasons for doing something like this, I do it all the time to keep the lines at a reasonable lenght or to see the code in approximately the same layout as the user will see, for example.
ts.Format("%s #%d", KnownExternalSizers[ndx].TargetShortName, theServ->CalcIDNumber);
ts = CString("This page anchors the \"") + ts + CString("\".\r\n\r\n") +
CString("Please use that tool to enter data and make changes to your requirements.\r\n\r\n") +
CString("Do Not Close / Exit that application, doing so will lose any data entered and will not produce results.\r\n\r\n") +
CString("When you use the \"Solve / Submit\" button above, the results of that tool will be combined with the other results of the ") +
master_UserPreferences->GetSizerLongName();
m_messagebox.SetWindowText(ts);
|
|
|
|
|
OK, now why was this downvoted? It reinforces the original question with an example that even experienced programmers (me) use such a construct and it's perfectly reasonable. I'm trying to understand the reasons for the anonymous downvoters choice.
|
|
|
|
|
Correction, it does work, just a package option error in my list.
hmm, the string builds fine, but when ran through the ShellExecuteEx, the lpParameters bombs. with a -214 type of error. Not looking for the answer, just an FYI if someone runs across this thread in the future.
This worked as a small test.
lp_Parameters = "/iu "IIS-WebServerRole;IIS-WebServer;";
modified 27-Sep-11 18:56pm.
|
|
|
|
|
|
On a sidenote, this shouldn't even compile as there is no operator+(const char*, const char*) ! At best you could write:
lp_parameters = CString("/iu;") +
CString("IIS-WebServerRole;") +
But, as I've seen, you already found the better solution.
|
|
|
|
|
Hi,
The problem is:
I have a Cstring Object and inside then there are a function name that is wrote in my aplication code.
How can i start that function using the content of CString ?
It seems to me that i need to seek the memory function address and use then as a pointer...
It it possible ?
Samuel
|
|
|
|
|
Please share any relevant code with us, seeing the code might us help understand the problem you are facing.
You can modify your question to add the code.
0100000101101110011001000111001011101001
|
|
|
|
|
Yep... I did not understand that question at all...
|
|
|
|
|
Sorry for my poor explanation
please, Look at answer sent to Maximilien
Samuel
|
|
|
|
|
Sorry for my poor explanation
please, Look at answer sent to Maximilien
Samuel
|
|
|
|
|
nope, you cannot directly call a function from a string.
If I understand correctly, you have something like this and want to call myFunction .
CString s("myFunction");
What you will need is a factory:
void myFunction(){};
CString s("myFunction");
Factory(s);
void Factory( CString& string);
{
if ( string.Compare("myFunction") == 0 )
{
myFactory();
}
}
Watched code never compiles.
|
|
|
|
|
Thanks for you attention Maximilien.
Realy, today i do this ... but a have so many functions to call and the struct of IF is going to be bigger i was planned.
I want to create a text file and put inside then a struct of tasks as shown above:
1 - Text description of task 1
1.1 - Text description of task 2 (Below to task 1)
1.1.1 - Text description of task 3
2 - Text description of task 4
2.1 - Text description of task 5
2.1.2 - 1.1 (reused it and your childs, if there are)
It seems complex, but it isn't for my aplication and the objective is wish.
As you can see, with this method i can create complex tasks just manipulating the file. obviosly i pass and return data and parameters between the functions using files seems like .ini
the ideia It will be like this:
.h
void GPC_1_2{};
.cpp
--> I create a deque or table and put inside then all functions names found inside text file
--> I receive a command from entrace process to execute task "GPC_1_2"
--> now a want to get the memory address for "GPC_1_2"
--> Using the memory address, i want to start GPC_1_2 function
Ps: Sometime ago i saw, but not save, a code to find the memory address function. it was using just the name of function inside a string object.
Sorry for the poor english, it is not my native language. I'm Brazilian
|
|
|
|
|
You might be able to use LoadLibrary() and GetProcAddress() to accomplish this. See here[^] and here[^].
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Excellent suggestion. Dynamically lookup names of functions found in a DLL entry vector. That'll do it.
|
|
|
|
|
Chris,
I beliave it works, but i will need many of DLLs and a process to manage then. The struct i'm using will must change a lot to work this way
Samuel
|
|
|
|
|
Samuel Nunes de Arruda wrote: i will need many of DLLs and a process to manage then
This is not true. You can put all your functions into a single DLL and load it once using LoadLibrary() [^]. You can then find any of the exported functions using GetProcAddress() [^] with the name that you read from your text file. You can do this with minimal changes to your existing code.
|
|
|
|
|
You can use an map of function pointers to accomplish this.
This is assuming all the functions have the same signature, that is same return type and same numbers and types of parameters.
typedef void (*VoidFuncType)();
map<string, VoidFuncType> functions;
functions["myFunction1"] = myFunction1;
functions["myFunction2"] = myFunction2;
...
string func = "myFunction1";
...
functions[func]();
Note that myFunction1 and myFunction2 are functions or methods in your code.
If they are member functions, then the typedef will need to be different, and so will the subsequent usage.
Be sure to
#include <map>
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
modified 28-Sep-11 17:11pm.
|
|
|
|
|
Thank you ahmed,
Your solution can solve the problem because all the functions are using the same prototipe:
bool XXXXXX( Cstring )
The CString is the name of a file where the parameters (All data generate by de functions) are saved
to the next
The file represent the task data.
Realy thank you.
Samuel
|
|
|
|
|
Glad to be able help.
Good luck with your project.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
|
|
|
|
|
hi,
I have an aplication whose view is based in TabControl. It has three tab and one of them have a Edit control. I'd like show text in this edit control when I press a button. I thought do a global variable that keep a valor, for example 1, and in the method, to do a control that show text only if the variable have valor 1.
But my problem is after press button, don't happen something. I think that I must to update the view with the method onUpdate or something like that.. but I dont know how.
What do you think?
This is my aplication:
http://i54.tinypic.com/1e9qtx.png
This is code :
http://www.megaupload.com/?d=1QT43LOQ[^]
|
|
|
|
|
Global variables are usually not a good answer to anything. What you should do is post a message to the view and tell it to update the control whenever you need a value displayed or updated (use SendMessage() or PostMessage() ). You should not access the control directly from any window that does not own the control.
In the future, try and post applicable code in your question.
|
|
|
|
|
Ok, but I dont know how to update the control so that when I press the button show a message
|
|
|
|
|
Well, there's a number of steps:
1. To get notification of a button press, make sure the button control owner is catching the notification message.
2. To alert the other control's owner of the button press, the message handler of the button press should SendMessage() or PostMessage() to the edit control owner window requesting he make the change. The owner window needs a message defined and appropriate message handler.
3. Within the owner of the edit control, the message handler for changes to the edit control should take the parameters passed to it, then set the window text.
Which step do you not understand? As you can see, this is a somewhat complex process if you don't know how messaging works. You need to do a bit of research.
|
|
|
|
|
I don't have idea about messaging works, can you give me information? any page or something like that?
|
|
|
|
|