|
Please think about your design... otherwise, declare the classes "friend" as appropriate. For example, if you want to grant class A access to class B private areas, class B must state that class A is a friend.
Run-time - if you want access to the live data, well, you'd need to think about where you want the data and how the object instances know of the other.
Charlie Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
My son's PDA is an M249 SAW.
My other son commutes in an M1A2 Abrams
|
|
|
|
|
What is the "physical" relationship between class A and B ?
can't you pass a pointer a A to class B ?
|
|
|
|
|
I can do that but i think that the compiler gets confused when i do a double include...
e.g.
Class A : public CDialog
#include B.h
SetDlgPtr(this);
Class B : public CWnd
#include A.h
void B::SetDlgPtr(CA * pCA)
{}
|
|
|
|
|
This is a common problem. The solution is simple. In one of the .h files, don't #include the header file of the other class. Instead just put a forward declaration. For example, in b.h, remove #include A.h and put "Class A;". Then in b.cpp put the #include a.h.
|
|
|
|
|
what about creating a static pointer in the classes that you want to be able to use from any other class/function. then all you need to do is include the header for the class and voila!. For example:
<br />
<br />
class One<br />
{<br />
public:<br />
One(void);<br />
~One(void);<br />
public:<br />
void oneFunction();<br />
int oneX;<br />
<br />
};<br />
<br />
class Two<br />
{<br />
public:<br />
Two(void);<br />
~Two(void);<br />
public:<br />
static Two* m_ptrTwo;
<br />
void twoFunction();<br />
int twoX;<br />
};<br />
<br />
and the body...
<br />
<br />
#include "hello.h"<br />
<br />
<br />
Two*Two::m_ptrTwo = NULL;
<br />
Two::Two(void)<br />
{<br />
m_ptrTwo = this;
}<br />
<br />
Now we can use the pointer 'm_ptrTwo' to call anything in the public interface of the class Two. For example:
<br />
One::oneFunction()<br />
{<br />
Two::m_ptrTwo->twoFunction();<br />
Two::m_ptrTwo->twoX = 1234;<br />
}<br />
<br />
|
|
|
|
|
I have seen some folks using HeapAlloc instead of malloc, how is that different?
thanks!
|
|
|
|
|
All my literature states they are basically the same. I guess portability would be the only difference. Malloc does not require a specific OS. HeapAlloc does.
But correct me if I'm wrong...
|
|
|
|
|
They are effectively the same. However malloc is in the C runtime libraries, so if you use it your application has to link in the C runtime. HeapAlloc is defined in kernel32.dll, so if you want to reduce the code size of your application you can avoid linking to the C runtime and use HeapAlloc to allocate memory.
Using HeapAlloc may make your code less portable if that is a concern for you.
I hope this helps.
Deus caritas est
|
|
|
|
|
Portability across different OSes or even across different flavours of Windows?
thanks!
|
|
|
|
|
Across different OSs.
Deus caritas est
|
|
|
|
|
Every process creates a default process heap.
This is the heap used by malloc/new/...
Aside from using the process heap, malloc/new/... (can) add other optimization features such as lookaside lists, small-block heaps, ...
HeapAlloc is the low level way to alloc a block of memory on a heap.
Some people will create a number of heaps within a program, each designed to hold a specific type of data or a specific group of data. This can help reduce heap fragmentation and speed up parts of some applications.
I use separate heaps for different types of data (e.g. all string buffers in one heap, all blobs in another, ...).
I use separate heaps for different groups of data (e.g. all database column data in one heap, all network packets in another, ...).
This just touches on the subject.
In the end it provides the developer with just another tool.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I have tried so many times to create a new report using crystal report 11 by incorporating a template with vc++. I didnot find any article or sample code which is written in c++. But after some effort I got to know that there is a function called put_ReportTemplate() which is used for this task. I already know how to create a new report without using a template.
If anybody can help me by supplying a vc++ code, it will greatly appreciated.
Jagathucsc
|
|
|
|
|
hello.. i am using a listctrl box to display the directories on the FTP server.. the directory listing is successful when first connected to the server. but when refresh button is pressed, the directory listing fails. the refresh button uses the same code that is used for the directory listing. can anyone tell me what to do??
thanks..
vijay aroli
|
|
|
|
|
Can you post the refresh code ? Can you tell us what fails and how it looks like ?
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
hello sir!!i am new to MFC programming and i am developing an FTP client. the code is as shown below. i call the same code when i first connect to the FTP server and the code does the directory listing successfully. but when i call the same code to refresh the directory listing, the code fails.. just see where i am doing the mistake..
//delete all items in the listCtrl
m_cListDir.DeleteAllItems();
try
{ CString pStrptr;
CString str;
BOOL nRC = pConnect->GetCurrentDirectory(pStrptr);
pStrptr.Format("%s is the current directory", pStrptr);
MessageBox(pStrptr, " Info", MB_OK);
// use a file find object to enumerate files
CFtpFileFind finder1(pConnect);
pConnect->SetCurrentDirectory(pStrptr);
BOOL bWorking = finder1.FindFile( _T("*"));
if(bWorking)
{
int i = 0;
CString str;
CTime time;
while (bWorking)
{
bWorking = finder1.FindNextFile();
//display the file name, file size and last modified in a listctrl box
str.Format("%u byte(s)",finder1.GetLength());
m_cListDir.InsertItem (i,((LPCTSTR) finder1.GetFileTitle()));
m_cListDir.SetItemText(i,1,(LPCSTR)str);
finder1.GetLastAccessTime(time);
str.Format("%d-%d-%d",time.GetDay(),time.GetMonth(), time.GetYear());
m_cListDir.SetItemText(i++,2,(LPCSTR)str);
}
}
else
{
CString str;
MessageBox("'/' is empty", "Info", MB_ICONINFORMATION);
str.Format("Error : %s", GetLastError());
MessageBox(str, "Error",MB_ICONERROR);
}
}
catch (CException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
MessageBox("Cannot retrive the server drive information","ERROR!",MB_ICONERROR);
pEx->Delete();
}
vijay aroli
|
|
|
|
|
aroli vijay wrote: ...when refresh button is pressed, the directory listing fails.
Which means what exactly? Set a breakpoint in your code and narrow the problem down to just a few statements.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
hi!! thanks to everyone. the problem has been solved. i didnot close the find file object after enumerating all the files once. that was the cause for the problem. thanks to everyone
vijay aroli
|
|
|
|
|
I am looking for the most basic example of word automation. I have looked at all of them on this webiste and they are all too complex for me. All I need is couple of lines of code (no interface at all) on how to create a completely blank word file with the path specified by me (like c:\\myfile.doc). How can I do that??
Thanks in advance!
|
|
|
|
|
Search microsoft MSDN site for:
Q180616: HOWTO: Use Automation to Create & Show a PowerPoint Presentation
Q178784: HOWTO: Use Automation to Open and Print a Word 97 Document
Old articles, but easiest way. Searching for automate brings nice examples as well.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
where can I find the msword.h file??
-- modified at 9:54 Friday 18th August, 2006
|
|
|
|
|
great_tommy wrote: where can I find the msword.h file??
It, along with a .cpp file, is created by ClassWizard when you import the type library.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
VC6.0
My Application: the same window explore
I cut 2 files in window explore, then in my application
I paste them there. How to know that:
1. 2 files are cutting
2. Path is exist
3. ListCtrl control: how to sort folders are top, files are bottom
Thanks
|
|
|
|
|
|
VC6.0
My Application: the same window explore
I cut 2 files in window explore, then in my application
I paste them there. How to know that:
1. 2 files are cutting
2. Path is exist
3. ListCtrl control: how to sort folders are top, files are bottom
Thanks
|
|
|
|
|
Hi,
plz tell me. how can i read excel sheet using visual c++ MFC.
i have write following code but it reads only three rows.
void CReadExcelDlg::OnButton1()
{
CDatabase database;
CString sSql;
CString sItem1, sItem2,sItem3;
CString sDriver;
CString sDsn;
CString sFile = "ReadExcel.xls"; // the file name. Could also be something like C:\\Sheets\\WhatDoIKnow.xls
// Clear the contents of the listbox
m_ctrlList.ResetContent();
sDriver = GetExcelDriver();
if( sDriver.IsEmpty() )
{
// Blast! We didn´t find that driver!
AfxMessageBox("No Excel ODBC driver found");
return;
}
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile);
TRY
{
database.Open(NULL,false,false,sDsn);
CRecordset recset( &database );
sSql = "SELECT field_1, field_2 "
"FROM demo_table "
"ORDER BY field_1";
recset.Open(CRecordset::forwardOnly,sSql,CRecordset::readOnly);
while( !recset.IsEOF() )
{
// Read the result line
recset.GetFieldValue("field_1",sItem1);
recset.GetFieldValue("field_2",sItem2);
// recset.GetFieldValue("field_3",sItem3);
// Insert result into the list
m_ctrlList.AddString( sItem1 + " --> "+ sItem2 );
// Skip to the next resultline
recset.MoveNext();
}
// Close the database
database.Close();
}
CATCH(CDBException, e)
{
// A database exception occured. Pop out the details...
AfxMessageBox("Database error: "+e->m_strError);
}
END_CATCH;
}
////plz help me
|
|
|
|