|
That's ok.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
i need to send a UDP broadcast message to a network of sensors, and i'm trying to use the CAsyncSocket class. the sensors are accepting text string commands on port 7000. here's the code:
<br />
int errorCode;<br />
<br />
if (!m_udpSocket.Create(0, SOCK_DGRAM))<br />
{<br />
AfxMessageBox("Create Error");<br />
errorCode = GetLastError();<br />
}<br />
<br />
if (m_udpSocket.SendTo("xxxxx", sizeof("xxxxx"), 7000) == SOCKET_ERROR)<br />
{<br />
AfxMessageBox("Send Error");<br />
errorCode = GetLastError();<br />
}<br />
<br />
m_udpSocket.Close();<br />
the Create() function is working, but SendTo() gives me an error. the errorCode is 0, but this doesn't seem to match any of the winsock codes on MSDN. am i missing something or leaving something out? i don't know much about networking, but i have to use UDP and the sensors don't support CArchives so i can't use CSocket. any help is greatly appreciated!
(p.s. -- if there is a syntax error or something, it's probably just my typing - i don't have my hands on the actual code atm.)
|
|
|
|
|
replace sizeof("xxxxx") with strlen("xxxxx") , and if it still doesn't work try to put this line before SendTo() .
int on = 1, optlen = sizeof(on);
m_udpSocket.SetSockOpt(SO_BROADCAST,&on,optlen);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
thanks, that answered my question perfectly!
|
|
|
|
|
i'm having the same problem now with a tcp send.
<br />
if (Connect(host, 9000) == SOCKET_ERROR)<br />
{<br />
AfxMessageBox("Error Connecting");<br />
errorCode = GetLastError();<br />
}<br />
if (Send(command, command.GetLength()) == SOCKET_ERROR)<br />
{<br />
AfxMessageBox("Error Sending Packet");<br />
errorCode = GetLastError();<br />
}<br />
the Connect() seems to work, but i get an error sending. again, the errorCode is 0. is there another option i need to set? thanks, again.
|
|
|
|
|
Hi,
i'm developing this app using MFC now i want to store some functions(MFC),controls(MFC) ect. in a dll,
i have 2 options
Regular DLL using shared MFC or MFC extension DLL
wich is better to use and what is the difference beetwen them,
thanks
~dzenan~
|
|
|
|
|
Hi:
Regular DLL: Allows you to use any MFC classes and functions, but you can only exports "C" functions.
MFC extension DLL: Allows you to export Classes that you can derive from in your client app.
hope it helps
regards
Daniel Cespedes
"There are 10 types of people, those who understand binary and those who do not"
"Santa Cruz de la Sierra Paraiso Terrenal!"
daniel.cespedes@ieee.org
|
|
|
|
|
Thanks, that's the answer i was lookig for.
~dzenan~
|
|
|
|
|
I have a COm framework where I have two classes A and B that service requests based on their respective queues .
for e.g life Sequence for Class A is as follows :
1.Class A object created
2.AddedToQueue_A event created as nonSignalled .
3.Worker thread within Class A created .
4.CLass A QUEUE is empty hence Worker thread is blocked with the call:
ResetEvent(AddedToQueue_A)<br />
WaitForSingleObject(AddedToQueue_A,INFINITE);
5. When a request is added to Queue(Enqueue) a call is made to awaken the thread like :
SetEvent(AddedtoQueue_A);
6. Thread A is awakened and the request is serviced .
Similar is the case of Class B object
Observations :
1. With Class A object present and when there is no Class B object the thread is awakened properly and the queue is serviced .
2. With Class A and CLass B objects present , the observation is that though an entry is added to the Queue of class A , Class A thread is not getting awakened everytime for some reason .the thread gets awakened every alternated time when the Queue size =2;
My question is that is the blocking statement
WaitForsingleObject() associated with the thread priority . Why isnt Class A's thread being called everytime I Set the event while enqueuing ?
|
|
|
|
|
I don't entirely get your design, but I guess it doesn't matter, because:
ResetEvent(AddedToQueue_A)
WaitForSingleObject(AddedToQueue_A,INFINITE); is fundamentally flawed. Let me explain. Suppose a request is enqueued into A when worker thread A is servicing a prior request and before it has completed to do so. When the worker thread fininshes, it resumes waiting, but before that it calls ResetEvent(AddedToQueue_A) : the signal is lost and the thread sits here waiting for ever (or until another request with more lucky timing gets in).
Instead, create AddedtoQueue_A as automatic (see the docs for CreateEvent ) and do not use ResetEvent . Good luck.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you for your insight .
I made the modification but still find that my thread (Class A)gets awakened every alternate request (i.e Queuesize=2) . This behaviour is absent when the other thread of class B is absent .
here is a snippet of my thread operation
while(threadNeedstorun){<br />
if(queueSize>0){<br />
}<br />
WaitForSingleObject(AddedtoQueue_A,INFINITE)<br />
}<br />
<br />
here is the snippet of my Enqueue operation <br />
<br />
if(queueSize<MAX_QUE_SIZE){<br />
<br />
array[(head+queueSize)%MAX_QUE_SIZE]=newVal;<br />
queueSize++;<br />
<br />
SetEvent(AddedtoQueue_A) <br />
}<br />
|
|
|
|
|
OK, this kind of stuff is always somewhat messy. Try this. Define a CRITICAL_SECTION , say CS_A (don't forget to initialize it with InitializeCriticalSection ), create AddedtoQueue_A as manual and use the following for incrementing and decrementing the number of elements in the queue:
void DecrementElementsInA()
{
EnterCriticalSection(CS_A);
--queueSize;
if(queueSize==0){
ResetEvent(AddedtoQueue_A);
}
LeaveCriticalSection(CS_A);
}
IncrementElementsInA()
{
EnterCriticalSection(CS_A);
++queueSize;
if(queueSize>0){
SetEvent(AddedtoQueue_A);
}
LeaveCriticalSection(CS_A);
} Think this sould do. Please report back, regards,
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I may be making a rash statement here, but this looks like a job for a semaphore, rather than an event.
Create a semaphore with an initial count of 0 and a huge max count (LONG_MAX or something like that). Each time a writer puts something in the queue, it calls ReleaseSemaphore. The reader(s) wait on the semaphore and remove one item from the queue each time they wake up.
--------
There are 10 types of people in this world. Those who know binary and those who don't.
|
|
|
|
|
Hi,
I was told to run these lines of code in order to instantiate a class I have that is derived from CFrameWnd (CLogViewFrame):
<br />
CRuntimeClass* pRuntimeClass = RUNTIME_CLASS( CLogViewFrame );<br />
CObject* pObject = pRuntimeClass->CreateObject();<br />
ASSERT( pObject->IsKindOf( RUNTIME_CLASS( CLogViewFrame ) ) );<br />
It compiles nice, but now, how do I access my class, how do I reach it's methods ? Non of the pointer created, can lead me to my class.
Shay
|
|
|
|
|
pObject points to your class, you just have to type cast it.
CLogViewFrame *pLogViewFrame = dynamic_cast<CLogViewFrame *>(pObject);
ASSERT (pLogViewFrame); Untested code.
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!
|
|
|
|
|
Cooooooolllllllll !!!
thanks !
|
|
|
|
|
Hi,
I have a VB ActiveX DLL, how can I add it to my VC++ project?
Its very easy in the 6.0 version, but I have trouble with .NET !!
Ehsan Behboudi
|
|
|
|
|
Hi,
Whe I used my CListBox on a dialog and wanted to scroll it programatically, I used:
<br />
list_box.SetAnchorIndex (pivot+18);
list_box.SetSel (pivot-1);<br />
<br />
<br />
But when I used CListBox as a view inside a CFrameWnd it does not work anymore, it always shows the selected line at the top.
???????????/
Shay
|
|
|
|
|
OK OK
I found it alone,
Apperantly the SetSel, scroll the view back to the top.
So what I did was to swap between the commands and now it all works
Good for me
|
|
|
|
|
God, I'm hoping some of you can help me here. I need DIRECTION.
I want to create a .NET application. I want to use C# language since it seems good for rapid application development.
I want to create the user interface (GUI) using the Visual Studio IDE form design.
Tell me if the following is possible:
I want to use DirectShow AND the Microsoft Speech .NET SDK in the SAME application. How can I do this? All the DirectShow examples are written in C++. All the .NET speech examples are written in C#.
Can I write the bulk of my application in C# and use C++ only for the DirectShow portion of it? Is this possible too?
Also, I'd like to "skin" my application, or in the very least give it some "personality" with rounded buttons and some custom controls that I create myself. Can I still use the Win32 API and "layered" windows to skin a GUI created with the "forms" wizard in Visual Studio? Is there any other way of creating that "custom" look?
I'm new to this stuff and I'm really confused. What's worse, is that I read all kinds of stuff about "managed code" and how DirectShow does not use managed code... DirectShow is built upon COM objects.... .NET allows one to mix managed and unmanaged code in the same application.... blah blah blah.... HELP!!!
All I want is some direction and advice on what to do 1st, 2nd, 3rd... I just don't know where to start... I don't want to read a 400 page book on ATL and COM if I'll be using C# which hides the COM internals... you know what I mean? HELP!!!
|
|
|
|
|
Brian JR wrote:
I just don't know where to start
A possible alternative to using DirectShow may be to use the Windows MediaPlayer ActiveX control, which may simplify the development process, but assumes all you want is fairly standard playback. If you do need to use DirectShow, start with the SDK samples, try playwnd for playback of a file. From personal experience, DirectX programming and DirectShow in particular takes a while to get used to - if you've got the time to spend learning it or after testing you know you need better performance, it's brilliant, otherwise look for a quicker solution.
Brian JR wrote:
I'd like to "skin" my application
Keep in mind that the "custom look" and "skinning" are quite different areas to DirectShow - many articles on CP can help you in this area.
Brian JR wrote:
I read all kinds of stuff about "managed code"
I haven't played much with managed extensions, but that board may be a more appropriate place to ask that question. MSDN mentions the Microsoft.DirectX.AudioVideoPlayback namespace, and there seems to be stuff for C# available.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.audiovideoplayback.asp[^]
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Thanks for the advice. I appreciate it.
Still doesn't seem that I'm further ahead than before. All the examples I've seen so far use the Win32 API to generate a GUI for DirectShow - this is not what I want. Since I'm starting out, I'd like to pick the "right" GUI platform, or perhaps something a bit easier to use. I like the "forms wizard" in C# in Visual Studio 2003. I want to stay away from MFC and WTL, if I can.
What does "CP" stand for?
Do you think it's possible to write the application in C#, use the C# forms wizard for the GUI, and wrap all the DirectShow stuff into managed code?
Seems like this is going to be a bigger challenge than I originally thought.
|
|
|
|
|
Brian JR wrote:
What does "CP" stand for?
CodeProject.
BTW, you can use unmanaged API's from C# just as easily as from C++.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
thanks.... think I'm getting closer to my answers... thank God for the internet... and these forums...
|
|
|
|
|
OK. I found this type library for DirectShow: Seems like no one else has taken this approach in all the articles I've read so far. Do you know why?
http://www.kohsuke.org/dotnet/directshowTypelib/
Does this type library solve my problem of working with DirectShow in .NET? So I can use this type library to do MC++ and C# programming?
Brian
|
|
|
|