|
I run 1 or 2 thread at button click and on second button click I am closing dialog box but I am checking before closing thread to treminate.
pThreadHandle = new HANDLE[nCount] ;
....
....
....
WaitForMultipleObjects(nCount,pThreadHandle,TRUE,INFINITE)
But It goes in infinte lopp and dialog never ends. How it is wating for infinite?
Give me suggestion to do so.
|
|
|
|
|
need to check your thread function, how are you closing/intimating your thread to close? let us know the function code!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
One of your thread function might not be exiting. Do they have any looping code ?
It's better you post your thread functions here.
|
|
|
|
|
Either of the threads are not exiting.
Put some logging code like OutputDebugString or printf or write something to a file from the thread so that you can get at what is going on inside the thread.
|
|
|
|
|
Hi,
In the application which I'm working on. Bluetooth server on pc, exchanges text with bluetooth client on mobile.
I would like to what is the GUID needs to be registered for this text exchange service.
I'm currently using
GUID serviceID = OBEXFileTransferServiceClass_UUID;
But it doesn't seem to work.
Thanks in advance.
Regards,
Vijay.
|
|
|
|
|
OBEX is used to send files.
For sending simple text, use SerialPortServiceClass_UUID .
|
|
|
|
|
HI,
I'm using windows 7 , 64 bit os, and had written bluetooth server program running on this pc.
This server will accept connections from clients , and display the text sent by clients.
My issue is , Bluetooth server running on PC, is not receiving data sent from clients, but connection establishment is successful.
What I mean is, after executing "recv(s2,(char*)buffer, sizeof(buffer), 0);" function call, the server is blocked indefinitely.
Please let me know how this issue could be resolved.
#include "stdafx.h"
#include <WinSock2.h>
#include <ws2bth.h>
#include <bthsdpdef.h>
#include <BluetoothAPIs.h>
#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "irprops.lib")
TCHAR *GetLastErrorMessage(DWORD last_error)
{
static TCHAR errmsg[512];
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
0,
last_error,
0,
errmsg,
511,
NULL))
{
return (GetLastErrorMessage(GetLastError()));
}
return errmsg;
}
int _tmain(int argc, _TCHAR* argv[])
{
WORD wVersionRequested = 0x202;
WSADATA m_data;
if (0 == WSAStartup(wVersionRequested, &m_data))
{
SOCKET s = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
const DWORD lastError = ::GetLastError();
if (s == INVALID_SOCKET)
{
printf("Failed to get bluetooth socket! %s\n", GetLastErrorMessage(lastError));
exit(1);
}
WSAPROTOCOL_INFO protocolInfo;
int protocolInfoSize = sizeof(protocolInfo);
if (0 != getsockopt(s, SOL_SOCKET, SO_PROTOCOL_INFO, (char*)&protocolInfo, &protocolInfoSize))
{
exit(1);
}
SOCKADDR_BTH address;
address.addressFamily = AF_BTH;
address.btAddr = 0;
address.serviceClassId = GUID_NULL;
address.port = BT_PORT_ANY;
sockaddr *pAddr = (sockaddr*)&address;
if (0 != bind(s, pAddr, sizeof(SOCKADDR_BTH)))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}
else
{
printf("\nBinding Successful....\n");
int length = sizeof(SOCKADDR_BTH) ;
getsockname(s,(sockaddr*)&address,&length);
wprintf (L"Local Bluetooth device is %04x%08x \nServer channel = %d\n", GET_NAP(address.btAddr), GET_SAP(address.btAddr), address.port);
}
int size = sizeof(SOCKADDR_BTH);
if (0 != getsockname(s, pAddr, &size))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}
if (0 != listen(s, 10))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}
WSAQUERYSET service;
memset(&service, 0, sizeof(service));
service.dwSize = sizeof(service);
service.lpszServiceInstanceName = _T("Accelerometer Data...");
service.lpszComment = _T("Pushing data to PC");
GUID serviceID = OBEXFileTransferServiceClass_UUID;
service.lpServiceClassId = &serviceID;
service.dwNumberOfCsAddrs = 1;
service.dwNameSpace = NS_BTH;
CSADDR_INFO csAddr;
memset(&csAddr, 0, sizeof(csAddr));
csAddr.LocalAddr.iSockaddrLength = sizeof(SOCKADDR_BTH);
csAddr.LocalAddr.lpSockaddr = pAddr;
csAddr.iSocketType = SOCK_STREAM;
csAddr.iProtocol = BTHPROTO_RFCOMM;
service.lpcsaBuffer = &csAddr;
if (0 != WSASetService(&service, RNRSERVICE_REGISTER, 0))
{
printf("Service registration failed....");
printf("%d\n", GetLastErrorMessage(GetLastError()));
}
else
{
printf("\nService registration Successful....\n");
}
printf("\nBefore accept.........");
SOCKADDR_BTH sab2;
int ilen = sizeof(sab2);
SOCKET s2 = accept (s,(sockaddr*)&sab2, &ilen);
if (s2 == INVALID_SOCKET)
{
wprintf (L"Socket bind, error %d\n", WSAGetLastError ());
}
wprintf (L"\nConnection came from %04x%08x to channel %d\n",
GET_NAP(sab2.btAddr), GET_SAP(sab2.btAddr), sab2.port);
wprintf (L"\nAfter Accept\n");
unsigned char buffer[2000];
while(1)
{
memset(buffer, 0, sizeof(buffer));
int r = recv(s2,(char*)buffer, sizeof(buffer), 0);
printf("Error = %d\n",WSAGetLastError() );
wprintf(L"Received : %s\n",buffer);
Sleep(500);
}
closesocket(s2);
if (0 != WSASetService(&service, RNRSERVICE_DELETE, 0))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}
closesocket(s);
WSACleanup();
}
return 0 ;
}
Here is the snapshot, where you can see server is waiting, (executing recv())
http://dl.dropbox.com/u/37131873/Pics/6675.jpg[^]
Thanks in advance.
Regards,
Vijay.
|
|
|
|
|
Use SerialPortServiceClass_UUID for the serviceClassId parameter.
|
|
|
|
|
Hello to everybody,
I wrote a simple code for data reading and writing from USB HID device.
My code looks as follows:
HidDeviceObject = CreateFile (
(LPCTSTR)DevicePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
(LPSECURITY_ATTRIBUTES)NULL,
OPEN_EXISTING,
0,
NULL);
In this way I open device for communication (synchronously).
Now I create two threads, one for data reading and one for data writing to device.
This is read thread:
while(TRUE)
{
if(!WRITE_BUTTON)
{
if (HidDeviceObject != INVALID_HANDLE_VALUE)
{
CancelIo(HidDeviceObject);
int Result = ReadFile(HidDeviceObject, &InputReport, sizeof(InputReport), & NumberOfBytesRead,NULL);
}
}
}
where WRITE_BUTTON is flag( if I click on write button in my GUI, WRITE_BUTTON is equal to 1, else 0)
My write thread is:
while(TRUE)
{
if(WRITE_BUTTON)
{
if (HidDeviceObject != INVALID_HANDLE_VALUE)
{
CancelIo(HidDeviceObject);
int Result = WriteFile(HidDeviceObject,&OutputReport, sizeof(OutputReport), & NumberOfBytesWriten, NULL);
WRITE_ROPRT = FALSE;
}
}
I am new in thread programing, and I need help fast. If I comment one of the threads, second one works fine. Where is my mistake? How to make them to works together in the same time? I want to send some data to device and wait for device to respond to me. When I open device with async flag (asynchronously) ( instead 0 in CreateFile function, I put FILE_FLAG_OVERLAPPED) threads works fine together, and I can send data to device and "capture" response from it.
Thanks
|
|
|
|
|
|
Hi!
I've developed a dialog based MFC application which embeds flash movie(.swf files) in it. Some more things I've used in this application are:
(i) CInternetSession
(ii)IXMLHTTPRequestPtr
I've to port this application to Linux and Mac. Is it possible? If yes, what tool is needed(Of course, it should be free)? Will Linux and Mac support .OCX(Activex) components?
modified on Monday, August 29, 2011 5:12 AM
|
|
|
|
|
|
Do I need to install any specific library to port my application? Or changing the class and Event names as told is enough?
|
|
|
|
|
wxWidgets is a library (just like MFC is)... it needs to be installed to be used...
|
|
|
|
|
Consider to use Qt if wanting to implement a cross platform native application.
Another alternative is to use Silverlight and .NET.
|
|
|
|
|
Hi!
Is it available free? Won't there be any license issues? Can you please confirm these things before I decide to use Qt? If it's payable, how much is the cost?
modified on Tuesday, August 30, 2011 1:12 AM
|
|
|
|
|
|
Hi all,
i want to write multiple files inside a loop simultaneously. But how many files will be written at a time will be decided at run time but, i know the maximum limit can be 15.
I am not getting how to create object of class FILE and then how to access them.
Can anybody help me in this.
Thanks in advance
|
|
|
|
|
Can this[^] and this[^] help you?
-Sarath.
Rate the answers and close your posts if it's answered
|
|
|
|
|
Create using fopen[^]
Write using fwrite[^], fputs[^], fprintf[^] and alike.
Close by fclose[^].
The fopen page even has a small example around the bottom.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Usually it gives very bad performance to write to multiple files at the same time. Maybe this has changed with the introduction of SSD disks.
|
|
|
|
|
Hi ,
I am converting my 32 bit windows application in VC++ into 64 bit windows application. I convert it with configuration setting req. for 64 bit platform. But when i check performance of 64 bit application, it is same as 32 bit. I did not found any improvement is speed execution of application. What changes i need to do in C++ VC++ code to speed up the execution of my application on windows 64 bit OS.
Regards
abm
|
|
|
|
|
There is no performance improvement by converting to 64 bit, unless your application performs lots of 64 bit calculations.
The main reason for converting to 64 bit is to get access lots of RAM, so one is not restricted by the usual 1-2 GByte RAM. The minor reason is that in 10-15 years the 32 bit platform will no longer be supported (Like 16 bit was abandoned with Win7)
See also Find out if you need the 64-bit version of your product[^]
|
|
|
|
|
Just to add a little to the previous post:
There is a minor performance improvement for all programs in terms of function calls. The calling conventions have been optimised for speed, by passing the first few arguments via the CPU registries.
However, this increase is only seen if your application uses a lot of function calls. Mostly, the compiler tries to avoid them in the first place, such as using inlining.
Also, if you make lots of API calls then you should see a small increase, as the WoW64 subsystem is taken out between the application and the Windows kernel (which does the conversion to the new calling convention for the 32 bits applications).
But, mostly, 64 bits is for the increase in address space, the most noticeable example being that you can use more than 4 GiB of RAM in your system.
|
|
|
|
|
I was messing around with resource files and such in C#.
I found out that with a Compiled Resource Script you can add multiple icons to your applications.
Then I found out that a manifest file allows you to force it to be run as admin.
But a choice has to be made between the two (in c#).
I came to the conclusion that the Compiled Resource Script must contain a manifest.(if this is faulty, please correct me.)
I took a quick look into Resource Scripts (RC) C++ and saw something of a structure.
IDI_ICON1 ICON "file.ico"
IDB_BITMAP1 BITMAP "file.bmp"
Taking a peek in the Resource.h file that was generated I noticed the definition for IDI_ICON1, same goes for IDB_BITMAP1. ICON and BITMAP seem keywords for the Resource Compiler (can't find their definitions in #includes).
But what if I want to add a manifest?
IDM_MAN MANIFEST "file.manifest"
ends up with a folder called "Manifest" (including quotes, which does not happen with ICON and BITMAP).
I've seen MSDN saying that a manifest can be to an existing (post-compile) binary file, but can it be done with Resource Script, compiled with RC.exe?
The first rule of CListCtrl is you do not talk about CListCtrl - kornman
|
|
|
|
|