|
k, it works, thanks.
Cynicannibal
|
|
|
|
|
Hi, I need some help, I'm trying to make a function that fills the length of some string with 0 at left, the function receives two parameters, the string, and the desired length, but when I compile it, appears an error, the error C2440 cannot convert from 'class CString' to 'int'
-------------------------------------
Here is my function:
CSValidating::fill(CString a, int b)<br />
{<br />
CString filled;<br />
filled = a;<br />
while (filled.GetLength() < b)<br />
filled = "0" + filled;<br />
<br />
return filled;<br />
}
--------------------------------------
I would appreciatte if someone can help me to solve this error...
thnxz
|
|
|
|
|
Try declaring retuned value as CString or CString&
|
|
|
|
|
ponshio wrote:
CSValidating::fill(CString a, int b)
should read something like:
CString CSValidating::fill(CString a, int b)
C++ functions return int by default if you don't specify the return type, so the conversion error is referring to the return filled;
I would suggest that you can improve on that algorithm somewhat too - the hint is that CString has a constructor that can take a character ('0' ) and a number (something like b - filled.GetLength() ) indicating how many times to repeat it
--
Ian Darling
"The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
|
|
|
|
|
You may have to reverse the order of "0" and filled. I think I recall that there is no overloaded "+" for const char* + CString
And probly better to pass as a reference rather than replicating the CString twice.
J.
----------------------------
|
|
|
|
|
As the others pointed out, you are returning an int - probably without knowing it.;P
You definitely need to return a CString , not CString& or *CString . You cannot return anything local to your function, as it needs to exist after your function has terminated.
Your first parameter should be a const CString& : As you are only ever reading it, so you can promise that to the compiler and let it optimize your code. It should be a reference, as there is no point in making a temporary copy of the CString just for this call (as the normal call-by-value does). Yes, I know about CString doing refernce counting, but this is beginner level.
Third, your variable names could be longer and more 'telling' about their use. But that is purely personal style.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
Hi,
In my application i have this:
HBITMAP hImage;
hImage = (HBITMAP)::LoadImage (AfxGetInstanceHandle(), "c:\\TEMP.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE |LR_CREATEDIBSECTION );
DeleteObject(hImage);
These statement will increase the memory usage by 28 KB.
Size of the "temp.bmp" file is 360KB.
Could any one tell me why is it so?
Regards
Neha
|
|
|
|
|
Neha wrote:
These statement will increase the memory usage by 28 KB.
How are you measuring this?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Using window task manager mem usage for that application.
|
|
|
|
|
the value displayed in the task manager is not correct at all!
Don't try it, just do it!
|
|
|
|
|
Is there any proof for that?
|
|
|
|
|
The best you could hope to come from TM is to show the size of the address space that is in use, not the amount of that address space that your program is actually using. Perhaps you are confusing address space with program size.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I am talking about the Mem usage column in the processes tab.
I think this represents the memory usage by the application.
|
|
|
|
|
this is not the answer to your question, but for loading a bitmap from the disk, you dont need to pass the hInst to the function!
Don't try it, just do it!
|
|
|
|
|
Still no difference..
One more strange thing is when some of function been called, It will increase the memory usage by 4KB.Those function don't allocate anything......
|
|
|
|
|
Neha wrote:
One more strange thing is when some of function been called, It will increase the memory usage by 4KB.Those function don't allocate anything......
How do you know? When you call a function that is not your own, are you sure of what it does, or doesn't do, behind the scene?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
If you execute that code 100 times does it increase the memory in task manager by 2800 K?
If yes, then it is a memory leak.
If no, it is just increasing the process address space one time to reflect the additional library code you used.
|
|
|
|
|
Yes,It increases by 2800K........
|
|
|
|
|
Write a program that doesn't do anything
main()
{
return 0;
}
Now see how much memory this takes in task mgr. According to you it shud take 0 bytes!!
|
|
|
|
|
hi,
is someone familiar with manipulating PE/COFF Files. I need to add a DLL into the import Table, but that's a damned hard job. One of my problems is, that i can't create a valid Relative Virtual Address (RVA). I need help.
Thanks in advance!
|
|
|
|
|
what is the problem with it?
Don't try it, just do it!
|
|
|
|
|
There are a few problems.
Number 1: You can't simply add as much DLL Entries as you want into the Import Table, without changing the rva's of the following sections.
Number 2: You have to find a place in the .exe/.dll file which is mapped into the memory
Number 3: The place must be big enough to hold every needed information, such as the name of the dll you want to add
Number 4: You must calculate a valid RVA for the position where the name of the DLL is located.
Number 5: ... Number 4 seems not to be the last point to pay attention for, because if you fixed every mentioned problem, it still won't work!
Do you know a better solution ?
Thanks in advance!
|
|
|
|
|
Microsoft may not want you tampering with their binaries, there may be safeguards in there, too.
J.
----------------------------
|
|
|
|
|
Hi all,
i am creating a dialog like this:
CBDRMainDlg dlg(IDD_BDR_DIALOG);
dlg.AddTitleButton(<big>CBDRMainDlg::CloseDialog</big>,
IDB_CLOSE_BTN_UP,
IDB_CLOSE_BTN_DOWN,
IDB_CLOSE_BTN_OVER,
IDB_CLOSE_BTN_DISABLED);
as you can see the first parameter is a pointer to a method CBDRMainDlg::CloseDialog
the method AddTitleButton is defined like this:
typedef void (* FUNC_PTR)(...);
.
.
.
void AddTitleButton(FUNC_PTR func,
UINT idNormal,
UINT idDown,
UINT idOver = 0,
UINT idDisabled = 0,
CString szTitle = _T(""),
COLORREF rgbTextColor = BUTTON_FX_BASE_TEXT_COLOR,
enBtnState eBtnState = bsNormal);
as you can see the first parameter is a typedef of a pointer to a function.
the passed method is defined like this:
.
.
public:
void CloseDialog();
trouble is a get an error compilation:
"error C2664: 'AddTitleButton' : cannot convert parameter 1 from 'void (__thiscall CBDRMainDlg::*)(void)' to 'void (__cdecl *)(...)'
There is no context in which this conversion is possible"
can any1 help?
thanks in advanced
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
I bet CBDRMainDlg::CloseDialog is not static...
Thats the ususal gotcha.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|