|
I got it working!
thanks
BW
{insert witty/thought-provoking saying here}
|
|
|
|
|
Does it give any trick to include some little resource objects (like bitmaps) in the header file of a class?
I want to write a subclassed dialog with some buttons, but I don't want to add the button bitmaps (icons) to the resource file! I want to add this bitmaps in the header or cpp file, so that I can use the class very easy!
--
Nice greets, Daniel.
|
|
|
|
|
Funny I was thinking the same thing just the other day...
The way I see it, yes it has advantages...you don't have to include resource files with your project, just one CPP and one H file is all that are required...
I think if anything it'd be a bit (no pun intended) faster than using traditional resource bitmaps. You can avoid the call to LoadBitamp() or LoadImage()
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
You can but the size of bitmap you can include is limited.
Todd Smith
|
|
|
|
|
Any one knows how to convert a binary array to a decimal array in C++? Thanks.
mIchAel Liu
__________________________________________________________
The secret of business is to know something that nobody else knows.
|
|
|
|
|
what's a "binary array" ?
-c
All you have to do is tell the people they are being attacked, and denounce the opposition for lack of patriotism and exposing the country to danger.
-- Herman Goering, on how to control the public
|
|
|
|
|
... and what's a "decimal array" ?
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
1111 0000 1111 1000 = F0F0
is "111100001111000" a string?
Developing with C++ is like programming by the seat of your pants
|
|
|
|
|
Actually, I have a big integer value, larger than 80 bits which I can't use DOUBLE to hold this value and print it out. Now I have a array to hold this value by binary integers(0,1), then I need to convert it to another array which hold decimal integers(0 to 9) to present this large value. Because I can't use power of 2 ( if I have 256 bits, then I can't hold the it), I have touble to convert it.
mIchAel Liu
__________________________________________________________
The secret of business is to know something that nobody else knows.
|
|
|
|
|
CString * pArray;
int iArraySize = 4;
for (int i =0; i< iArraySize; i++)
{
pArray[i] = "abc";
}
It chokes at the line where I assign it "abc" . Previously I had assigned it 2*i, so I thought that since i is int and p String, thats causing the crash. But the above is not happy.
Whats wrong?
Appreciate your help,
ns
|
|
|
|
|
Why don't you assign the array like that:
const int iArraySize = 4;
CString Array[iArraySize];
for (int i=0; i < iArraySize; i++)
{
Array[i] = "abc";
}
<pre>
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Fine. Thanks for that!
How will I pass this array into a function?
myFunc( CString * pArray)
called as
myFunc(pArray)
? ????
Appreciate your help,
ns
|
|
|
|
|
eh... If I get you right you could call it as myFunc(&pArray), I think
|
|
|
|
|
try this:
void Arr(CString pArray[], int intArrCount)
{
for(int i=0; i<intArrCount; i++)
pArray[i] = "abc";
}
you simply pass the array like that:
CString array[4];
Arr(array, 4);
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Exactly the info I needed. Many many thanks!
Appreciate your help,
ns
|
|
|
|
|
I hope you are not writing software I will install for any reason on my computer in the future.
I am not bashing you, I am just figuring out you don't know what a pointer is. And it worries me.
sometimes it helps to look at the IL generated code
a MS guy on develop.com "answering" .NET issues
|
|
|
|
|
Well,
I am just trying to pattern it after a char array which we pass in by name as
myFunc(myArray)
where its
myFunc(char * myArray)
(Am I wrong about this too? )
Appreciate your help,
ns
|
|
|
|
|
ns wrote:
I am just trying to pattern it after a char array
Actually, you're better off using the MFC collection class CStringArray which seems ideally suited for your purpose, since you don't have to worry about freeing up storage, knowing its length, etc. Here's what I mean:
CStringArray arrayOfStrings;
for (long nIndex=0; (nIndex < 4); nIndex++) {
arrayOfStrings.Add ("abc");
}
myFunction (arrayOfStrings);
...
void myFunction
(CStringArray& stringArray)
{
}
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Then why don't you help the guy find out what a pointer is, instead of just telling him that he can't program?
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
I think there are a couple fundamental concepts you're missing here, so I'll try to explain it... hopefully this makes sense.
In a nutshell, your assignment of pArray[i] = "abc" fails because pArray isn't pointing at anything useful in your sample code. Your first line creates the pointer, but at that point it's merely a pointer to a CString; it's not really a CString yet.
A CString is an object, which is very different from the char data type. What's the difference between a CString pointer and a char pointer? You can do this with a char pointer:
char *c;
c = "abc";
When the compiler sees a literal string like "abc", it actually creates that string as a globally-accessible char array variable, which can then be "pointed at". This happens automatically for you, and you're not even really aware that it's happening. The char pointer in the above example can then point at that global variable because the datatypes match. It's a character array located at some address in memory, and you've got a character pointer that can store that address. Essentially, the above code is equivalent to doing this:
char cArray[4];
char *c;
cArray[0] = 'a';
cArray[1] = 'b';
cArray[2] = 'c';
cArray[3] = 0;
c = cArray;
Obviously this is a pain in the ass to code, so conveniently C and C++ compilers handle character strings automatically for you.
Okay, so now where does your CString come in? A CString is a C++ class that wraps character arrays; by itself it's not actually an array of characters. It's not a primitive datatype like char or int. If you tried the following, you'd get a compiler error:
CString *p;
p = "abc";
In this case, p is supposed to be pointing to a CString. "abc" as you learned is actually an array of characters, exactly 4 bytes long. You can't convert from an array of characters to a CString pointer; they're incompatible. You need to point at an actual CString object.
Knowing that, why does your code compile? Your code compiles fine because you access the pArray pointer through the reference operator []. This special operator lets you treat the pointer as a sort of index into an array. You can move anywhere within the array by just changing the index. However, there's a problem in your example. Your pArray isn't pointing at anything. You never initialized pArray to point to an array of CString objects. pArray is pointing at some garbage value off in no-man's land in memory. pArray[i] is trying to move around in that range, and it throws an access violation.
So, the bottom line is you need to initialize your pArray variable to actually point at some valid location in memory. You can follow some of the other examples, or even do something like this:
int iArraySize = 4;
CString *pArray = new CString[iArraySize];
for( int i = 0; i < iArraySize; i++ )
{
pArray[i] = "abc";
}
delete []pArray;
In this case, pArray points to an array of CString objects, dynamically allocated on the heap. The pointer can access each of the four through the reference operator.
Ty
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein
|
|
|
|
|
Many thanks. That really cleared up things for me.
Appreciate your help,
ns
|
|
|
|
|
I'm worried, this is commercial s/w you're developing?
Developing with C++ is like programming by the seat of your pants
|
|
|
|
|
How do you make a number (integer) into a CString?
Appreciate your help,
ns
|
|
|
|
|
CString str;
str.Format("%i", iFoo);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank you. Any thoughts on my CString * pArray thread? Its quite short and probably obvious to you...
Appreciate your help,
ns
|
|
|
|