|
What you are after is not possible. You could pull it off while in debug mode, but the same trick would not work in release mode.
When you dynamically allocate memory, the amount requested is usually stored in a variable or a #define directive.
char *buff = new char[255]; Now whenever buff is used by other functions, the value 255 must also be sent to those functions. Make sense?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi Guys
I have to convert a IP-Address which is a CString to an UInt, but i have no clue how to do this. Also i must convert a Port CString to an UInt.
MFG
RedDragon2kx
Unix and C are the ultimate computer viruses.
|
|
|
|
|
don't you use a class that use ip addresses, and in which some function take a string (either char* or std::string or CString...) ?
else, you might write your own function that test first the validity of the address, and then, extract it to a UInt...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
You can sscanf the string like so:
CString sIPAddr;
UINT nByte1, nByte2, nByte3, nByte4;
UINT nPort;
DWORD dwIPAddr;
int nArgs = sscanf( (LPCTSTR)sIPAddr, "%d.%d.%d.%d:%d",
&nByte1, &nByte2, &nByte3, &nByte4, &nPort );
if( nArgs != 5 )
{
}
else
{
...
...
dwIPAddr = (nByte1 << 24) + (nByte2 << 16) + (nByte3 << 8) + nByte4;
}
You may want to verify my byte ordering (nByte4 may be the high byte) when building the dwIPAddr, but this should do the trick.
Bob Ciora
|
|
|
|
|
Thx. That fixed my problem.
Unix and C are the ultimate computer viruses.
|
|
|
|
|
For future reference, take a look at the inet_addr function in the MSDN library. I can't believe there isn't built in global c runtime functions for parsing an IP address in this day and age. But if you are programming with MFC or windows, you can use this windows function.
I hate the sscanf method myself. It seems wonderful on paper but there seem to be all kinds of weird issues when I try to use it. It never worked well for me as a validation tool for any kind of number. I always use the cruntime methods such as strtod for taking strings and validating them as actual numbers and converting them into an int value (for instance). Unfortunately, I don't see a c-run time method for IP addresses that would be more portable. Since I am a windows programmer, I have to settle for the windows libraries to provide this capability.
Shawn
|
|
|
|
|
Question. I have been doing c++ code for sometime now but only in console code. I am starting now to use MFC and I wanted to convert my old Console code into GUI MFC code. My Code relies heavily on Stream I/O with strings and character arrays, but I am having a problem getting my character arrays to output to my GUI correctly. I keep getting assertion errors when when running the program (NOTE: the program compiles error free).
Here is an example of what works:
void CParserDlg::OnParse()
{
char key[16]; //Make Array "Key"
strcpy(key, "Text Here"); //Copy "Text Here" into array
UpdateData(TRUE); //
m_strkey.Format(key); //Send String to Dialog Box
UpdateData(FALSE); //
}
This works fine and outputs the string "Text Here" to the dialog box. Now if I try and output 1 character and not the whole thing I get an assertion error:
void CParserDlg::OnParse()
{
char key[16]; //Make Array "Key"
strcpy(key, "Text Here"); //Copy "Text Here" into array
UpdateData(TRUE); //
m_strkey.Format(key[2]); //<------- Send String to Dialog Box
UpdateData(FALSE); //
}
Notice key[2] instead of just key. Not sure why it will not let me just output 1 character.
Thanks
|
|
|
|
|
I am going to go out on a limb here. Someone please correct me if I am wrong.
The first example works because a CString can be assigned the value of a character array:
m_strkey = key;
BUT a CString does not know what to do with a single character from an array. If you want to use the second example try:
m_strkey.Format("%s", key[2]);
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|
Actually, the assignment operator works for both strings and characters, as per the MSDN documentation.
So you can simply do a:
m_strKey = key;
...
...
m_strKey = key[2];
As mentioned in the other reply, CString::Format is CString's version of sprintf(). You can use it to assign a string (as you did), since it didn't have any formatting characters in it. But CString is flexible enough that you can simply assign directly via =.
Bob Ciora
|
|
|
|
|
you are using CString::Format() the wrong way.
if you know about printf(), use Format() exactly the same...
so, if you want to print a single character, use Format("%c", key[2]);...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Thank you gentlemen. I never familiarized myself with printf() as I always used cout and cin for my Stream I/O before.
Again thank you.
|
|
|
|
|
Ok thanks guys for that, Now onto trying to outputting multiple characters. I have tried a couple of different ways, but to no avail thus far:
void CParserDlg::OnParse()
{
char key[16]; //Make Array "Key"
strcpy(key, "Text Here"); //Copy "Text Here" into array
UpdateData(TRUE); //
m_strkey.Format("%c", key[0]); //Output "T"
m_strkey.Format("%c", key[1]); //Output "e"
UpdateData(FALSE); //
}
void CParserDlg::OnParse()
{
char key[16]; //Make Array "Key"
strcpy(key, "Text Here"); //Copy "Text Here" into array
UpdateData(TRUE); //
m_strkey.Format("%c", key[0], key[1]); //Output "T" and "e"
UpdateData(FALSE); //
}
I also played with the UpdateData(), but again it will only output the last character I send which in this case is "e". "T" gets lost somewhere along the lines even if I send it by sending FALSE to UpdateData().
|
|
|
|
|
In both cases you are overwriting the 'T' character.
In the first case you are first setting the m_strkey to 'T' then
immediately changing it to 'e'
If you want to add the 'e' instead of changing from 'T' to 'e' use:
m_strkey.Format("%c", key[0]); //Output "T"
m_strkey += key[1];
Or you could just simply use
m_strkey = key[0];
m_strkey += key[1];
In the second case you are using a format string that only accepts one
character then passing two characters as arguments (of course only one is used):
m_strkey.Format("%c", key[0], key[1]); //Output "T" and "e"
Use:
m_strkey.Format("%c%c", key[0], key[1]); //Output "T" and "e"
Steve T
|
|
|
|
|
thank you.
I am learning this little by little. Its the little things that give me the most trouble. Do you know of any tutorials or articles where I can learn about this?
Thanks
|
|
|
|
|
I would lose the calls to UpdateData() . Rare is the case that it is ever useful.
You did not indicate what control on the dialog box is displaying the text so I will assume it is an edit control. In the dialog's class, you need a CEdit variable (e.g., m_edit ). Now your code can look like:
void CParserDlg::OnParse()
{
char key[16];
strcpy(key, "Text Here");
m_strkey = key;
m_edit.SetWindowText(m_strkey);
} or
void CParserDlg::OnParse()
{
m_strkey = "Text Here";
m_edit.SetWindowText(m_strkey);
} or
void CParserDlg::OnParse()
{
m_edit.SetWindowText("Text Here");
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thank you for the reply. I already have a CEdit variable in this case being: "m_strkey for the Edit Box which I am outputting to (you we're correct on that assumption).
I tried using SetWindowText() instead of Format(), but I keep getting an error:
error C2039: 'SetWindowTextA' : is not a member of 'ATL::CStringT<basetype,stringtraits>'
with
[
BaseType=char,
StringTraits=StrTraitMFC_DLL<char>
]
Not sure why it says "SetWindowTextA", I only have "SetWindowText".
|
|
|
|
|
Is there a way, in a Visual Studio .NET Setup project, that you can make a custom folder under the Application folder that will include all the files from some source directory? I only see a way of specifiying individual files to add to the folders. I just want this folder to include c:\somefolder\*.* and not worry about adding and removing individual files if it changes.
Thank you
|
|
|
|
|
I'm pretty sure the answer to this is no. You definitely cannot do it through the VS interface.
The problem is the MSI package is basically a database, and all files must have unique keys as well as attributes assigned. The file keys must also be assigned as secondary keys to other keyed tables like the Components table. So it is not a simple process.
InstallShield may still provide a drag and drop capability - the pre MSI versions did.
You can write an external app that populates MSI tables through APIs, but it would definitely be a non-trivial task to create. Much harder than manually adding the files...
You could also write a custom action that simply extracted all files from a given CAB and copy them to a target directory. But you would also have to provide custom actions for how, and when to remove this files in case of an uninstall, since the MSI itself would not have the set of information it needed to be able to handle for this.
Also non-trivial, at least to do it right.
Sorry,
Robert
|
|
|
|
|
i added a few of MFC software on a web-site for free download, is there any idea to increase traffic to this free software web-site?
includeh10
|
|
|
|
|
This probably is not the best forum to post this type of questions. But to give a quick answer, submit your web site to all the search engines out there. Add links to your website on other peoples website.
Good luck. it may take a month before you see any results...unless your willing to pay for quicker action.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Are there any way to Save/Restore appearance scheme from C++ code ?
|
|
|
|
|
I'm not sure what "appearance scheme" is, but applications generally put configuration-related data in the registry.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
hai,
Everyone who know that how to use the install.inf file to perform the silent installation?? i mean that what are the coding in the .inf file to perform silent installation!
Example: the coding can hide the next button when perform installation!
Thanks for ur!!!!
|
|
|
|
|
What would cause DrawDragRect to draw black square?
It's suppose to disappear if you draw over the same square twice but some how I am getting black square and I don't know what's causing it. I am using pretty much the same code I used for OnMouseMove(which works fine), the only difference is I changed how deltaPt behave.
dc.DrawDragRect(pLink->GetRc(moving[1]-1)-ScrollClip, bdry, pLink->GetRc(moving[1]-1)-ScrollClip, bdry, NULL, NULL);
Would cause no square to be drawn
dc.DrawDragRect(pLink->GetRc(moving[1]-1)-ScrollClip, bdry, pLink->GetRcLast(moving[1]-1)-ScrollClip-deltaPt, bdry, NULL, NULL);
Would cause a delay on clearing up. Show two square when I scroll down.
In both cases I would suspect my code would work. I am out of ideas what else to test for.
Here is my code
BOOL CEditView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt){
CClientDC dc(this);
CPoint deltaPt = CPoint(0,0);
POSITION pos = 0;
CEditDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CObList& LinkList = pDoc->GetLinkList();
CPoint ScrollClip;
int MaxScroll;
ScrollClip = GetScrollPosition();
MaxScroll = GetScrollLimit(SB_VERT);
if(zDelta < 0 && (ScrollClip.y < MaxScroll)) {
deltaPt = CPoint(0, 63);
} else if (zDelta > 0 && ScrollClip.y > 0) {
deltaPt = CPoint(0, -63);
} else {
deltaPt = CPoint(0, 0);
}
CString test;
if(moving[1]){
pos=LinkList.FindIndex(moving[0]-1);
CLink* pLink = (CLink*) LinkList.GetAt(pos);
pLink->OffsetRc(moving[1]-1, deltaPt);
dc.DrawDragRect(pLink->GetRc(moving[1]-1)-ScrollClip, bdry, pLink->GetRcLast(moving[1]-1)-ScrollClip, bdry, NULL, NULL);
pLink->EqualRc(moving[1]-1);
}
return CScrollView::OnMouseWheel(nFlags, zDelta, pt);
}
|
|
|
|
|
Hello,
I am creating a dll in which I simply want to export a class.
When creating the dll I noticed in the .cpp file that is default created by VC and which has the InitInstance inside, the following comment:
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
// ......
etc...
Does that mean that in each member function of the class which I want to export I`ll need to add that macro?
Why isn^t it present in the default InitInstance function?
And what`s the use of that InitInstance function anyway? I created the dll and debugged it and put a breakpoint in tthe InitInstance function, but it was never called. The theApp object of the dll was never instantiated either, but none the less I used an exported class from that dll in another app.
Thx for any help you might give.
Friendly regards,
Davy
|
|
|
|
|