|
If the function expects a CString, you should pass in a CString.
So simply create a CString variable and pass that in.
CString str;
xxx:yyy(str);
If you want the value in buf, you can later copy it.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hi Superman,
Thanks for your reply...
i actually want to read the content of a file...
If i use CString it is retrieving only the file name and not file content... rather if i use getbuffer() method, i think i can get the content..but its not accepting if i give like this xxx:yyy(str.getbuffer()) ..........it threw an error stating it cant convert wchar_t * to cstring&....
my doubt is this.. i need to copy the content of the file to that wchar variable as well as it should be passed into the function of type cstring&..
how can we do that sir?
Thanks,
Rakesh
|
|
|
|
|
Rakesh5 wrote: if i give like this xxx:yyy(str.getbuffer())
Arghh.... Never nevver use GetBuffer without having read the documentation of that function first. It doesn't make any sense to call this function here because the CString object already provides a cast operator to the same string type returned by the GetBuffer function. So, if passing the CString object directly is failing, calling the GetBuffer function will fail in the same way. Besides, doing that is really bad practice because this function is only inteded to get a way to access the internal buffer of the CString object, which is almost never needed (only in very rare conditions).
|
|
|
|
|
You *must* read the article pointed out by Cedric in his other reply to you.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Why are you using a WCHAR array instead of a TCHAR array in the first place ?
I suggest you read this article[^] first, to be able to understand the concepts. Things will probably be much clearer afterwards.
|
|
|
|
|
Thanks Moonen..
I really appreciate your timely help...
Thanks,
Rakesh
|
|
|
|
|
The function takes a reference to a CString object. You cannot, therefore, pass anything else to it. Please buy a book on C++.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi,
I have created a Window UI using CreateWindowEx(), than on top of that I created a Tabbed control using the same function. On each tab i have a edit control, I am not getting the messages from the edit control.
I am expecting that the mesaages should come to WM_COMMAND/WM_NOTIFIY of the parent window.
thanks in advance.
Birajendu
SonicWALL
Bangalore
India
|
|
|
|
|
Code 1:
while(TRUE)
{ ..........
}
if(1) { ......... }
Compiler warning:- Constant data in conditional statement.
How to get rid of this?
Can i do like.....
bool flag = TRUE;
while(flag) {.......}
Code 2:
unsigned short a = -1;
Compiler warning:- Possible loss of data...
How to get rid of this warning?
Can i do.....
unsigned short a = (ushort)-1;
Code 3:
char a[10];
char b[20] = "H";
strcpy(&a[2], b);
Now i want to convert this function to strcpy_s, where in i have to pass the buffer size..
so can i do like...... strcpy_s(&a[2], sizeof(a), b);
Can i do like that? Or is that i just need to pass the sizeof that particular array index, like sizeof(a[2])
Any help is welcome....
Thanks in advance.
|
|
|
|
|
Hi,
AFAIK there is only one way to create an "eternal loop" that should never generate a warning, whatever smart the compiler is:
for( ; ; ) {
...
}
since this is legal C/C++ code that clearly shows no exit condition. Everything else, checking on 1 or TRUE or a variable with a constant value, is bound to be flagged when compilers are smart enough, their intent is to WARN you that maybe you made a mistake.
The same holds true for empty loops:
while (someCondition); may generate a warning (unintentional empty loop, maybe due to an extraneous semi-colon), whereas
while (someCondition) {}
is fine since now the compiler must realize you typed two characters to create an empty code block.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
dipuks wrote: unsigned short a = -1;
Compiler warning:- Possible loss of data...
How to get rid of this warning?
This is absurd. Why do you want to assign a signed value to unsigned type? What's wrong in using just short ?
|
|
|
|
|
N a v a n e e t h wrote: This is absurd. Why do you want to assign a signed value to unsigned type?
This is not as uncommon as you might think.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
dipuks wrote: while(TRUE)
{ ..........
}
As suggested by Luc, use for ( ; ; )
dipuks wrote: if(1) { ......... }
Why would you ever want to do this?
You really do not need the condition check here.
dipuks wrote: unsigned short a = -1;
Assigning a signed number to an unsigned variable does not make sense.
You should either change the unsigned variable to a signed variable.
Or assign the value 0xFFFFFFFF to the unsigned variable.
A lot of work has been done in this field. Look at Inside SafeInt[^]
dipuks wrote: strcpy_s(&a[2], sizeof(a), b);
You may have to do strcpy_s(&a[2], sizeof(a) - 2, b);
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
these are discussable item, and to tell a long story short, there are different ways possible.
Code 1: writing loops with no "exit strategy" isnt fine
Code 2: common way to initialize with invalid data
Code 3: a[2] = 'H';
+ bug, buffer is false computed !!! strcpy_s(&a[2], sizeof(a) - 2, b);
+ i would use sprintf-style funktion "H%s" for extensionable coding
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
My title is probably not very well phrased, but here is the problem. Let's say I've got functions a() , b() , where a() calls b() , and b() calls vector<T>::iterator iter = someVector.begin() .
b() needs to pass this iterator down to a() via a void* mechanism, without returning it (essentially using reference passing), so more explicitly, the two functions are:
void a(void*& param);
void b(void*& param);
The problem is, we can't simply do something like this:
vector<T>::iterator iter = someVector.begin();
param = reinterpret_cast<void*>(iter)
This is because the compiler (MSVC9) will complain about trying to cast an iterator to a void*:
error C2440: 'reinterpret_cast' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'void *'
Likewise, I can't do something like...
vector<T>::iterator iter = someVector.begin();
param = reinterpret_cast<void*>(&iter)
...because even though this will compile, it will not work because begin() actually returns an iterator object and not a pointer to some memory location, so the memory address of that object will go out of scope (not sure when, but I'm guessing when you leave b() ). So, because I can't do any of this, I thought that maybe I could do a memory copy of the iterator, pass it up as a void*, and then cast it back to an iterator, so something along these lines:
vector<T>::iterator iter = someVector.begin();
void* mem = malloc(sizeof(vector<T>::iterator));
param = mem;
And on the flip side, in order to decode my data, I'd do something like this:
vector<T>::iterator = reinterpret_cast<vector<T>::iterator>(param);
I'm wondering whether or not this idea of mine is feasible or will cause me many problems, or if there is a better way of doing what I'd like to do, given the limitations (can only pass by void* reference).
Thanks.
|
|
|
|
|
Apart from the fact you're using malloc, the last idea's OK.
Use new instead - it's C++, man!
param = reinterpret_cast<void*>(new vector<T>::iterator(someVector.begin()));
Remember to delete it afterwards as well....
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Yeah, well, the way I see it, malloc just does a simple memory allocation, whereas new also calls the parameterless constructor. In this case, since I'm overwriting everything, I figured malloc was the better way, but from my testing, it seems that new works as well. I've managed to get some sample code working, and it seems to be fine when T = int, but I've been told that it may not work where T is a more complicated class.
|
|
|
|
|
Should be fine, no matter what T is - an iterator generally only holds a reference to an item in a container (for simple, container iterators).
Cyrilix wrote: new also calls the parameterless constructor
new will call whichever constructor you specify. In my example, I use teh copy constructor.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
In any recent version of VC, iterators are not simple pointers. There is some debug info kept around to detect dangling iterators and iterators that point outside of their containers. So doing a straight memcpy will work only as long as the original iterator exists.
What about this:
vector<T>::iterator* piter = new vector<T>::iterator ( someVector.begin() );
void* pv = (void*) piter;</T></T> ? Last modified: 5hrs 10mins after originally posted -- fixde tpyo
--Mike--
|
|
|
|
|
|
Is there any function which can transfer date time string to SYSTEMTIME?
the string may be, such as, "2009-06-21 3:12:13" or "2009-06-21".
|
|
|
|
|
|
No single WIndows function, but VarDateFromStr[^] followed by VariantTimeToSystemTime[^]. That will use the date/time format(s) defined by your current locale.
Alternatively,
SYSTEMTIME st;
sscanf("2009-06-21 3:12:13", "%4d-%2d-%2d %d:%d:%d", &sy.wYear, &st.wMonth, &st.wDay, &st.wHour, &st.wMinute, &st.wSecond);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I need help with the GDI-function Alphablend() on Vista. Here's my code:
hMemDC:=CreateCompatibleDC(hdc)
hbitmap:=CreatecompatibleBitmap(hdc,width,height)
...
blendfunc.BlendOp=0
blendfunc.BlendFlags=0
blendfunc.SourceConstantAlpha=128
blendfunc.AlphaFormat=0
AlphaBlend(hdc,siPX,siPY,width,Height,hMemDC,0,0,Width,Height,@blendfunc))
//StretchBlt(hdc,siPX,siPY,Width,Height,hMemDC,0,0,Width,Height,SRCCOPY)
//BitBlt(hdc,siPX,siPY,Width,Height,hMemDC,0,0,SRCCOPY)
When i use StretchBlt() or Bitblt() it works OK, so coordinates are ok. My language is not C so @blendfunc seams wrong but im sure it is not (it means 'pointer to a structure'). I suspect AlphaBlend does not work (returns false) because my bitmap has no alpha-channel. Saw on the MS-website an example that uses CreateDibSection() to create a 32-bit bitmap but that doesn't work also.
It goes like this:
hMemDC:=CreateCompatibleDC(hdc)
memclear(@bmi,_sizeof(_winBITMAPINFO))
bmi.bmiHeader.biSize:=_sizeof(_winBITMAPINFOHEADER)
bmi.bmiHeader.biWidth:=width
bmi.bmiHeader.biHeight:=height
bmi.bmiHeader.biPlanes:=1
bmi.bmiHeader.biBitCount:=32
bmi.bmiHeader.biCompression:=BI_RGB
bmi.bmiHeader.biSizeImage:=oDim:width*oDim:height*4
hbitmap:=CreateDIBSection(hMemDC,@bmi,DIB_RGB_COLORS,pBits,NULL,0)
SelectObject(hMemDC,hbitmap)
So im out of options... Has anyone an idea, or a codesnippet that does work, so i can try that one?
Thanks,
Rozis
modified on Sunday, June 28, 2009 5:04 AM
|
|
|
|
|
I've been working in C# and Java for a while, with only a little experience in using C++, and I'm having a little trouble finding information on if there is anything like base or super in C++. If for example I have this:
class foo {
public:
virtual void myMethod() { cout << "this part is in foo" << endl; }
};
class bar : public foo {
public:
void myMethod() { base.myMethod(); cout << "\tthis part is in bar" << endl; }
};
Such that, base.myMethod() would perform the tasks of myMethod() in the base class, and then it would carry out the new implementation from there; is anything like this possible in C++?
thanks!
|
|
|
|
|