|
hkl wrote:
flag = socket.Receive(buff,sizeof(buff));
Execution in this thread blocks until Receive can get (sizeof(buff)) bytes of data. You should probably use CAsyncSocket; it would probably meet your requirements better.
Jon
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
That is because the thread Accept() ing the connection is the same that Receive() s the request on the socket.
You must dispatch the socket returned by Accept() first param to another thread, which will Receive() , preventing the server thread from blocking.
If you have problem understanding this concept, I suggest that you read this:
http://www.codeproject.com/useritems/winsockintro03.asp
Michel
If I am wrong or said something stupid, I apologize in advance
|
|
|
|
|
that's all,
i want to know if it possible pass a array of doubles like parameter by reference to a function and in the case it was possible how.
Thanks in advance.
|
|
|
|
|
You just want to change the array elements in the function?
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
Yes i want, if it's possible i want pass an array where after an operations the result was back in this array.
|
|
|
|
|
Hi,
I need to pass an IPicture through process boundaries, but IPicture cannot be marshaled so I decide to pass it over one Stream created on one HGlobal..., what I did in the server is:
STDMETHOD(SetMetafile)(VARIANT GlobMeta)
{
HGLOBAL hGlob = (HGLOBAL) GlobMeta.lVal;
IStream *pStream = NULL;
HRESULT hr = ::CreateStreamOnHGlobal(hGlob, TRUE, &pStream);
if(!pStream) return S_FALSE;
if(!SetMeta(pStream, &_Pict)) {
return S_FALSE;
}
pStream->Release();
return S_OK;
}
BOOL SetMeta(IStream *pStream, IPicture **Pict)
{
BOOL bResult = FALSE;
CComPtr<IPictureDisp> pic;
LARGE_INTEGER l;
l.QuadPart =0;
pStream->Seek(l, STREAM_SEEK_SET, NULL);
OleLoadPicture(pStream, l.LowPart, FALSE, IID_IPictureDisp, (void **) &pic);
if(pic != NULL) {
pic->QueryInterface(IID_IPicture, (void **) Pict);
if(Pict) {
bResult = TRUE;
}
}
return bResult;
}
Do you see something wrong in the code ( it fails when tries to load the picture (( ).
Thanks in advance, Greetings
Braulio
|
|
|
|
|
Very first thing, I would use an HRESULT and catch the return value from OleLoadPicture. In fact you should be checking the return values of all of your COM function calls especially the ones that cross process boundaries. With COM the functions can fail due to unforeseen problems outside of your program.
after you get the HRESULT, you can test if it is valid with the SUCCEEDED(hResult) macro, or if it failed with the FAILED(hResult) macro. Also if you want to know what the error code is when it fails you can look it up in the tools menu with error lookup.
|
|
|
|
|
Thanks for the tip,
One thing... to install my COM server DLL in another computer, I only need to call
RegSvr32 MyDll.dll
Not more not less ?, or do I need to make more operations ?
Thanks !
Braulio
I
|
|
|
|
|
That should be it, but it has to be called from that computer.
|
|
|
|
|
Hi everyone. I have a dialog with a control toolbar, which I have been able to successfully create. It has 2 combo boxes, both were simple combo boxes, and it worked fine. Then, I made one of the combo boxes a CFontPreviewCombo (which is a combo box which displays all available system fonts, which is a new control added to CodeProject, by Chris Losinger). I did this by changing the type from CComboBox to CFontPreviewCombo, and it compiled and ran fine. It did display the fonts in the combo box, but box itself did not draw properly. I realized it was supposed to be owner drawn variable, so I made it owner drawn variable by using the CBS_OWNERDRAWVARIABLE style.
When I did that, I got a daocore.cpp, line 42. It asserts on the cToolBar.m_cboFont.Create() line, when the combo box is created. It does not assert when not owner drawn, but does when it is.
I have my combo box code below, I am doing this in the OnCreate() of the dialog. I was told this was the right place to put it, but I am not completely sure, I have to admit I am new to manipulating toolbars directly.
<br />
int CDlgReport::OnCreate(LPCREATESTRUCT lpCreateStruct) <br />
{<br />
if (CDialog::OnCreate(lpCreateStruct) == -1)<br />
return -1;<br />
<br />
CRect rect;<br />
<br />
<br />
cToolBar.Create(this);<br />
cToolBar.LoadToolBar(IDR_TBR_REPORT);<br />
<br />
#define SNAP_WIDTH_FONT_SIZE 50 //the width of the combo box<br />
#define SNAP_WIDTH_FONT 150 //the width of the combo box<br />
<br />
<br />
cToolBar.SetButtonInfo(0, ID_TBR_REPORT_CBO_FONT, TBBS_SEPARATOR,<br />
SNAP_WIDTH_FONT);<br />
cToolBar.GetItemRect(0, &rect);<br />
<br />
rect.top+=2;<br />
rect.bottom += 200;<br />
<br />
<br />
<br />
<br />
<br />
<br />
if (!cToolBar.m_cboFont.Create(WS_CHILD|WS_VISIBLE|CBS_AUTOHSCROLL| CBS_OWNERDRAWVARIABLE |<br />
CBS_DROPDOWNLIST|CBS_HASSTRINGS | CBS_SORT,<br />
rect, &cToolBar, IDC_CBO_FONT))<br />
{<br />
TRACE0("Failed to create combo-box\n");<br />
return FALSE;<br />
}<br />
<br />
<br />
<br />
cToolBar.m_cboFont.SetFont(cToolBar.GetFont());<br />
cToolBar.m_cboFont.ShowWindow(SW_SHOW);<br />
<br />
cToolBar.m_cboFont.m_style = CFontPreviewCombo::NAME_GUI_FONT;<br />
cToolBar.m_cboFont.Init();<br />
<br />
<br />
<br />
<br />
cToolBar.SetButtonInfo(1, ID_TBR_REPORT_CBO_FONT_SIZE, TBBS_SEPARATOR,<br />
SNAP_WIDTH_FONT_SIZE);<br />
cToolBar.GetItemRect(1, &rect);<br />
<br />
rect.top+=2;<br />
rect.bottom += 200;<br />
<br />
if (!cToolBar.m_cboFontSize.Create(WS_CHILD|WS_VISIBLE|CBS_AUTOHSCROLL| <br />
CBS_DROPDOWNLIST|CBS_HASSTRINGS,<br />
rect, &cToolBar, IDC_CBO_FONT_SIZE))<br />
{<br />
TRACE0("Failed to create combo-box\n");<br />
return FALSE;<br />
}<br />
cToolBar.m_cboFontSize.SetFont(cToolBar.GetFont());<br />
cToolBar.m_cboFontSize.ShowWindow(SW_SHOW);<br />
<br />
cToolBar.m_cboFontSize.AddString("1");<br />
cToolBar.m_cboFontSize.AddString("2");<br />
cToolBar.m_cboFontSize.AddString("3");<br />
cToolBar.m_cboFontSize.AddString("4");<br />
cToolBar.m_cboFontSize.AddString("5");<br />
cToolBar.m_cboFontSize.AddString("6");<br />
cToolBar.m_cboFontSize.AddString("7");<br />
cToolBar.m_cboFontSize.SetCurSel(0);<br />
<br />
return 0;<br />
}<br />
If I am not specific enough, I can provide more code. I hope I explained this correctly.
Thanks in advance!
|
|
|
|
|
Replace with : CBS_OWNERDRAWFIXED
my part codes:
// Create the Line Style combo box
SetButtonInfo(6,ID_PRTFMTLINESTYLE,TBBS_SEPARATOR,80);
GetItemRect(6, &rect);
rect.top = 2;
rect.bottom = rect.top + 18*8;
if (!m_LineStyleSelect.Create(
CBS_DROPDOWNLIST|CBS_OWNERDRAWFIXED|CBS_SORT
|WS_VISIBLE|WS_TABSTOP,
rect, this, ID_PRTFMTLINESTYLE))
return -1;
|
|
|
|
|
I tried making it own drawn fixed, but it also asserts
|
|
|
|
|
my codes was run normally! if possible, please send your more codes
*.h
----------------------------------------
class AFX_EXT_CLASS CLineStyleComboBox : public CComboBox
{
protected:
virtual void MeasureItem( LPMEASUREITEMSTRUCT lpMIS);
virtual void DrawItem( LPDRAWITEMSTRUCT lpDIS);
virtual int CompareItem(LPCOMPAREITEMSTRUCT lpCIS);
//{{AFX_MSG(CLineStyleComboBox)
afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct );
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
void AddStyleItem(int Style) { AddString((LPCTSTR)Style);}
int SelectItem(int Style);
};
*.cpp
----------------------------------------
#define LSTYLE_ITEM_HEIGHT 18
BEGIN_MESSAGE_MAP(CLineStyleComboBox, CComboBox)
//{{AFX_MSG_MAP(CLineStyleComboBox)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
int CLineStyleComboBox::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
int nRet = CComboBox::OnCreate(lpCreateStruct);
if( nRet==-1 )
return nRet;
static int styles[] =
{
PS_SOLID,PS_DASH,PS_DOT,PS_DASHDOT,PS_DASHDOTDOT,PS_NULL
};
for(int i=0;i<sizeof(styles) sizeof(styles[0]);i++)
="" addstyleitem(="" styles[i]="" );
="" setcursel(0);
="" return="" nret;
}
void="" clinestylecombobox::measureitem(lpmeasureitemstruct="" lpmis)
{
="" lpmis-="">itemHeight = LSTYLE_ITEM_HEIGHT;
}
void CLineStyleComboBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CDC* pDC = CDC::FromHandle(lpDIS->hDC);
COLORREF Color =
(lpDIS->itemState & ODS_SELECTED)?RGB(0xff,0,0):RGB(0,0,0);
int nPenStyle = int(lpDIS->itemData);
CPen Pen( nPenStyle,1, Color );
CPen * pOldPen = pDC->SelectObject( &Pen );
pDC->SetBkMode(TRANSPARENT);
int y = (lpDIS->rcItem.top+lpDIS->rcItem.bottom)>>1;
pDC->MoveTo( lpDIS->rcItem.left,y );
pDC->LineTo( lpDIS->rcItem.right,y );
pDC->SelectObject( pOldPen );
}
int CLineStyleComboBox::CompareItem(LPCOMPAREITEMSTRUCT lpCIS)
{
return int(lpCIS->itemData1)-int(lpCIS->itemData2);
}
int CLineStyleComboBox::SelectItem(int Style)
{
int n = GetCount();
for(int i=0;i
|
|
|
|
|
I wonder if you understand me when I explain my problem.
I am trying to make an application with Visual C++, my application must contain MFC and ADo connection.
It must me connected to database (which I made in Access).
We must be able to brows tables (2-3 different tables) of the database.
INserting, adding and deleting records of the tables.
I have done the following:
My database is a phonebook, I have made and access database connection to it, and I can brows it, add, delete and updating.
My problem is: How do I add another table in the application? I have tried everything, and made mistakes and over and over again. What I meen is that I must have 2 tables och more working paralell in the application.
How do I do this?
|
|
|
|
|
I've written an MFC DLL, say ClientAPI.dll and ClientAPI.lib. In the DLL, there's a class, say CMyClassA, it's just a class doing some getXXX and setXXX with CString's, and without any memory allocations.
However, in the application using it, i just link with ClientAPI.lib, and create an instance as
CMyClassA *pInsA;
pInsA = new CMyClassA();
delete pInsA;
In delete pInsA, I got an error :
Heap block at 003B7378 modified at 003B7400 past requested size of 80
What's worng with it ?
Thanks
|
|
|
|
|
Probably the reason of heap corruption is that you're allocating memory blocks for CStrings in .DLL and freeing them in .exe.
Did you link with MFC dynamically or statically?
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
Yeah, the CString's are in the classes in the DLL, but I just make it class variable ( should be auto variable ). I didn't allocate memory on my own.
You are right too, I declared the classes in the DLL, and use it in a EXE. In the exe routine, i did
CMyClassA *pInst;
pInst = new CMyClassA;
delete pInst;
I like MFC dynamically in debug mode.
Hiya, Everybody ^^
|
|
|
|
|
Hi!
I making a "funny" application (not serious but good practice). I want to steer a picture with the arrow keys. The problem is that when I holding arrow left to move the picture left and then press up arrow while I holding left arrow down the left arrow functionality seems to stop then... How to make the picture move left and up at the same time? because that must be the problem...
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
You could create a sub-message handler specifically for your arrow keys when you handle the WM_CHAR message.
Then what this handler would do is call GetKeyboardState, or GetKeyState in order to test the values
of all of the arrow keys. Then you can logically decide which way to move the image based on which arrow keys are set.
If you wanted to get more complicated with the way that the keys control the movement you will have to store the last known state of the keys. For instance, say that you are holding the left arrow key, then you hit the right arrow key. The simple solution in this case would be not to move the items because both keys cancel themselves out. However, if you record the state of the keys in the WM_KEYUP and WM_KEYDOWN messages, you would be able to tell that the right arrow key was clicked second, and the movement of the picture should change to the right.
|
|
|
|
|
When I use the Data Grid control and ADO in my program, It run correctly,but it can't run on the machine whithout the Vc++ IDE correctly. It troubles me for all day. Can somebody help me !
Thanks very much!!
splendoury
VCBeginer
|
|
|
|
|
You have to register ocx file of DataGrid in that machine.For this purpose you can use installshield and add that file to it.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Is it to copy the file named DBGRID32.OCX to the system directory! I do like this, but it's unuseful. Is it ADO that cause it!!
VCBeginer
|
|
|
|
|
Forlegend wrote:
DBGRID32.OCX
no,thats msdatagrid.ocx. If you don't use installshield,use regsvr32 in command menu for that file,then run your application.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Thank you very much!!
VCBeginer
|
|
|
|
|
Hi all,
how to create a main application and with a menu command open inside this main applicationa one or more dialog (but not called with a DoModal())?!
Thanks!
|
|
|
|
|