|
Then why the unnecessary cast?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hey what happend for your posts(are you toxxct? ) of course I give you 5 vote ,but its question for me why 1 without any explain?
|
|
|
|
|
Thanks a lot for the vote.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
You're welcome.
|
|
|
|
|
ThatsMe. wrote: I m using here SelectString but it is not working.
Why its not working?whats the return value?
|
|
|
|
|
CComboBox m_Cmb;
m_Cmb.SetCurSel(0);
|
|
|
|
|
Hi All,
i want to capture Video by using Web camera. For this i am using
capCreateCaptureWindow API to capture Video. but there is fatal error as
rror LNK2019: unresolved external symbol _capCreateCaptureWindowW@32 referenced in function "public: virtual int __thiscall CVideoCaptureDlg::OnInitDialog(void)" (?OnInitDialog@CVideoCaptureDlg@@UAEHXZ)
i am using this API in OninitDialog() function of DialogBox class. The code is as
BOOL CVideoCaptureDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
HWND hWndC = capCreateCaptureWindow((LPCWSTR)"My Capture Window",WS_CHILD | WS_VISIBLE,
0,0,240,240,m_hWnd, 0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Though i include header file Vfw.h and link lib file Vfw32.lib in my project.
So Is there any setting required to execute Above API correctly?
Thanks
Atul
|
|
|
|
|
I have written a simple Stash of string program, I used the Stash header file from the book "Think in C++", but when I tested the program, it didn't run well. The Stash can hold each line from the file, but when I cout each line from Stash, it outputs some unknow characters, could you please tell me why? And what's wrong in my program, many thanks.
#include <vector>
struct Stash {
int size;
int quantity;
int next;
unsigned char* storage;
void initialize(int size);
void cleanup();
int add(const void* element);
void* fetch(int index);
int count();
void inflate(int increase);
};
#include "stash.h"
#include <iostream>
#include <cassert>
#include <vector>
using namespace std;
const int increment = 100;
void Stash::initialize(int sz) {
size = sz;
quantity = 0;
storage = 0;
next = 0;
}
int Stash::add(const void* element) {
if(next >= quantity)
inflate(increment);
int startBytes = next * size;
unsigned char* e = (unsigned char*)element;
for(int i = 0; i < size; i++)
storage[startBytes + i] = e[i];
next++;
return(next - 1);
}
void* Stash::fetch(int index) {
assert(0 <= index);
if(index >= next)
return 0;
return &(storage[index * size]);
}
int Stash::count() {
return next;
}
void Stash::inflate(int increase) {
assert(increase > 0);
int newQuantity = quantity + increase;
int newBytes = newQuantity * size;
int oldBytes = quantity * size;
unsigned char* b = new unsigned char[newBytes];
for(int i = 0; i < oldBytes; i++)
b[i] = storage[i];
delete []storage;
storage = b;
quantity = newQuantity;
}
void Stash::cleanup() {
if(storage != 0) {
cout << "freeing storage" << endl;
delete []storage;
}
}
int main() {
ifstream in("stash.h");
Stash t;
t.initialize(sizeof(string));
string s;
int i = 0;
while(i < 6) {
getline(in, s);
cout <<"s:" <<s<<endl;
t.add(&s);
i++;
}
i = 0;
cout <<"------------------"<<endl;
while(i < 6) {
cout <<"+" <<*(string *)(t.fetch(i))<<endl;
i++;
}
|
|
|
|
|
quboo wrote: ...it outputs some unknow characters...
Are the strings nul terminated?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Suppose there is a class ClassTest with one argument constructor (no default constructor).
ClassTest
{
Public:
ClassTest(int i); //no default Cotr
}
A non heap array of objects of above class can be created as below
int ID1, ID2, ID3;
ClassTest ArrayClassTest [] = { ID1, ID2, ID3};
How to create an array of object of class ClassTest. If its Ctor takes two args
ClassTest
{
Public:
ClassTest(int i,int j); //no default Cotr
}
VIBIN
"Fool's run away,where angle's fear to tread"
|
|
|
|
|
vibindia wrote: int ID1, ID2, ID3;
ClassTest ArrayClassTest [] = { ID1, ID2, ID3};
How to create an array of object of class ClassTest. If its Ctor takes two args
ClassTest
{
Public:
ClassTest(int i,int j); //no default Cotr
}
ClassTest ArrayClassTest [] = {ClassTest( 1, 2), ClassTest( 1, 2)};
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
I used StringFormatFlagsDirectionVertical , but it is 90 degrees clockwise.
How to draw a string 90 degrees counter clockwise?
Thanks.
|
|
|
|
|
Matrix matrix;
matrix.RotateAt(/*stuff*/);
graphics.SetTransform(&matrix);
graphics.DrawString(/*stuff*/);
graphics.ResetTransform();
|
|
|
|
|
90 counter clockwise = 270 clockwise
Judy
|
|
|
|
|
Yes, it is.
But the origin is (0,0), so just rotate is not enough.
|
|
|
|
|
use the Matrix to translate, offset, scale, rotate, etc...
See my previous post in this thread.
|
|
|
|
|
Hi all,
I have a CString as follows,
CString str = "Some Data";
str.Format(_T("%s%d"), str, 123) );
If I use str as a standard string in c++, how can I do this format.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: If I use str as a standard string in c++, how can I do this format.
Use std::stringstream .
std::stringstream strstream;<br />
strstream << "Some data: " << 123;<br />
strstream.str();
CodingLover wrote: CString str = "Some Data";
str.Format(_T("%s%d"), str, 123) );
Doesn't this crash? You are passing str to str.Format function, and IMO %s doesn't know what's an object to copy it by value, so it's taking it by address. Format function will in turn modify this address to store new string!!
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Thanks for the infor. I'll try this and see.
Nibu babu thomas wrote: Doesn't this crash? You are passing str to str.Format function!!
Actually I dot this from MSDN and it gives only a compile error that, addition ) at the end.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: Actually I dot this from MSDN and it gives only a compile error that, addition ) at the end.
But it's clearly written in MSDN that this will cause unpredictable results. In fact given as a warning to avoid such code!
From MSDN:
The call will fail if the string object itself is offered as a
parameter to Format. For example, the following code:
CString str = "Some Data";
str.Format("%s%d", str, 123);
will cause unpredictable results.
Also note this...
MSDN:
When you pass a character string as an optional argument, you must
cast it explicitly as LPCTSTR.
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
I agree with you. 95% of the time you can get away with it but then it fails under certain circumstances. Lots o' fun to debug after you've coded it all over the place.
Convenient? yes.
However, it will piss you off when the unpredictable results come a calling.
Your advice to avoid it is good. However, alot of people will get enough positive behavior that they will convince themselves you are crying the "sky is falling".
They will live and learn someday.
|
|
|
|
|
bob16972 wrote: Your advice to avoid it is good. However, alot of people will get enough positive behavior that they will convince themselves you are crying the "sky is falling".
But it's documented not to do so!
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Don't get me wrong, I agree with you.
It just always confused me why people tend to shun good advice. I am always laughed at for being cautious since it tends to yield the same results as being reckless 9 times out of 10. I sometimes question whether I should just join in and throw caution to the wind, but that's just not me so I continue mind the documentation and take the safer road.
|
|
|
|
|
Ok, in such a case what should I do?
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: Ok, in such a case what should I do?
CString str;
str.Format("%s%d", _T( "Some Data" ), 123);
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|