|
Hi,
I am working on a MDI application. I use CDaoDatabase (so I include AFXDAO.h) for my application. After doing some manipulation wiht the data, I close my dialog box, which has a "Close" button with the ID "IDCANCEL". So, when I close my dialog box, the whole application is getting closed.
But the dialogs which are not using this afxdao.h is working fine. That means, it closes only the dialog and not the application.
Could anyone, please help me in this regard.
PS: I am using VC++ 6.0.
Thanks in advance.
Regards
saravana
|
|
|
|
|
Put a breakpoint on CMainFrame::OnClose()...then in debug mode look at the call stack to understand why you reach that point of the code.
Hope it helps
Russell
|
|
|
|
|
may be the dialog sends PostQuitMessage() , what type of dialog is that and it is dervied from ?
If u can Dream... U can do it
|
|
|
|
|
Hi I'm trying to write a function that will return an array this is what I have
unsigned char sendbuf[6];
sendbuf[0] = myclass::makesendbuffer(SendPacket);
unsigned char myclase::makesendbuffer(Packet SendPacket){
unsigned char sendbuf2[6];
if(SendPacket.data < 0){
SendPacket.data += 65536;
}
sendbuf2[0] = SendPacket.data % 256;
sendbuf2[1] = floor(double(SendPacket.data/256));
sendbuf2[2] = SendPacket.address % 256;
sendbuf2[3] = floor(double(SendPacket.address/256));
sendbuf2[4] = SendPacket.command;
return *sendbuf2;
}
The return is just giving me the value of the first element and everything else is not used. Any ideas of what I'm doing wrong here would be great thanks!
Simon
|
|
|
|
|
simoncoul wrote: return *sendbuf2;
and
simoncoul wrote: unsigned char myclase::makesendbuffer(Packet SendPacket)
the functions needs to return an unsigned char , not a pointer (to an array) ...something could be wrong...
I think that you want to pass all the array...then:
unsigned char* myclase::makesendbuffer(Packet SendPacket)<br />
and then something like
return sendbuf2;
But you can't return a pointer to a local variable if you want that everything runs well....
The solution could be pass to the function a pointer to a vector and fill it inside the function
-- modified at 14:14 Wednesday 8th August, 2007
Russell
|
|
|
|
|
Thanks for the help I got it to work
unsigned char sendbuf[6];
myclass::makesendbuffer(SendPacket, sendbuf);
unsigned char myclase::makesendbuffer(Packet SendPacket, unsigned char sendbuf2[6]){
unsigned char sendbuf2[6];
if(SendPacket.data < 0){
SendPacket.data += 65536;
}
sendbuf2[0] = SendPacket.data % 256;
sendbuf2[1] = floor(double(SendPacket.data/256));
sendbuf2[2] = SendPacket.address % 256;
sendbuf2[3] = floor(double(SendPacket.address/256));
sendbuf2[4] = SendPacket.command;
return sendbuf2;
}
Made much for sense to send a pointer to the array and do stuff to in in the function then what ever I was trying to do!
|
|
|
|
|
And this very code does work as expected?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Yeah that code works perfectly, since I'm sending the point of sendbuf, I am able to manipulate it as if it was being declared inside of the function. I dunno if this is the correct C++ way of doing it but it makes sense to me(but I know know C).
|
|
|
|
|
I just asked, because your format of the second parameter is, well, uncommon.
And you are using the identifier sendbuf2 twice.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
simoncoul wrote: I dunno if this is the correct C++ way of doing it but it makes sense to me
hmmm...
Maybe take another look
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
simoncoul wrote: unsigned char myclase::makesendbuffer(Packet SendPacket, unsigned char sendbuf2[6])
{
unsigned char sendbuf2[6];
There's no way you could have gotten this to compile.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
int main(void){
unsigned char sendbuf[6];
myclass::makesendbuffer(SendPacket, sendbuf);
}
void myclass::makesendbuffer(Packet SendPacket, unsigned char sendbuf[6]){
if(SendPacket.data < 0){
SendPacket.data += 65536;
}
sendbuf[0] = SendPacket.data % 256;
sendbuf[1] = floor(double(SendPacket.data/256));
sendbuf[2] = SendPacket.address % 256;
sendbuf[3] = floor(double(SendPacket.address/256));
sendbuf[4] = SendPacket.command;
}
That was what I finally ended up with and it works, is there a problem with it that u can see?
|
|
|
|
|
simoncoul wrote: is there a problem with it that u can see?
No, assuming all of the values being assigned to sendbuf are between 0 and 255.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Yeah they are!
Thanks for all the help guys!!
|
|
|
|
|
you are wellcome...
but
simoncoul wrote: unsigned char sendbuf2[6];
cut this line
and I think that is better if
void myclase::makesendbuffer(Packet SendPacket, unsigned char* sendbuf2)
Russell
|
|
|
|
|
ok Thanks I see what u mean doesn't make sense to say sendbuf[6].
Thanks again!
|
|
|
|
|
simoncoul wrote: Any ideas of what I'm doing wrong here would be great thanks!
You are programming in C. This might or might not be intended.
The C++-way would be a std::vector .
BTW: You can easily hand that over to C-Functions by getting the address of the first element: &vec[0] .
I assume that you want to use C(ish) Code.
I see two errors:
1) You are allocating the sendbuf in your function on the stack. The memory will be freed on leaving the function. Later access to it will fail. When you don't expect it. Catastrophically.
You either need to allocate it outside and hand a pointer in, or you need to allocate it in the function on the heap and return the pointer you got (And delete it after use!).
2) Your code explicitly states that it is returning exactly one unsigned char.
What you want is returning the array of chars, I think.
So you need to return a pointer to the first element of the array and the length. Alternatively, when the length is always 6, you could define a datatype of 6 unsigned chars to be a sendbuf , and return only the sendbuf -pointer.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
How can I get a point to the document class. I tried copying from the view class header and body and putting it in myclass would not work (changing CControlView:: to myclass: and I got error C2143: syntax error : missing ';' before '*'
header:
public:
CControlDoc* GetDocument();
body:
CControlDoc* CControlView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CControlDoc)));
return (CControlDoc*)m_pDocument;
}
cwbenson
|
|
|
|
|
cwbenson wrote: and I got error C2143: syntax error : missing ';' before '*'
And did you remember to also include the doc's header file in myclass.h ?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
cwbenson wrote: How can I get a point to the document class.
You probably need to give it to your class.
I have a FrameWnd creating a few Views in OnCreateClient, and it gets the Doc and the View in CCreateContext.
Most of the other classes that need Document-Access are somehow children of the view and can get its adress to ask it for the Document.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
I have made it in one project. Quite easy.
#include "CMyDoc.h"
CMyDoc* pMyDoc;
void CMyMainView::OnInitialUpdate()
{ CScrollView::OnInitialUpdate();
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
extern CMyDoc* pMyDoc;
pMyDoc = GetDocument ();
return;
}
#include "stdafx.h"
CMyDoc* pMyDoc_InSecondView;
CMySecondView::CMySecondView()
: CFormView(CMySecondView::IDD)
{
extern CFPSDoc* pMyDoc;
pMyDoc_InSecondView = pMyDoc;
}
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
hi, i createad a MFC dialog with a worker thread, my worker thread needs to communicate with the dialog, so i decide to use messages.
project name:MultithreadingTest
in MultithreadingTest.h, i defined 2 user message.
// MultithreadingTest.h : main header file for the PROJECT_NAME application
//
#define WM_USER_GET_DATA WM_USER+0x100
#define WM_USER_THREAD_ABORTED WM_USER+0x101
....
// Implementation
afx_msg LRESULT OnGetData(WPARAM wParam, LPARAM lParam);// WM_USER_GET_DATA handler
afx_msg LRESULT OnThreadAborted(WPARAM wParam, LPARAM lParam););// WM_USER_THREAD_ABORTED handler
DECLARE_MESSAGE_MAP()
then in MultithreadingTest.cpp,
// MultithreadingTest.cpp : Defines the class behaviors for the application.
//
// CMultithreadingTestApp
BEGIN_MESSAGE_MAP(CMultithreadingTestApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
ON_MESSAGE (WM_USER_GET_DATA, OnGetData)//<-ERROR hee
ON_MESSAGE (WM_USER_THREAD_ABORTED, OnThreadAborted)//<-ERROR thee
END_MESSAGE_MAP()
I got some error at ON_MESSAGE(...)
error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CMultithreadingTestApp::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' None of the functions with this name in scope match the target type
what's the cause??
|
|
|
|
|
No problem with VS6. Are you using VS2005 perhaps?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Then the function's prototype has apparently changed.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|