|
Hi all.
I have two threads ... one as a sender and the other a receiver for data sent over sockets. But the sockets are being created and handled in a dll ( a VC# dll which has a class named Class1). so when I call these threads I have to pass the object of the class in the dll because the sender and receiver use the same sockets right!!.
Here is what I have in the sender and receiver threads... ( and I dont know a work around for the DoEvents thing, because I have to enforce the processor to do other tasks while the thread is in a while loop .... and I have removed the doevents completely as well and it doesnt make any difference. So the problem is not with doevents).
DWORD WINAPI SenderThread(LPVOID iValue)
{
Mutex^ mut = gcnew Mutex();
mut->WaitOne();
Class1^ senderdll = *((Class1^*)iValue);
mut->Close();
int returnval;
DoEvents();
while(true)
{
returnval = senderdll->SenderEntryPoint();
if(returnval == 1) // sockets closed
{
break;
//dynamic_cast<autoresetevent^>(stateInfo)->Set();
}
}
return 0;
}
DWORD WINAPI ReceiverThread(LPVOID iValue)
{
Mutex^ mut = gcnew Mutex();
mut->WaitOne();
Class1^ receiverdll = *((Class1^*)iValue);
mut->Close ();
int returnval;
DoEvents();
while(true)
{
returnval = receiverdll->ReceiverEntryPoint();
if(returnval == 1) // the sockets closed
break;
}
return 0;
}
and here is how I am creating these threads. (The cmdListen_Click function creates the sockets.)
Class1^ c = gcnew Class1();
c->cmdListen_Click(NewPosition);//call the dll function to create sockets
////Threads start
DWORD dwGenericThread;
hThread2 = CreateThread(NULL,0,SenderThread,&c,0,&dwGenericThread);//the sender thread
if(hThread2 == NULL)
{
DWORD dwError = GetLastError();
return 0;
}
hThread3 = CreateThread(NULL,0,ReceiverThread,&c,0,&dwGenericThread);//the receiver thread
if(hThread3 == NULL)
{
DWORD dwError = GetLastError();
return 0;
}
//////Threads end
Now the two problems I am facing are:
1) How do I synchronize the threads? The AutoResetEvent (as given in http://msdn2.microsoft.com/en-us/library/system.threading.autoresetevent.aspx), uses a threadpool to create threads. My problem is if I use the threadpool instead of using the CreateThread how do I pass the Class1 object in the threads ?
2) My second problem is the AccessViolation error, which I am getting at the point where I create the instance of the Class in the thread. ( in both sender or receiver, depending upon which thread I am creating first !!).
Class1^ receiverdll = *((Class1^*)iValue);
What am I doing wrong here? When I was getting an access violation error in VC#, I used LOCK to enforce resource allocation. How do I do this in VC++?
Thanks.
|
|
|
|
|
Try posting your C++/CLI questions here[^]
|
|
|
|
|
Does anybody know which string would expand to "C:\Windows\Profiles\<username>\ ", I believe this path exists on Win98 & ME.
Or better still, does anybody know of a reference list for these strings? MSDN has come up a little short on this api
|
|
|
|
|
That would be %USERPROFILE%
|
|
|
|
|
Thanks for that. It expands to something different on Vista, and since I don't have access to a 98 machine, it's better to ask :p
|
|
|
|
|
|
Invisible window? Don't create a console app, instead create a windows app and don't show the window.
|
|
|
|
|
|
is there any way to change it in the registry? or any way to change it without hacking explorer.exe?
|
|
|
|
|
of course on the codeproject you can see an example of Start Button I'm not its helpful for you but see it
|
|
|
|
|
Hello all this is my first post here,
just a quick question, how do I create a program using vstudio2005, and be able to run
in on other windows machine.
thank you
|
|
|
|
|
The biggest reason programs won't run on previous versions is because the programer chooses functions that are not supported. When making your program, refer to MSDN for the api calls, MSDN lists the minimum version of windows required.
|
|
|
|
|
Hi WalderMort,
The only difference between the two system is that the other one does not have
visual studio 2005, so I was just wondering if this is/are one of the reason the exe I created does not run,
the exe was from a beginners tutorial from this site.
thank you
ennm4
|
|
|
|
|
What error are you getting? It sounds as though the exe is looking for a dll that may not be on your other PC.
|
|
|
|
|
Well , when I run the exe file , I got the following msg
"The application failed to start because incorrect configuration. Reinstalling may fix it"
I created the exe , by using the build option on the visual studio 2005 ide, this is the correct way right?
thanks again
ennma
|
|
|
|
|
I see, By default VS2005 adds a manifest file to the exe, this file will prevent the exe from running unless specific dlls are in a specific directory. Try excluding the manifest from your app, or add the required dll's, in the correct directory ( sorry I can't remember which ).
|
|
|
|
|
WalderMort wrote: By default VS2005 adds a manifest file to the exe, this file will prevent the exe from running unless specific dlls are in a specific directory.
No, it’s because VS2005 targets the latest C Run time. It is no longer a matter of just distributing the latest DLLs they have to be installed onto the target system. See Mark Salsbery's post for further information.
Redistributing Visual C++ Files[^]
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
ennm4 wrote: how do I create a program using vstudio2005, and be able to run
in on other windows machine.
Become part of the solution, not part of the problem
Redistributing Visual C++ Files[^]
|
|
|
|
|
hello to everybody.
i have a problem about polynomials by using c which includes a link command to mupad. but i am new at c++ and mupad programmes, and i cant find examples about the mixture of c and mupad.
1) the c programme must be able to take the degree and constants and sensitivity of the polynomial from user.
2) the programme must be able to find a root of the polynomial with a given initial value by using Newton-Raphson method.
3) the programme must be able to sense that is subjected to multiple root, and it must be able to prevent the negativities of this condition.
4) and the programme must do the steps 2 and 3 by using mupad.
if somebody can help me about this soon, i will be very grateful.
have a nice day to everybody...
|
|
|
|
|
You asked this question before. See the replies you received...
If you try to write that in English, I might be able to understand more than a fraction of it. - Guffa
|
|
|
|
|
I need a way to get the name of the application owning the foreground window. I would also like to monitor this rather than constantly polling it. I assume this would involve some use of GetForegroundWindow() function and WM_ACTIVATEAPP notification but can't seem to figure it out exactly.
|
|
|
|
|
Retrieval:
- GetWindowThreadProcessId and obtain process ID;
- pass the ID to OpenProcess and obtain the process HANDLE (PROCESS_QUERY_INFORMATION will suffice);
- call GetProcessImageFileName on process handle to get full path of the executable file.
Monitoring (without polling):
- implement a global hook in a dll, with SetWindowsHookEx and WH_CALLWNDPROC(RET) or maybe WH_CBT; inside hook procedure, do nothing more than look for message(s) WM_ACTIVATE, WM_ACTIVATEAPP and whatever other messages you may need to figure when active window is changing; send the appropriate notification to the executable on the next point;
- implement an executable to process the notification from the hook dll;
- use a communication mechanism (named pipe for example, or even mailslots since hook dll and executable are local); the dll will write and the exe will read; anything else will do, just be careful to not break the hook dll.
|
|
|
|
|
I'm trying to program a dialog which has a "canvas" for me to draw lines and text.
The general idea is to have a dialog with editboxes etc for inputing line coordinates and text to display on a canvas.
Any help appreciated.
|
|
|
|
|
What part are you having problems with?
|
|
|
|
|
what exactly u seeking for ? u can draw lines on WM_PAINT messages comes. u can also draw text using TextOut or DrawText . But why you need to enter position for line ? or is it any 3d coordinates etc ?
If u can Dream... U can do it
|
|
|
|