|
The only reason you get 4 (4 bytes) for sizeof (cArray1) is that sizeof actually measures the size of the cArray1, which is a pointer. And as you probably know.... a size of a pointer is 4 bytes (in your compiler anyway...).
char *cArray1 = new char[]; //very bad idea! No array size specified.
instead, use fixed sized buffer: char cArray1[ARR_SIZE];
This one you can measure:
size_t iArraySize = sizeof (cArray1) /sizeof(*cArray1) ;
--BlackSmith--
/*The roof is on fire, we don't need no water, let the MF burn*/. BHG.
|
|
|
|
|
Ok, I really feel dumb now hehe. I was out of code for a while so I totally overlooked that fact about the operator referring to the pointer. Thanks for the help. I just used strlen and it works fine. Thanks for all the help!
|
|
|
|
|
Well...
Your array is actually a pointer, so the function sizeof() will always return
4 because that's the size of a pointer. Getting the number of elements in an
array is a different thing.
Now, I think you should do this some other way. First of all, why would you want to give the user unlimited input length? Just specify a limit and save
yourself a headache.
Second, maybe it could help to know the length of the array before allocating any memory... but, well, what is it you want to do?
Aritosteles
|
|
|
|
|
Hi all,
If I use VS.NET to create a dialog application and say I add a ListCtrl with the designer and set the style to REPORT.
So where is this information stored, does the designer generate code? For example I would look for some code in my project containing LVS_REPORT :
m_myListCtrl.Create(<br />
WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT,<br />
CRect(10,10,400,200), pParentWnd, 1);
but that code does not exist in my project!
Thanks in advance.
Soliant | email
"The whole of science is nothing more than a refinement of everyday thinking." -Albert E.
|
|
|
|
|
There's no generated code. The dialog layout is defined by so-called 'dialog template' stored in program resources. When you invoke dialog box, Win32 API (not MFC) creates the dialog box and populates it with controls.
The code you'll see in MFC app is responsible for creating CWnd-derived objects mapped to their Win32 API counterparts (HWNDs). Look in DoDataExchange for this.
Tomasz Sowinski -- http://www.shooltz.com
** Putt knot yore thrust inn spel chequers. **
|
|
|
|
|
if u want to just change the style do this:
m_cListCtrl.ModifyStyle(0, LVS_REPORT);
in the constuctor or initdialog();:
Ashok Singh
<west end="" india="">
|
|
|
|
|
Hi
another question
why don't the following code compile?
extern CFile cfile;
void *data;
CFile::Open(m_Pathname1,modeRead);
data = cfile.Read(0,cfile.GetLength());
i get the error:
error C2440: '=' : cannot convert from 'unsigned int' to 'void *'
Conversion from integral type to pointer type requires einterpret_cast, C-style cast or function-style cast
(BTW, what does extern do! Otherwise CFile::Read(etc) also works)
thanks
|
|
|
|
|
extern CFile cfile;
CFile::Open(m_Pathname1,modeRead);
DWORD dwFileLength = cfile.GetLength();
BYTE *data = new BYTE[dwFileLength];
DWORD dwBytesRed = cfile.Read(data,dwFileLength);
Martin
--------------------------------------------
C'mon we all know computers are experimental devices and should only be used for playing games.
Using them for alternative stuff like business, is clearly not using them for what they are intended.
Colin Davies
|
|
|
|
|
tx, this works
what does BYTE *data = new BYTE[dwFileLength] do?
|
|
|
|
|
It allocates memory to hold data from the file. When you will finish using it, then you have to free that memory with:
delete [] data;
I think you have to read little bit more about C++.
Martin
--------------------------------------------
C'mon we all know computers are experimental devices and should only be used for playing games.
Using them for alternative stuff like business, is clearly not using them for what they are intended.
Colin Davies
|
|
|
|
|
|
Jenny2 wrote:
ok hero
Martin
--------------------------------------------
C'mon we all know computers are experimental devices and should only be used for playing games.
Using them for alternative stuff like business, is clearly not using them for what they are intended.
Colin Davies
|
|
|
|
|
I am trying to write two classes that work togeather. One is a color storage class (CSoilColor) and a lookup table class (CColorChart). When I added a member variable to CSoilColor to hold a pointer to a CColorChart object, the compiler choked. Each header file has an include to each other so they should recognize each other, but from the error they apparently do not. Even though the comiler chokes, the development environment recognizes the CColorChart member variable because it allows me access to the CColorChart's members in the CSoilColor's cpp file.
Here are the class definitions:
#include "SoilColor.h"
class CColorChart
{
public:
bool IsValidColor(int nHue, int nValue, int nChroma);
bool GetHue(int nHueID, CString& sHueName);
bool GetRGBcolor(CSoilColor SC, COLORREF* RGBcolor);
void InitChart();
bool GetColorName(int nHue, int nValue, int Chroma, CString& sColorName);
CColorChart();
virtual ~CColorChart();
private:
CString Hue[nMAXHUES];
COLORCHART Chart[nMAXHUES][nMAXVALUES][nMAXCHROMAS];
};
=====================================================
#include "ColorChart.h"
class CSoilColor
{
public:
CSoilColor();
virtual ~CSoilColor();
int GetChroma();
int GetValue();
int GetHue();
COLORREF GetRGBcolor();
bool SetColor(int nHue, int nValue, int nChroma);
private:
CColorChart* m_pColorChart; //ERROR HERE
int m_nHue;
int m_nValue;
int m_nChroma;
};
I think it is probably a simple error, but I am going crazy trying to find it! If anyone has Ideas, please let me know. Thank You.
|
|
|
|
|
Use forward declaration instead of #include:
class CColorChart;
class CSoilColor
{
...
CColorChar *m_pColorChart;
};
Tomasz Sowinski -- http://www.shooltz.com
** Putt knot yore thrust inn spel chequers. **
|
|
|
|
|
Now that you mention it I did know that at one point.
Thank you very much.
|
|
|
|
|
hi
if i work in VC for a while, i am unable to access the toolbar list that appears whenever you type something like CString p.
is it lack of memory? If i restart my PC it works again...
tx
|
|
|
|
|
Simple answer:
VC is screwy, and has a habit of doing that just to annoy you
usually it'll stop working if there is a syntax error somewhere in your code.
Visual Assist (http://www.wholetomato.com/[^]) is a handy Visual Studio addin that fixes lots of these problems
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
benjymous wrote:
http://www.wholetomato.com
Where does that obsession from different kind of fruits and vegetables come from?
Martin
--------------------------------------------
C'mon we all know computers are experimental devices and should only be used for playing games.
Using them for alternative stuff like business, is clearly not using them for what they are intended.
Colin Davies
|
|
|
|
|
The phrase "Help me! I'm turning into a grapefruit!" was something utterly non-sensical that I picked up the top of my head to go as the text to a scrolly screensaver on my University Linux account. It drew lots of amusement from people who saw it, so it ended up as my email sig as well (and eventually when I came to create a decent website for myself, I thought up the name "grapefruitopia" as it rolls off the tongue nicely, is pretty bizarre, but easy to remember.)
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
When Intellisense stops working, it's usually due to a syntax error earlier in the function. However, I have seen it just stop showing the popup list (the VC status bar indicates that Intellisense is otherwise operating fine), and in that case just close & restart VC.
--Mike--
Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Do you know why is that every time that i use this code the intelisense stops working. (the code work just fine)
rs->Open(_variant_t(sql), conn.GetInterfacePtr(), adOpenDynamic, adLockOptimistic,adCmdText);
Casa.Sapo.pt
|
|
|
|
|
I need to develop an application that performs a query on
a database and stores the query output in an Excel document.
How can I develop the Excel document management (file creation
and data storage) ?
Thanks a lot
|
|
|
|
|
You need to use Ole Automation....
Best Regards
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
Use DAO, ODBC (.csv, .xls)
Or export to the Excel xml file format (you'll get the reference with this key search on MSDN : "Microsoft Office Drawing File Format". Using xml allows you to create charts or pivot tables as well.
And if you need the .xls format itself, yes the simplest way to do it is through Automation, at least if you are running Windows.
Final point, you may buy a finished product (softartisan).
Or crack the binary file format.
And I swallow a small raisin.
|
|
|
|
|