|
I'm trying to write a client for a Windows CE 4.2 .NET device to use Bluetooth.
I'm getting a WSAEFAULT error (10014) on bind, does anyone know why this is?
The official documentation claims that its a bad pointer or too small of size. The conversion to SOCKADDR* (16bytes) is for winsock backwards compatablity, and the type SOCKADDR_BTH is 32bytes, thus the need for the the addr length in the third parameter.
WinMain
//
UINT Bluetooth_Message = RegisterWindowMessage(TEXT("BT_MSG"));
SendMessage(HWND_BROADCAST, Bluetooth_Message, 1, 0);
Sleep(1000);
printf("Bluetooth On\n");
WORD wVersionRequested = 0x202;
WSADATA m_data;
if (0 == ::WSAStartup(wVersionRequested, &m_data))
{
SOCKET s = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
DWORD lastError = ::GetLastError();
if (s == INVALID_SOCKET)
{
printf("Failed to get bluetooth socket! %s\n", GetLastErrorMessage(lastError));
exit(1);
}
printf(" socket Call completed: [0x%x] with ws: %d:%d\n", s, HIBYTE(m_data.wVersion), LOBYTE(m_data.wVersion));
SOCKADDR_BTH address= { 0 };
ZeroMemory(&address,sizeof(SOCKADDR_BTH));
address.addressFamily= AF_BTH;
address.btAddr= 0x0;
address.port= BT_PORT_ANY;
// address.serviceClassId= 0l;
SOCKADDR * pAddr=(SOCKADDR*)&address;
int nAddressSize= sizeof(SOCKADDR_BTH);
if (SOCKET_ERROR == bind(s, (const sockaddr*) &address, nAddressSize))
{
printf("Error with bind:\r\nWSAERROR: %d\n", WSAGetLastError());
printf("Sizes: SKB > %d", sizeof(SOCKADDR_BTH));
printf(" %d <adr ",="" sizeof(address));
="" printf("="" ska="" %d",="" sizeof(sockaddr));
="" %d\n",="" printf("\t="" saa="" %d="" naddrsize="" sizeof(*paddr),="" naddresssize);
="" printf("skabth:="" %u="" %l\n"="" ,="" address.addressfamily,="" address.port,="" address.btaddr);
=""
sleep(3000);
="" return="" -1;
="" }
this="" returns:
connected="" [1],="" 2;2
error="" with="" bind\r\nwsaerror:="" 10014
sizes="" skb="" 32="" addr="" ...="" naddresssize="" 32
...
i'm="" following="" the="" documentation="" (http:="" msdn2.microsoft.com="" en-us="" library="" ms863315.aspx)="" does="" anyone="" know="" how="" or="" why="" i'm="" getting="" this="" error?="" right="" now="" stuck="" on="" that="" problem="" because="" i="" can't="" tell="" it="" to="" listen="" without="" a="" bind.
=""
<div="" class="ForumSig">-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
I can't seem to see anything wrong except it looks to me like the size of a SOCKADDR_BTH should
be 30, not 32.
...
#include <pshpack1.h>
...
typedef struct _SOCKADDR_BTH
{
USHORT addressFamily;
BTH_ADDR btAddr;
GUID serviceClassId;
ULONG port;
} SOCKADDR_BTH, *PSOCKADDR_BTH;
Am I calculating that length wrong?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Yep, structs are aligned 4bytes .... But I have tried using thirty in the length argument and it didn't make a difference. Although I can go up to sizeof(SOCKADDR_BTH)+8 that and after I'll get a Winsock error 10049.
-Steven Hicks CPACodeProjectAddict
|
|
|
|
|
(Steven Hicks)n+1 wrote: Yep, structs are aligned 4bytes
What? That's not the case at all, unless you specify it somewhere.
Maybe you are using a different SDK, but the ws2bth.h from PSDK 2003 R2 sets the structure
packing in the entire header to 1, which is why I included that line in my response.
sizeof(SOCKADDR_BTH) returns 30 on my system.
I am Curious why it's 32 on your build. What header files do you use and from where?
Of course, this still doesn't explain why substituting 30 doesn't work.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I'm using the CeGCC compiler for Linux to create PPC executables, along with it I'm using an older sdk, probably from eVC 4. Right now I have no idea why this isn't working.I've looked through many examples and I'm doing everything correct socket initialization etc and I'm still running up on this problem. The code compiles but this crashes on runtime.
-Steven Hicks CPACodeProjectAddict
|
|
|
|
|
(Steven Hicks)n+1 wrote: Right now I have no idea why this isn't working.
Me neither, sorry! The original code looked like good Winsock calls to me
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
You are calculating that correctly (2 8 16 4)....could this be a platform issue with allignment? Size of SOCKADDR_BTH is returning 32.
Could you test sizeof(SOCKADDR_BTH) on your machine?
-Steven Hicks CPACodeProjectAddict
|
|
|
|
|
(Steven Hicks)n+1 wrote: could this be a platform issue with allignment? Size of SOCKADDR_BTH is returning 32.
Could you test sizeof(SOCKADDR_BTH) on your machine?
That's what I was wondering originally. Using Platform SDK for Windows Server 2003 R2 header
files, sizeof(SOCKADDR_BTH) returns 30.
I was thinking it may be different building for CE but I can't find anything that indicates that
it should be.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I've used SetWindowsHookEx() and placed the hook procedure in a DLL, as it is a global hook.. I was just wondering how I call the CallNextHookEx() API from the hook procedure in the DLL because the first parameter is the hook handle, which I don't have access to, as SetWindowsHookEx() is called from the actual executable. Is there a way of obtaining this hook handle, or sharing the handle with the DLL from the executable code?
I'm working in C/C++ so no MFC
Thanks for your help!
--PerspX
|
|
|
|
|
Using Share data section.
|
|
|
|
|
What we usually do is that we write a function in the dll( eg - InstallHook )and from that function, the SetWindowsHookEx() is called. So the application that install hook normally call the InstallHook() function. The handle returned by the SetWindowsHookEx() is kept in a shared data segment in the dll itself.
nave
|
|
|
|
|
Hello,
what is a string table ? Why all the strings added in the program not seen in the string table.
What should be seen the string table
Prithaa
|
|
|
|
|
The strings that you added to the string table will be visible there. It's not a case of the IDE building a table of all strings, but of you building a list of strings to store and reference from there. This gives you a central location for, for example, changing hte language of your application.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
prithaa wrote: what is a string table ?
From MSDN:
It's a Windows resource that contains a list of IDs, values, and captions for all the strings of your application. String tables make it easy to localize your application into different languages. If all strings are in a string table, you can localize the application by translating the strings (and other resources) without changing source code.
prithaa wrote: Why all the strings added in the program not seen in the string table.
Don't confuse the string table resource with string literals.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello,
I made some chnages in the my program and because of which I am not able to view the string table in my resourse file.
And when I go to Resource file ,it says Load failed.
How do I get my resource files back?
|
|
|
|
|
When the loading fails, it usually pops up a dialog asking you whether to edit resource manually. It will guide you to the location of thr .rc file where the problem occurred. In many cases, you can fix the .rc file manually. Then reload the resource again.
Best,
Jun
|
|
|
|
|
Close your project and visual studio. Goto the folder where your projects ".sln" file is present. Double click it. It will open and load the resource file also. (Not 100% sure abt your system). But tell me if it is working in your system.
Anurag Gandhi.
|
|
|
|
|
Hello,
My project folder doesnot have .sln file. Now what should I do.
Now if I want to insert a dialog I am not able to do it.
When I click on .rc file I get a pain text file which has code written in it within BEGIN END
Prithaa
|
|
|
|
|
prithaa wrote: My project folder doesnot have .sln file. Now what should I do.
Verify whether you are using VS6 or VS200x.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello,
I have a command line application – developed by someone else and I need to be able to get the text from it (at some point that application writes in the command line window that a task is completed and I need to know when that occurs). I am able to find the window by the GetWindowText returns me the window name – which I already use for finding the window and the
<br />
::SendMessage(hwnd,EM_SETSEL,0,-1);
::SendMessage(hwnd,WM_COPY,0,0);<br />
::SendMessage(hwnd,EM_SETSEL,-1,0);
<br />
if (!IsClipboardFormatAvailable(CF_TEXT)) <br />
return TRUE; <br />
<br />
if (! ::OpenClipboard(NULL)) <br />
return TRUE; <br />
<br />
hglb = GetClipboardData(CF_TEXT);
is not working.
If anyone knows a way to solve this problem – please let me know. Thanks.
|
|
|
|
|
|
Thank you.
I had just try the sample and it seems to work .
Thanks!
|
|
|
|
|
Hi all
I have a server on a Windows machine that should accept client connections to send them data. This server is distributed with a software and all I have to do is to write the client application using socket programming.
If I write the client under Windows, it will work correct. But if I write the client under Linux, the client cannot connect to the server returning the error 'Connection timed out'. I use C++ and C# under Windows and C under Linux.
To make sure that my Linux client is correct, I wrote a server application under Linux and they worked correct. So I think that the problem is in Windows-Linux communication.
Any help...
Regards
islheg
|
|
|
|
|
Dumb question but do you have the correct server address?
-Steven Hicks CPACodeProjectAddict
|
|
|
|
|
Yes, and I can connect to it using telnet.
|
|
|
|