|
Assignment
Write a program in C++ and WIN32 api to implement an unnamed pipe. program should contain two threads ("producer" and "consumer") communicating through a pipe which is implmented using an array having 10 entries( ie 0 to 9). access to the pipe should be synchronized using a semaohore implemented as a " class" .The "p" and "v" operations supported by the semaphore should be exucuted "ATOMICALLY" Which is enforced using WIN32 API functions (e.g the createsemaphore funtion).
NOTE The P and V are the only operations supported by the semaphore class.
The poducer thread gets an integer ( a single digi, 0.....9) from the user and enqueues it into the pipe . The consumer thread always dequeues the first number in the pipe toward the front of the pipe after an item has been deposited ( by the producer) or consumed ( by the consumer)
We should use another "class" (ie the pipe class) to implement the pipe supporting operations " enqueue", "dequeue" and "move". The fisrt two operations have to be synchronized using the semaphore shown above (operation"move " is not because it is invoked by the first two operatios which can directl acces the shared pipe)
Note that your pogram should also be able to take care of the conditions when the pipe is either empty or full.When the consumer thread detects an empty pipe ,it prints a message to the screen.similarl when the producer thread detects afull pipe ,it prints a message to the screen too.
Note also that you should alwas delay the consumer thread by three 3 seconds by inserting a "sleep3000)" (without qoutes ) function into the appropriate place in the consumer thread.
The producer thread shold also show the contents of the pipe after a number is enqueued .
The consumer shouls aslso show the contents of the pipe after a number is dequeued .
The following shows the scenario of running program, where user inputs are underlined
enter a number: 5the
contents of the pipe (from the producer):bbbbbbbbb5
enter a number:2
the contents of the pipe(from producer):bbbbbbbb25
the contents of the pipe (from consumer);bbbbbbbbb2
enter a number:7
the contents of the pipe (from producer):bbbbbbbb72
the contents of the pipe (from consumer):bbbbbbbbb7
enter a number:
the contents of a pipe ( from consumer):bbbbbbbbbb
... an empty pipe is detected (from consumer):\\\
..................
|
|
|
|
|
1. Welcome to the academic world. You have two options. Either pay someone to do your homework now, and for the rest of your academic career, then go back to flipping burgers ( seeing as you will have learned nothing ), or try to do your own homework and ask for help when you get stuck. If you decide to fail your course, I'll do this program for you for $50. My fee for the next one will be $100, and so on. If you decide to learn for yourself, I'll be happy to help for free. That means you try first, and ask SPECIFIC questions when you get stuck.
2. This is the Managed C++ forum. Nothing about this assignment looks to me like MC++
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Christian said:
"If you decide to fail your course, I'll do this program for you for $50. My fee for the next one will be $100, and so on."
Hey, you are cheap!
And I was ready to bill him my usual rate of $250/hour to do his assignment for him!
Christian also said:
"If you decide to learn for yourself, I'll be happy to help for free. That means you try first, and ask SPECIFIC questions when you get stuck."
Exactly! No problem giving specific help, if stuck. I used to tutor Comp Sci in college, as well as work in the computer lab as a lab assistent (that was many years ago), and many times I've had other students want me to do thier assignments for them. It they where truly stuck and did not know how to get started, I did not mind giving some hints to help get them on thier way, but I was not about to do thier homework for them.
|
|
|
|
|
skonopa wrote:
Hey, you are cheap!
Hell, no. My fee does not increase by $50, it doubles every time. Every assignment.
skonopa wrote:
It they where truly stuck and did not know how to get started, I did not mind giving some hints to help get them on thier way, but I was not about to do thier homework for them.
Yeah, that's exactly my point, too.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi
I am developing a MDI application where I would like to be able to control
the activeChild form from buttons on the MdiParent toolbar.
For example navigate through records in the dataset of the activeChild form.
I would like to use the same buttons on the MdiParent tool bar for any
activeChild form that is open.
How would I accomplish this? (C#/C++ please)
Thanks,
JoseTA
FranTA
|
|
|
|
|
Hi,
I have been succesful using single statement of DllImportAttribute to use my unmanaged Dll code. But, now I want to have 2 entrys in my Dll, so I wrote two DllImportAttribute Statements:
[System::Runtime::InteropServices:llImportAttribute
("D:\\Tumego\\MultiWayTree\\VBMGUM_DLL\\Debug\\VBMGUM_DLL.dll", _
CharSet =CharSet::Auto)]
extern int GetValue1000(void);
//
[System::Runtime::InteropServices:llImportAttribute
("D:\\Tumego\\MultiWayTree\\VBMGUM_DLL\\Debug\\VBMGUM_DLL.dll", _
CharSet =CharSet::Auto)]
extern int GetValue99(void);
The Error messages are:
BMGUM_MG.cpp(16) : error C2363: ?argument? '"_\r\nCharSet"="CharSet::Auto"' (?Custom Attribute? 'System::Runtime::InteropServices:llImportAttribute') ?Can not be evaluated?
VBMGUM_MG.cpp(13) : error C3725: 'System::Runtime::InteropServices:llImportAttribute': ? Can not interpret overloading of attribute?
?it might be ?'System::Runtime::InteropServices:llImportAttribute:llImportAttribute(System::String __gc *)'
*****?----? is not exact but is translated from Japanese Version Visual Studio ***********
Writing multiple DllImportAttribute Statement like this is fine:
even I can use using namespace:
using namespace System::Runtime::InteropServices;
[DllImportAttribute("Kernel32.dll", CharSet=CharSet::Auto)]
extern "C" int QueryPerformanceFrequency(__int64* Freq);
[DllImportAttribute("Kernel32.dll", CharSet=CharSet::Auto)]
extern "C" int QueryPerformanceCounter(__int64* Tw);
I do not like Dll expression of "D:\\Tumego\\MultiWayTree\\VBMGUM_DLL\\Debug\\VBMGUM_DLL.dll", becasuse of manageing difficulty. But I do not know other way. May be this expression is the reason for trouble.
The rest of the codes:
DLL simplified finnally like this:
int GetValue1000(void)
{
int a = 1000;
return a;
}
int GetValue99(void)
{
int a =99;
return 99;
}
Definition file:
LIBRARY VBMGUM_DLL
EXPORTS
GetValue1000
GetValue99
Any hints, comments and May-be answers are appreciated, as well as final shot.
Please help me.
|
|
|
|
|
Hi
I came to a work around and I thought it may help some having the same problem, I read MSDN >.NET_Framework > Programming > co-operation with Unmanaged Code.
There is a Sample that donot spell 'DllImportAttribute' but spells 'DllImport' also NO 'CharSet=CharSet::Auto' specification.
For the time-being it happend to be OK for me.
After I elliminated 'CharSet=CharSet::Auto', I donot get strange errors.
Thank you.
Chkky
|
|
|
|
|
Hi,
I asked this question before in the VC++ forum, but I think my question was misunderstood. I´ll try it again with more explanation...
I´m making an Windows Form appl. using VC++ .Net 2003. As I start an "Form" is automatically created for me.
Then I want to make my own "MessageBox"-like class (due to interference with the "windows.h" header I cannot use the included MessageBox" properly.)
I go to Project->Add new Item->Windows Form (.NET) and a new "Form" is created, that I want to use as a dialog box, and I add a Label and an OK-button rto it.
In the Forms properties I set:
FormBorterStyle = FixedDialog
MaximizeBox = False
MinimizeBox = False
However, I don´t know which property I must set, or which method to call for making the Form close when I push the OK-button.
Does anybody have a suggestion?
(I display it by calling the ShowDialog() method.)
Apart from that it works as a dialogbox (I know there are probably better ways to solve the problem, but I´m quite new to VC/C++, and this seemed like the easiest way around it)
regards
doneirik
|
|
|
|
|
I believe if you call the button IDOK, it will do this for you. If not, then there's a property for what button is the OK button, but the name escapes me. At least, that's the case in C#.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
For your MessageBox problem...
In stdafx.h just add #undef MessageBoxA or MessageBox don't remember.
To close your dialog take a look at this and I'm going to help you a bit...
// Set the accept button of the form to button1.
form1->AcceptButton = button1;
|
|
|
|
|
Hi
i am right now doing a project on E - Learning Development Tool Software.
I faced some problems on whether to create projects individually first then transfer it into a DLL, or just do the coding in the DLL?
Jingpo
|
|
|
|
|
I thik you should decide wich way works the best for you. Anyway, I would choose creating projects individually.
--Nikola--
modified 7-Dec-20 21:01pm.
|
|
|
|
|
Hi there, can someone tell me where' a syntax error in that code on line 16.
<br />
#pragma once<br />
<br />
using namespace System;<br />
using namespace System::Windows::Forms;<br />
using namespace System::Collections;<br />
using namespace System::Net;<br />
using namespace System::Net::Sockets;<br />
using namespace System::Data::Odbc;<br />
using namespace System::Text;<br />
<br />
#include "MessagesCodes.h"<br />
#include "Utilities.h"<br />
<br />
__gc class CServer<br />
{<br />
public:<br />
CServer(TextBox* p_txtServerEvents, TextBox* p_txtUsersMessages);<br />
~CServer(void);<br />
<br />
void DecodeMsg(SocketChatClient* p_client, String* p_msg);
<br />
String* GetServerName();<br />
String* GetServerAddress();<br />
int GetServerPort();<br />
<br />
bool GetHost();<br />
void CreateSocket();<br />
<br />
void OnConnectRequest(IAsyncResult* p_ar);<br />
void NewConnection(Socket* p_clientSocket);<br />
void OnReceivedData(IAsyncResult* p_ar);<br />
<br />
private:<br />
String* m_hostName;<br />
IPAddress* m_addr;<br />
const static int PORT= 3050;<br />
Socket* m_serverSocket;<br />
ArrayList* m_arrClients;<br />
TextBox* m_txtServerEvents;<br />
TextBox* m_txtUsersMessages;<br />
<br />
__gc class SocketChatClient<br />
{<br />
public:<br />
SocketChatClient(Socket* p_sock);<br />
<br />
Socket* GetSock() { return m_sock; }<br />
void SetupReceiveCallback(CServer* p_server);<br />
Byte GetReceivedData(IAsyncResult* p_ar)[];<br />
<br />
private:<br />
Socket* m_sock;<br />
Byte m_byBuff[];<br />
};<br />
};<br />
I think the problem is that the compiler don't see the internal class SocketChatClient but I don't know how to correct it.
--------------
The Thruth Is Out There
|
|
|
|
|
have you tried moving the definition of SocketChatClient to the beginning of your CServer class?
that way it is defined before it is referenced...
__gc class CServer
{
__gc class SocketChatClient
{
public:
SocketChatClient(Socket* p_sock);
Socket* GetSock() { return m_sock; }
void SetupReceiveCallback(CServer* p_server);
Byte GetReceivedData(IAsyncResult* p_ar)[];
private:
Socket* m_sock;
Byte m_byBuff[];
};
public:
CServer(TextBox* p_txtServerEvents, TextBox* p_txtUsersMessages);
~CServer(void);
void DecodeMsg(SocketChatClient* p_client, String* p_msg);
String* GetServerName();
String* GetServerAddress();
int GetServerPort();
bool GetHost();
void CreateSocket();
void OnConnectRequest(IAsyncResult* p_ar);
void NewConnection(Socket* p_clientSocket);
void OnReceivedData(IAsyncResult* p_ar);
private:
String* m_hostName;
IPAddress* m_addr;
const static int PORT= 3050;
Socket* m_serverSocket;
ArrayList* m_arrClients;
TextBox* m_txtServerEvents;
TextBox* m_txtUsersMessages;
};
Steve
|
|
|
|
|
Ok it work now... never knew it could be such a that stupid!!!
thx
--------------
The Thruth Is Out There
|
|
|
|
|
I have some custom MFC controls that have been written over the past several years right now (and no, these are not ActiveX or COM components. These are straight-up MFC classes), that the powers-to-be does not want to invest the time to rewrite as .NET components.
Before attempting to use the more complex custom controls, as an experiment, I was able to succesfully compile and link a DLL/assembly that would put up a CListCtrl (yes, I konw there is a WinForm equivalent, but this is an experiment, to see if I can at least get a common MFC control to appear in a .NET app). Unfortunatly, when I run the program, it crashes with a "Debug Assertion Fail" error, when a function AfxGetInstanceHandle is called inside the MFC "Create" function for the CListCtrl.
A seperate DLL/assembly which is essentaly a wrapper around the MFC control is used. A reference to the assembly is incuded into the main app in which to try to display this MFC control.
I've searched the this forum as well as the internet as a whole and I've yet to find a good example of just how to embed an MFC control inside of a .NET application.
I've seen/found examples of how to call the .NET framework from inside of an MFC application, but I have not seen it the other way.
I've also seen/found examples of how to create managed wrappers around unmanaged classes, but none of the examples show how to do it around an MFC class.
Has anybody attempted anything like this, and more importantly, has anybody manage to actually get it to work? I'd like to know just how, preferably with a good example, to get an MFC control to work inside of a .NET application.
Thanks
|
|
|
|
|
|
I've seen that before. It shows how to call .NET from an MFC app.
However, I am trying to call MFC from a .NET (managed C++) app, of which I've not seen any examples, nor anybody with a working solution demonstrating such.
I am wondering if it is even possible.
Thanks for the help, though.
|
|
|
|
|
you can not use many classes, such as CWnd derived classes without a CWinApp object. So the better way is to create an MFC app and then add .Net support.
http://blog.joycode.com/jiangsheng
http://blog.csdn.net/jiangsheng
Command what is yours
Conquer what is not
---Kane
|
|
|
|
|
Thanks. I was afraid of that. Now that I think about it, it does make sense.
I guess that would explain the ASSERT errors coming out of AfxGetInstanceHandle. Looking up in the MSDN to see just what AfxGetInstanceHandle does, it is returning an instance of the current application, which I am assuming would be an instance of CWinApp. If there is no instance of a CWinApp being created, than there would be no handle for AfxGetInstanceHandle to return.
Again, thanks!
Well, it looks like in this case, we may have to ditch .NET and go back to MFC, as we got way to much invested in custom MFC controls to have to go back and re-write them to work with .NET. Tis a shame, as there are some nice features in .NET that I'd like to take advantage of.
|
|
|
|
|
Update:
I found this article right here on the Code Project site that shows exactly what I want to do.
I'll try to incorporate what I read in that article into my own project and see if I can get it to work for my needs.
Thanks
|
|
|
|
|
|
Please visit "http://www.codeproject.com/useritems/MFCDotNetApp.asp;P;P"
|
|
|
|
|
Hi,
I have a "SplitterAdvanced" user control, used to load ActiveX and User Control at runtime.
My "SplitterAdvanced" need to be able to load any User controls.
How I can do that ?
Thank
Regards,
Martin
|
|
|
|
|
Please help me with this. I want to extract the information about subsequent pages using this function
VirtualQuertEx()but i don't how i can go about it.
<br />
PROCESS_INFORMATION pi; <br />
STARTUPINFO si; <br />
HANDLE hProcess; <br />
BYTE buf[20000];<br />
DWORD NumberOfBytesRead = 0;<br />
DWORD bufsize = sizeof buf;<br />
DWORD baseaddr = 0;<br />
DWORD lpAddr = 0;<br />
PMEMORY_BASIC_INFORMATION lpBuffer = 0;<br />
DWORD dwLength = 200000;<br />
DWORD flNewProtect =0;<br />
PDWORD lpflOldProtect = 0;<br />
DWORD dwSize =0;<br />
LPCVOID lpBaseAddress = 0;<br />
DWORD nSize = 0;<br />
<br />
VirtualQueryEx(<br />
hProcess,
&lpAddr,
buf,
sizeof (MEMORY_BASIC_INFORMATION));
<br />
VirtualProtectEx(<br />
hProcess,
lpAddr,
dwSize,
flNewProtect,
lpflOldProtect );
<br />
ZeroMemory(buf, sizeof(buf));<br />
if( ReadProcessMemory( hProcess, lpBaseAddress, buf, bufsize, &NumberOfBytesRead ) == FALSE )<br />
{<br />
printf("\nProcess ID %d ",pi.dwProcessId);<br />
printf (" memory read failed (errcode: %d)", GetLastError());<br />
}<br />
else<br />
{<br />
printf("\nProcess ID %d ",pi.dwProcessId);<br />
printf("memory read: \n",buf);<br />
GetLastError());<br />
}<br />
How can i retrieve the buff size from that function
oam
|
|
|
|
|