|
Write a test program that just does what you are testing.
I have not (and will not) test what you have given. Your example is trying to do more than what you are asking about. You know the size of the bitmap, so why call StretchDIBits()? It looks like you're drawing some text on the DC, but then drawing the bitmap over that. etc...
Just write a simple program or a test function that just does what you are testing for and single step throu it with the debugger. That is how we solve the problems we face.
INTP
|
|
|
|
|
From my test I think GetDIBits can not be used for 8bits raw data. It can not get 8bits data from memDc correctly.
|
|
|
|
|
If the DC contains a bitmap, then it can get the data bits. Working with some GDI bitmap functions can be tricky, at least one of them just fails without telling you why (it just takes 1-bit, in the parameter data).
Examine CDibData.cpp and try to see what it is doing. May be you could write a test file for your data using it. If it fails then you are correct, and there is a bug I need to fix. Which would mean I (and others) have the same problem you do, and havn't fixed it yet.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
I m coding my server socket using CSocket.Everything goes right till the Accept (function of CSocket) is called.it shows Debug Assertion failed in File:sockcore.cpp
here is my code
BOOL CCSocketDlg::OnInitDialog()
{...
//AfxSocketInit() has been called
//CCSocketApp::InitInstance()
//default constructor creates TCP/IP so it is SOCK_STREAM
//this function will also binds the the socket with one //network card
BOOL bsocketcreate= socket.Create(36545);//create the //socket which will listen at port 36545
//if the socket is not created
if(!bsocketcreate)
{
::OutputDebugString(_T("socket couldnot be created"));
return FALSE;
}
else
::OutputDebugString(_T("socket created successfully"));
//SOCKET created then start listen socket
BOOL bsocketlisten= socket.Listen(5);
//if the socket is not able to listen at specified port
if(!bsocketlisten)
{
::OutputDebugString(_T("socket couldnot listen on specified port"));
return FALSE;
}
else
::OutputDebugString(_T("socket listens at specified port"));
// Begin the Socket thread
AfxBeginThread(fnMainThread,LPVOID(this));
return TRUE; // return TRUE unless you set the focus to a control
}
UINT fnMainThread(LPVOID p)
{
CCSocketDlg *m_Dlg=(CCSocketDlg*)p;
//create another CSocket variable to accept the connection
CSocket sockConnection;
//socket is listening it can know accept new connection
BOOL bsocketaccept=m_Dlg->socket.Accept(sockConnection);
if(!bsocketaccept)//if the connection with client is not //establish
{
::AfxMessageBox(_T("socket couldnot establish new connection with client"));
AfxEndThread(0);//end thread
return 1;
}
::OutputDebugString(_T("connection accepted on new socket"));
//Begin a new Socket thread AfxBeginThread(fnMainThread,LPVOID(p));
m_Dlg->socket.Close();
return 0;
}
thanx for help
-- modified at 4:10 Friday 26th August, 2005
|
|
|
|
|
1) try to change m_Dlg->socket.Accept(sockConnection); as
m_Dlg->socket.Accept(*sockConnection);
2) Or change CSocket sockconnection as CSocket* sockconnection = new CSocket()
redindian
|
|
|
|
|
i tried but same Debug Assertion has occurred
|
|
|
|
|
if i ignore the Debug Assertion then my server socket is connected to client and after that my program crashes.
|
|
|
|
|
Sunit,
This is repetetive problem when you use Windows Socket programing in Windows Operating system. As you know, MFC use asyncronous connection calls and request for scoket processing, MFC uses windows messagess for every new requests, data received etc...
Your problem is, you are created Windows socket in one thread, but using it on another thread. Bascially they will send messages which is irrelavant to another thread, hence assertion.
They are two appraches to solve this problem...
1. Create your server socket on UINT fnMainThread(LPVOID p) function. If you look at your function, there is no message handling is done. So you have to create a socket then you need to implement the message loop also for that thread.
2. When you use different thread for socket handling and creation,
first detach your socket handle from the main thread using Detach() method, copy that reference of socket and attach that reference to the new server socket object in another thread...
Please let me know if you need more help....
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
thanx for ur help
but still i want to clarify my doubts
what does asynchronous connection(used by MFC) means
|
|
|
|
|
asynchronous is used to avoid the blocking of the program.
Suppose you have a server socket which is waiting for a client to conenct,
it will stop the execution and waiting for a client to join. When a client joins, it will continue to next line..
To Avoid this Windows use asynchronous call. When a client connects, MFC will send a windows message, which you can come to know that one client has connected and you have to Accept the client..
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
i m creating Socket in main thread but using it in a worker thread .as worker thread doesnot handle the window messages so when MFC sends message for Client connection the my CSocket::Accept(which is another thread)cannot accept it.
m i right
thanx in advance
-- modified at 10:25 Friday 26th August, 2005
|
|
|
|
|
Hi, I suggest a redesign of your networking program:
1) use CAsyncSocket instead of CSocket
2) do all socket operations in one thread context, be event based instead of starting multiple worker threads for each socket
3) when implementing a server (not just multiple clients) then spend your program a list of incoming socket objects, something like std::list<casyncsocket*>. Here you store socket objects for house keeping and cleanup.
4) do a lot of testing. check against buffer overruns, code injection, etc
Hope it helps,
Moak
|
|
|
|
|
I want to automate Excel in MFC . I can automate a new application but how can i modify existing Excel File programmaticaly through those interfaces. Can some body help me how can I load existing file:
Here is the code:-
_Application app; // app is the Excel _Application object
// Start Excel and get Application object...
if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Couldn't start Excel.");
}
else
{
//Make Excel Visible and display a message
app.SetVisible(TRUE);
}
Can some1 plz tell me how to load a specific file ???
Regards
|
|
|
|
|
This is relatively easy, once you're familiar with the Excel object model. Of course, MS give most information for VB developers, but it isn't too hard.
Firstly, from the application object, get the Workbooks collection. From there, you can access already open workbooks, create new ones in the collection (but not necessarily save them to disk) and open existing files.
The method from the workbooks collection you want is 'Open'. This lets you open an existing file. From there, again, you can get the workbook itself (Workbooks Item) and from there the worksheet, and work with ranges etc. Then you can call the Workbook (the item not the collection) save method to write your changes.
Check out by searching for XLCLIENT in MSDN, and "Excel automation VC++" too. There is information in there, you just have to find it.
The hardest part is that in VB examples you see stuff like
set wb = application.workbooks("test1.xls")
and you have to figure out how to convert that to C++.
There was a useful tool which takes VB code in and spits out C++ stuff specifically for this purpose on the MS site, but I can never find it. It wasn't perfect but helped a lot.
Essentially, for any method that returns an object (like workbooks Item), you will need a corresponding wrapper object to hold the returned object, and then call it's methods, so it gets a bit long-winded.
One other caveat is that for a lot of methods, there will be arguments you don't want to specify, but cannot leave out, so you will need to construct a VARIANT for this purpose.
COleVariant v;
v.vt = VT_ERROR;
v.scode = DISP_E_PARAMNOTFOUND;
You can then pass v for optional args you don't want.
I tend to use #import on the type libraries, which does a similar thing to the MFC generation, but I find simpler to use.
Hope this helps.
Steve S
Developer for hire!
|
|
|
|
|
Search MSDN for
<br />
HOWTO: Use MFC to Automate Excel 97 and Navigate Worksheets<br />
Article ID: Q178782
A snapshot:
_Application app;
_Workbook book;
_Worksheet sheet;
Workbooks books;
Worksheets sheets;
Range range;
char buf[1024];
LPDISPATCH lpDisp;
long count;
int i;
COleVariant
covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Couldn't CreateDispatch on Excel");
return;
}
app.SetVisible(TRUE);
lpDisp = app.GetWorkbooks();
ASSERT(lpDisp);
books.AttachDispatch( lpDisp );
lpDisp = books.Open("C:\\My Docs\\Test",
covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional, covOptional
);
ASSERT(lpDisp);
~RaGE();
|
|
|
|
|
Hi
I have developed and MFC EXE application. In that I want to hide the rectangle that it shows in taskbar. Normally we use it to maximize and minimize the application.
I found some code here : "http://www.codeproject.com/dialog/hidetaskbar.asp"
But I didn't get what exactly it wants to say and where to put the code exactly....
Can anyone help me or any other ide how to do that ?
Thankx in advance
Mahesh
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
Assuming you have a dialog based MFC app ..do this (I am just repeating what the author says)
Declare
LPITaskbarList pTaskbar; in your yourdialog.h and
call the functions
xxx
pTaskbar->HrInit(this);
xxx
in yourdialog.cpp
It should do the work .
If you have a SDI or MDI MFC app , the same should work in your mainfrm.h and .cpp , provided the author's code compiles with urs
redindian
|
|
|
|
|
Thankx a lot for replying
Yes I have MFC application which is dialogue based application.
I tried in the same way but still not working...can you plz tell me it in detail..where to put all code exactly
Thankx in advance
Mahesh
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
EX:
http://localhost/test.rm download speeds is 600Kb/s
but I want the max speeds is 300Kb/s .Can you help me?
Thank you !
|
|
|
|
|
Hi all!
couple of days ago someone discussed an idea of hiding characters in ascii/test files in a way that actual file size won't change. In windows text file two characters are inserted in file with each line i.e. CR & LF. I thought a person could use one character to put his own char but notepad might show that character as a garbage symbol. So anybody knows or have any idea to achieve this?
Only quality never gets out of fashion
|
|
|
|
|
Hello ,.
I am new to MFC.
I am getting error in date field.
I used control as CMonthCalCtrl -- m_month .
I added below code in MCN_SELCHANGE
CString strDate;
CTime ct;
m_month.GetCurSel(ct);
m_strDate.Format("%02d-%02d-%d",ct.GetDay(),ct.GetMonth(),ct.GetYear());
MessageBox(strDate);
UpdateData(FALSE);
==========
But selected date is coming error. It is displaying advance of '12' to real date.
Suppose if I selected 10-8-2005 .,I t is displying
22-8-2005.
If I selected 24-8-2005 ., It is Displaying (24+12=36 Next month) Taking Next month i.e, 5-8-2005
Praveen Chowdam Kumar
|
|
|
|
|
GUys.. need help here.. here the situation.. in my main i need to change a value in one of my header file.. how do i go abt doing so..
i new to declare a variable right??
where do i do that?
in my dialog.cpp??
the situtaion is i need to constant change an ip address. but that address is fixed in one of my header file.. so how do i go about this..
Much help need.. and waiting for yrs kindess..
|
|
|
|
|
In your dialog.h , change the variable's value (IP address or whatever) and include it in your .cpp ,
job finshed
redindian
|
|
|
|
|
cue_ball wrote:
the situtaion is i need to constant change an ip address. but that address is fixed in one of my header file..
What do you mean by fixed? Perhaps you can try posting some code sample on that.
<font=arial>Weiye Chen
Life is hard, yet we are made of flesh...
|
|
|
|
|
Thanks alot for yr help.. but i still have some misunderstanding.. my program.. a simple server n client program.
For my client program.. the logged in ip. address is set in a uility.cpp (which is one of the header file..)
i was hoping to check it to more versitaile.. so that i can change the ip when the main dialog is running..
but it seem that the moment the program compile it read the uility first hence i can exe it.
is it possible to like by pass it then let call it back..
the ip.. setting is in uility.cpp and my simple edit. box is in dialog.cpp
anyhelp is greatly appraised
|
|
|
|