|
or call API PostQuitMessage()
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
ThatsAlok or call API PostQuitMessage()
Yes, and he still needs to break out of the message pump loop when this condition is recognised.
|
|
|
|
|
Hi, i hav made a mdi project in vc++ 6.0. Now i want to create a dll for this whole project. I hav searched on net but found only examples which show how to make dll for few methods. How can i create a dll for whole project including all classes?
|
|
|
|
|
I don't really understand what you are trying to do . You want to convert your exe into a dll ? For what reason exactly ?
|
|
|
|
|
Cedric Moonen wrote: You want to convert your exe into a dll ?
Someone must have written an article about this, or there is a rogue teacher somewhere. I keep coming across questions where developers think that their application should be a DLL rather than EXE. Then they want to start it from a console app and let it run independently.
|
|
|
|
|
As suggested by the name, a DLL is a library (of functions or classes). So, generally speaking your question doesn't make sense (i.e. is your whole project just a collection fo reusable functions or classes?).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
So, you succeeded in exporting functions, but don't know how to export classes from a DLL? See DLLs are simple: Part 2[^]
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
I'm getting the below exception and code given below.
Exception : "Windows has triggered a breakpoint in WBEventsSheetCalculate.exe.
This may be due to a corruption of the heap, which indicates a bug in WBEventsSheetCalculate.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while WBEventsSheetCalculate.exe has focus.
The output window may have more diagnostic information."
Any help is appreciated. Thanks in advance.
Excel::_ApplicationPtr xl;
Excel::WorkbooksPtr bookPtr;
class ExcelBookEventHandler : public IDispEventSimpleImpl<1, ExcelBookEventHandler, &__uuidof(Excel::WorkbookEvents)>;
{
BEGIN_SINK_MAP(ExcelBookEventHandler)
SINK_ENTRY_INFO(1, __uuidof(Excel::WorkbookEvents), 0x0000061b, &ExcelBookEventHandler::SheetCalculate, &SheetCalculateInfo)
END_SINK_MAP()
void _stdcall SheetCalculate(IDispatch *pDisp)
{}
}
std::vector<excelbookeventhandler> bookHandler;
class ExcelAppEventHandler : public IDispEventSimpleImpl<1, ExcelAppEventHandler, &__uuidof(Excel::AppEvents)>
{
public:
ExcelAppEventHandler(bool& doneFlag) : done_(doneFlag)
{
done_ = false;
}
// The sink map maps event handler functions to the events they handle
BEGIN_SINK_MAP(ExcelAppEventHandler)
SINK_ENTRY_INFO(1, __uuidof(Excel::AppEvents), 0x0000061f, &ExcelAppEventHandler::WorkbookOpen, &WorkbookOpenInfo)
END_SINK_MAP()
// When I create new excel workbook, this event gets fired.
void _stdcall WorkbookOpen(Excel::_Workbook *book)
{
ExcelBookEventHandler calc;
bookHandler.push_back(calc);
int val = xl->Workbooks->Count;
bookHandler[val-1].DispEventAdvise(book);
cout<<"Inside Workbook Open";
}// here, I'm getting the exception
int _tmain(int argc, _TCHAR* argv[])
{
CoInitializeEx(0, COINIT_MULTITHREADED);
{
if (SUCCEEDED(xl.GetActiveObject(__uuidof(Excel::Application))))
{
bookPtr = xl->Workbooks;
if(bookPtr)
{
bool flag=true;
BookCount = bookPtr->Count;
for(int i=1 ; i<=BookCount ; i++)
{
BookName = bookPtr->Item[i]->Name;
ExcelBookEventHandler calc;
bookHandler.push_back(calc);
}
}
}
for (int i=1 ; i<=BookCount ; i++)
{
bookHandler[i-1].DispEventAdvise(xl->Workbooks->Item[i]);
}
ExcelAppEventHandler handler(done);
if(SUCCEEDED(handler.DispEventAdvise(xl)))
{}
}
CoUninitialize();
return 0;
}
|
|
|
|
|
You really need to format your code using the <pre></pre> tags. Clicking 'code block' above the edit box when posting will do just that with selected text.
Have a look before you're posting code in order to verify that it looks as it should. You have used the std::vector template, but the template arguments are lost since they have been interpreted as HTML tags so the rest of us cannot figure out whether the map contains ExcelBookEventHandler objects or references to such objects.
North 2009 wrote:
void _stdcall WorkbookOpen(Excel::_Workbook *book)
{
ExcelBookEventHandler calc;
bookHandler.push_back(calc);
int val = xl->Workbooks->Count;
bookHandler[val-1].DispEventAdvise(book);
cout<<"Inside Workbook Open";
}
You've got to think this through....
You're creating an ExcelBookEventHandler object on the stack and adding it to the map; now it's really interesting whether the map holds real objects or references. The local ExcelBookEventHandler object will be destroyed when execution returns from WorkbookOpen() .
What does the call stack look like when you get the exception?
North 2009 wrote:
CoInitializeEx(0, COINIT_MULTITHREADED);
Why?
Are you really using multiple threads from a COM perspective? I would guess that you're not since nothing in the code you've posted suggests that you are.
What happens if you change this to using an ordinary STA instead, e.g.
::CoInitialize( NULL ); or
::CoInitializeEx( NULL, COINIT_APARTMENTTHREADED ); ?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi all, I ahve 2 questions.
First:
I would like to know how to convert the text from file into the format below.
In my program,
UINT Test_a(LPVOID lParam)
{
CStdioFile f1(_T("C:/abc/t1.txt"), CFile::modeWrite|CFile::OpenFlags::modeCreate|CFile::shareExclusive);
CString f1_txt;
......
f1_txt.Format("%le %le %le\n", x, y, z);
f1.Write(f1_txt, f1_txt.GetLength());
.....
f1.Close();
}
UINT Test_b(LPVOID lParam)
{
CStdioFile f2;
f2.Open((_T("C:/abc/t1.txt"), CFile::modeRead | CFile::shareExclusive);
CString rdtxt;
//how to read the text from the file t1 and convert it to "%le %le %le\n", &x, &y, &z format?
Can i do something like this?
while(f2.ReadString(rdtxt) != NULL)
{
rdtxt.Format("%le %le %le\n", &x, &y, &z);
....
}
f2.Close();
}
Second:
For CFile.Read. When i put CFile::shareExclusive in my f1.Open, i will have error. The error is
Debug Assertion Failed!
Program: c:\Documents and settings\...\GUi.exe
File:f:\dd\vctools\crt_bld\self_x86\crt\src\fscanf.c
Line:52
Expression:(stream != NULL)
When i change shareExclusive to shareDenyNone or shareDenyWrite, then the program work. How can i solve this? I don't other to open the file when i am running/using the file in my C++ program. The file is quite big, about 8M.
My program code:
text.txt file is created above my program using CStdioFile f2(_T("C:/abc/test.txt), CFile::modeWrite|CFile:shareExclusive);
CStdioFile f1;
CString rd;
CString output;
f1.Open(_T(C:/abc/test.txt"), CFile::modeRead | CFile::shareExclusive);
while(f1.ReadString(rd)!= NULL)
{
output += rd;
output.Format("%lf %lf %lf\n", &a, &b, &c);
.......
.......
}
f1.Close();
Thanks for helping out.
modified on Wednesday, October 21, 2009 1:03 AM
|
|
|
|
|
Nicholas Amh wrote: //how to read the text from the file t1 and convert it to "%le %le %le\n", &x, &y, &z format?
Can i do something like this?
while(f2.ReadString(rdtxt) != NULL)
{
Ya you can use the _tscanf() function.
_tscanf(rdtxt,_T("%lf %lf %lf\n"), &a, &b, &c));
|
|
|
|
|
Thanks. That work. But my problem still there. With CFile::shareExclusive and program don't work. Please help me out. Need to get it done asap. Thanks
|
|
|
|
|
Hi Nicholas,
Did you read the documentation for CFile::shareExclusive[^]? You cannot open the same file in two threads using this mode. It is doing exactly what your asking it to do.
What are you trying to achieve?
Best Wishes,
-David Delaune
|
|
|
|
|
Hi Randor,
I am trying to prevent other user from opening/accessing my file when my program is using/reading the file. Other user will have no access to my files during my process.
Thanks
|
|
|
|
|
Hi Nicholas,
You could add a CStdioFile member variable and open the file once. You could then pass the FILE* stream pointer to both threads something like:
if(NULL == m_f.m_pStream)
{
m_f.Open(_T("C:\\t1.txt"), CFile::modeReadWrite|CFile::OpenFlags::modeCreate|CFile::shareExclusive);
}
AfxBeginThread(Test_a,m_f.m_pStream);
AfxBeginThread(Test_b,m_f.m_pStream);
Using two threads to write to a single file stream is generally not recommended. CFile/CStdioFile are not thread-safe. Also keep in mind that reading/writing moves the file pointer. You will need to keep track of this file pointer and synchronize reads/writes and seek to the appropriate position.
Best Wishes,
-David Delaune
|
|
|
|
|
I smell, something somehwere gone wrong with the code.
1. what happens if Test_b is reading some data and control goes to Test_a, which write some other data and now there is inconsistency in data when Test_b reads data.
Aviod this condition.
While writing to a file, aviod reading.
Величие не Бога может быть недооценена.
|
|
|
|
|
Okay, thanks. The file that i write have already done writing before going for read.
|
|
|
|
|
Nicholas Amh wrote: Okay, thanks. The file that i write have already done writing before going for read.
Don't use threads for this unless you understand the implications; the code you have shown suggests you are something of a beginner. The best way of approaching this is to open, write, close the file in the first part of the program, then open, read, close in the second part. Also leave out the sharing part until you have the main logic working. Write the data to the file, use notepad or another editor to check the content is correct. Then read back the file and convert your data to its internal format. Also remember that
Format() is for output and
scanf() is for input.
|
|
|
|
|
Hi,
Am I correct in assuming that as soon as CWnd is Created or Intantiated that it is ready to receive messages
via SendMessage
My CWnd actually a Cdialog is waiting for Data I plan to Create or instatiate it
When the data arrives via SendMessage
I plan On Creating it (modlesss flavor)
thankx
|
|
|
|
|
ForNow wrote: Am I correct in assuming that as soon as CWnd is Created or Intantiated that it is ready to receive messages
Yes.
ForNow wrote: My CWnd actually a Cdialog is waiting for Data I plan to Create or instatiate it
When the data arrives via SendMessage
If the window is not created how it receive message?
|
|
|
|
|
It is my assumption that as Soon as CWnd/CDialog is inntantiated it has message pump
I dont think you need to Create a Window to receive messages
After All UI CWinthreads don't have windows but are Able to Receive messages though
its Not SendWindow rather PostThreadMessage
What I beleive these Objects have in Common is a Message Pump
thankx
|
|
|
|
|
ForNow wrote: It is my assumption that as Soon as CWnd/CDialog is inntantiated it has message pump
I dont think you need to Create a Window to receive messages
What do you mean by inntantiated? Creating an object of the class? Simply Creating the object of the class doesnt make any difference in message pumping..
ForNow wrote: its Not SendWindow rather PostThreadMessage
If the PostThreadMessage() is enough for you, you need to create only the window when the data arrive. But note that, you have to create your own message loop to receive messages that are recevied through PostThreadMessage() function.
|
|
|
|
|
I am just a beginner
but do I Have run ::Create to Receive a message Via ::SendMessge
isn't Having CWnd/CDialog Enough ????
|
|
|
|
|
ForNow wrote: I am just a beginner
Its been very long you been a beginner...
ForNow wrote: but do I Have run ::Create to Receive a message Via ::SendMessge
isn't Having CWnd/CDialog Enough ????
Ya you have to create a window. The SendMessage() function needs a window handle and the message will be delivered to that windows procedure. If the window is not created, the handle memeber variable of the Cwnd class will be 0.
|
|
|
|
|
I guess my only other option if I want use ::SendMessage to Receive messages is not to have the WS_VISIBLE flag on
and Do A ShowWindow When I receive the Data
I do MFC only a night durning the day I am MainFrame Programmer
Unlike others on the forum who work at this
Thankx for your help ..
|
|
|
|