|
LOL
I meant bytes, not bits!
hehe
|
|
|
|
|
Hello All, I'm writing client/server programs using named pipe.
In the server program,
when the user click on a button, it create a thread. Inside a thread function, CreatePipe is called first then listen to client.
Here the code how server program creates the pipe and the thread function
<br />
UINT theThreadFunction(LPVOID lParam)<br />
{<br />
ServerApp *s = (ServerApp*)lParam;<br />
s->CreatePipe();<br />
while(!stop)<br />
{<br />
s->CommunicateWithClient();<br />
}<br />
}<br />
<br />
void ServerApp::CreatePipe()<br />
{<br />
CString temp = "\\\\.\\pipe\\Server"; <br />
LPCTSTR lpszPipename = (const char*) temp;<br />
<br />
hPipe = CreateNamedPipe( <br />
lpszPipename,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE |
PIPE_READMODE_MESSAGE |
PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
BUFSIZE,
BUFSIZE,
NMPWAIT_USE_DEFAULT_WAIT,
NULL);
if (hPipe == INVALID_HANDLE_VALUE) <br />
{<br />
MessageBox("CreatePipe failed"); <br />
enableDlgItems = true; <br />
return ;<br />
} <br />
}<br />
<br />
void ServerApp::CommunicateWithClient()<br />
{<br />
...<br />
bool fConnected = ConnectNamedPipe(hPipe, NULL);
...<br />
}<br />
The client application get executed before the Server Application gets executed.
The client used the following code.
<br />
bool ClientApp::ConnectToServer( HANDLE &hPipe)<br />
{<br />
LPCTSTR lpszPipename = "\\\\serverComputerName\\pipe\\Server";<br />
bool connected = false;<br />
hPipe = CreateFile( <br />
lpszPipename,
GENERIC_READ |
GENERIC_WRITE, <br />
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hPipe != INVALID_HANDLE_VALUE) <br />
{<br />
connected = true;<br />
break; <br />
}<br />
return connected;<br />
}<br />
Here the problem, the ServerApp CreateNamedPipe() and then called ConnectNamedPipe(). If there isn't a client connect to the same pipe, the ConnectNamedPipe() waits until a client get connected.
The client Application called CreateFile() to connect to the pipe the server opened,
and return was return connected = true. However in the ServerApp, ConnectNamedPipe() is still waiting for the client to connnect.
Why the ServerApp stills think there isn't a client connecting to the pipe even though the CreateFile() in the ClientApp is successfully connected to named pipe?
Thank you
|
|
|
|
|
I have an up coming project where I need to scan a map and link part of the map to a database. I am c++ and c# programmer. If there is any techology out there that is related I would like to know. I don't want to reinvent something.
|
|
|
|
|
|
Hi.
A simple question.
How could I change the fontcolor of a static control or edit box or button, etc.
For example: if I have the static control with the ID -> IDC_STATIC, what should write in InitDialog to change the fontcolor to green?.
Thank you very much.
|
|
|
|
|
Wim Summer wrote:
How could I change the fontcolor of a static control or edit box or button, etc.
Handle the WM_CTLCOLOR message of your dialog box.
Try something along the lines of:
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
<code> if(pWnd->GetDlgCtrlID() == IDC_STATIC)
{
pDC->SetTextColor(RGB(0,128,0));
}</code>
return hbr;
}
Happy Programming and God Bless!
"Your coding practices might be buggy, but your code is always right."
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
Hi.
A simple question.
How could I change the fontcolor of a static control or edit box or button, etc.
For example: if I have the static control with the ID -> IDC_STATIC what should write in InitDialog to change the fontcolor.
Thank you very much.
|
|
|
|
|
you need to override the CWnd::OnCtlColor function in the parent window
you will need something like this
HBRUSH MyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor )
{
HBRUSH aBrush = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(pWnd->GetDlgCtrlID() == IDC_STATIC)
pDC->SetTextColor(RGB(255,0,0)); //red for example
return aBrush;
}
|
|
|
|
|
I am using Visual C++ 6.0 and I have problems using CBitmap.
Sometimes when I use the function
MyBitmap.LoadBitmap( IDB_BITMAP );
a debug assertion occurs:
File: wingdi.cpp
Line: 1120
The Bitmaps (256 colors, 8 Bit) were created in Photoshop. Paradoxically this assertion failure does not occur during the use of all bitmaps, only when I try to load some of them. I replaced the Bitmaps that did not work with new ones, changed the order of the bitmaps to load and deleted the debug folder, but nothing changed.
Is there any resolution for this problem?
Thank you for you help,
R.
|
|
|
|
|
Line 1120 of wingdi.h is
ASSERT(m_hObject == NULL); That means you are trying to load a second bitmap into a CBitmap object. You have to detach and delete the existing image before you can load a new one.
DeleteObject(MyBitmap.Detach());
MyBitmap.LoadBitmap(IDB_BITMAP);
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
ok, that was the point!
Thank you,
R.
|
|
|
|
|
Everybody knows the Microsoft forms 2.0 image control. I'm getting nuts with this.
I need to set the image file dynamically...but look at this.
m_imagecontrol.SetPicture(LPDISPATCH newValue);
I have a file dialog to browse the image, the question is:
how can I set the CFileDialog.GetFilename() in m_imagecontrol.SetPicture(LPDISPATCH newValue);
CFileDialog.GetFilename() is a CString, if there's a function to do this, please tell me before I kill myself.
thanks in advance pals
|
|
|
|
|
Try to look for IPicture usage. I think the LPDISPATCH param is a IPicture interface.
(rough guess)
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
I'm attempting to add a gradient background to my applications main menu bar
to match what I've done to the toolbars. I've got as far as creating a
pattern brush from a bitmap and setting it as the menus background using
SetMenuInfo() but it is not being rendered correctly. The colour should go
from dark at the top to light at the bottom but what I've ended up with is
the darker half at the bottom going from dark to light and the lighter half
at the top going from dark to light. Its as if the origin for the brush has
negative coordinates. Can anybody suggest how to correct the origin of the
brush?
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
Hi 2 all,
It is nice to be a member of this good site.Its veryh good site because its help in solvin out the queries and the problem faced by us.So know i should discuss my problem with u guys.
As i m a student of Undergrad and got a project in VC++.Our peoject is about multiLingual Translator.The basic objective is to take an input from the user and then translate it to someother language.So this is only done by Unicode. Since i donot have any exposure to Unicode so i want ur help.How should this be carried out .I dont know how to store Unicode in Database ?
So anybody who knows this solution please contace me on my Yahoo id i.e luckylaeeq4u@yahoo.com. Thanx for reading my problem . Hope some positive response from you Guys.
Bye and Take Care.
Laeeq Ahmad.
Pakistan
|
|
|
|
|
I want to do something like this, however wsprintf throws a compiler error. Is there another format function that I should use instead to do this?
BSTR path = NULL;
int num = 1;
path = SysAllocString(L"//errors/error[@id='%i']");
wsprintf(path, num);
- Nick Parker My Blog | My Articles
|
|
|
|
|
int wsprintf( LPTSTR lpOut,
LPCTSTR lpFmt,
...
);
Nick Parker wrote:
BSTR path = NULL;
BSTR != LPCTSTR (wrong type)
int num = 1;
wsprintf(_T("//errors/error[@id='%i']");, num);
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
palbano wrote:
BSTR != LPCTSTR (wrong type)
I realize that. I need to use a BSTR for the rest of what I am working on. Any other suggestions?
- Nick Parker My Blog | My Articles
|
|
|
|
|
Do all formatting using LPTSTRs, then use the T2BSTR conversion macro to get your BSTR type.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Ummm, there is a problem ...
Aside from the BSTR != wchar_t*, what do you expect wsprintf to do ?
I mean it's used to take a format string (path) and create a result - you haven't specified a result string. Are you expecting it to modify path in place (it won't even with correct types) ?
From MSDN :
typedef OLECHAR * BSTR;
These strings are zero-terminated, and in most cases they can be treated just like OLECHAR* strings. However, you can query a BSTR for its length rather than scan it, so it can contain embedded null characters. The length is stored as a 32-bit integer at the memory location preceding the data in the string.
The 32-bit is placed before the BSTR value so you don't need to worry about it, just cast the BSTR to a wchar_t*.
e.g. (without error checking)
wchar_t res[500];
BSTR path = NULL;
int num = 1;
path = SysAllocString(L"//errors/error[@id='%i']");
wsprintf(res, (wchar_t*)path, num);
...cmk
Save the whales - collect the whole set
|
|
|
|
|
You're misusing the BSTR . wsprintf() prints into a TCHAR array, but a BSTR is not an array.
BSTR path = NULL;
CString s;
int num = 1;
s.Format ( _T("//errors/error[@id='%i']"), num );
path = s.AllocSysString(); If you can't/don't want to use CString , alloc a TCHAR buffer instead and make sure it's big enough, then use the T2BSTR conversion macro to convert it to a BSTR .
Check out this article[^] if you need more details on converting between string types.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
I am working on a SDI project that calls a function SetModifiedFlag(), in my document file, if any value in my document file changes. That function is not part of my projects document file but seems to be a call to a function that exists in CDocument...(CDocument::SetModifiedFlag()). Can someone tell me what this function is? The function contains a boolean value, bModified. How can I access this value for reading, and resettng. Is this a typical way to test to see if any of your doc values have changed, etc. I am just not familiar with this and someone else developed this piece of code.
Thank You.
Jerry
|
|
|
|
|
jerry1211a wrote:
How can I access this value for reading, and resettng.
CDocument::IsModified()
CDocument::SetModifiedFlag()
jerry1211a wrote:
Is this a typical
Yes
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
In a straighforward MFC implementation, you can call SetModified() and the variable you mention is set to a 'true' value indicating data has changed. The framework would use that, or you would, when the user 'closes' your application and you would ordinarily pop up a warning that the document has changed, and ask user if he wants to save it before exiting your program. In an SDI instance, I think you would do the same thing on File|New or File|Open if the data had changed, so user does not lose data changes prior to loading a new document. When the document is saved, then the modified flag is reset to a 'false' value.
|
|
|
|
|
Hey Guys
Last Week i sat up a new system. Unfortunatly I've lost my the serial. But i've still installed it on the old PC. Any idea how i can get it from there ?
Please Help
|
|
|
|