|
Yes, it is platform independent, but you need to take care below points when going across different platform (in terms of processer)
1) Before send data, convert your data in to network type. (ex. using "htonl" function.)
2) if you passing whole structure as a binary data then need to take care about padding. (use __attribute__((__packed__)))
Parag Patel
Sr. Software Eng, Varaha Systems
|
|
|
|
|
thanks.
But now i can't send or receive the data from Toolkit which i download. My application is in VC++ and Toolkit is in Java. Is there any function i have to add in my application.
|
|
|
|
|
Abhijit D. Babar wrote: But now i can't send or receive the data from Toolkit which i download. My application is in VC++ and Toolkit is in Java. Is there any function i have to add in my application.
is your toolkit is Socket server or socketclient. Are you connecting on right socket port?
"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
|
|
|
|
|
After running your application at both side (server/client) check that your application able to bind on that port or not? You can use "netstat" command in window.
Parag Patel
Sr. Software Eng, Varaha Systems
|
|
|
|
|
I use netstat and Telnet also and it bind the socket. But when i try to run my client program, it will wait or stop on "connect" function.
I place the client code below, please see, where is the problem.
/// Client code ////
CString str;
int sock,iResult,iOptVal,iSenderAddrSize;
int BUFF_SIZE = 30,iError;
char recv_data[30];
char* localIP = "";
struct sockaddr_in server_addr,SenderAddr;
struct hostent * lpHostEntry;
WSADATA wsaData;
iSenderAddrSize = sizeof(SenderAddr);
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != NO_ERROR)
AfxMessageBox(_T("Error at WSAStartup()\n"));
if ((sock = socket(AF_INET, SOCK_STREAM,0)) == -1)
AfxMessageBox(_T("Error at Socket"));
gethostname(localIP,56);
lpHostEntry = gethostbyname(localIP);
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(2050);
server_addr.sin_addr.s_addr = inet_addr("192.168.1.9");
iError = connect( sock, (SOCKADDR*) &server_addr, sizeof(server_addr) );
if(iError == SOCKET_ERROR){
iError = WSAGetLastError();
CString s1;
s1.Format(_T("Connect Error = %d"),iError);
AfxMessageBox(s1);
exit(1);
}
while(1){
memset(recv_data,0,sizeof(recv_data));
int iResult = recv(sock,recv_data,BUFF_SIZE,0) ;
if(iResult > 0)
{
recv_data[BUFF_SIZE] = '\0';
str = inet_ntoa(SenderAddr.sin_addr);
AfxMessageBox(str);
}
else{
iError = WSAGetLastError();
}
}
////////
When i run my Server program, it will stop or wait on "accept" function.
//// Server code /////
int sock, connected, bytes_recieved ;
char send_data [1024] , recv_data[1024];
CString str,s;
struct sockaddr_in server_addr,client_addr;
int sin_size;
int iResult;
WSADATA wsaData;
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != NO_ERROR)
AfxMessageBox(_T("Error at WSAStartup()\n"));
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
AfxMessageBox(_T("Socket"));
exit(1);
}
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(2050);
server_addr.sin_addr.s_addr = INADDR_ANY;
//bzero(&(server_addr.sin_zero),8);
if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr))== -1)
{
AfxMessageBox(_T("Unable to bind"));
exit(1);
}
iResult = listen(sock, 1);
if(iResult == SOCKET_ERROR){
AfxMessageBox(_T("Listen"));
iResult = WSAGetLastError();
exit(1);
}
while(1)
{
sin_size = sizeof(struct sockaddr_in);
connected = accept(sock, (struct sockaddr *)&client_addr,&sin_size);
if(connected == INVALID_SOCKET ){
AfxMessageBox(_T("Invalid socket"));
}
CString strIPAddress;
strIPAddress = inet_ntoa(client_addr.sin_addr);
str.Format(_T("\n get a connection from (%s , %d)"),strIPAddress,ntohs(client_addr.sin_port));
char *sendbuf = "CMS";
while(1)
{
iResult = send(connected, sendbuf, (int)strlen(sendbuf), 0 );
if(iResult == SOCKET_ERROR){
iResult = WSAGetLastError();
s.Format(_T("send Error= %d"),iResult);
AfxMessageBox(s);
}
if(iResult > 1) {
s.Format(_T("String Length = %d"),iResult);
AfxMessageBox(s);
}
}
}
please reply....
|
|
|
|
|
Hey man, code is working, i have tested it.
I think something else in your application which is causing issue.
Just cross check below basic things
1. Message box not going background, and thats why you are feeling that program is stuck.
2. You have given right IP at client side.
Parag Patel
Sr. Software Eng, Varaha Systems
|
|
|
|
|
Hi,
May i know whther is it possible to use UrldownloadToFile in batch file...if yes pls let me know...
|
|
|
|
|
I don't think so. However, you can use the API in an executable and run the executable from a batch file (command line parameters to control it, may be).
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
What does mean to use UrldownloadToFile in batch file?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Yes, if you write a exe which uses the call.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
yes you can, if you know how to load the dll and invote the api from it in bacth file.
"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
|
|
|
|
|
Have you tried RunDll32.exe?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi All
I have a problem to get information of connected USB Device.I am useing
OnMyDeviceChange(WPARAM wParam, LPARAM lParam); function which is provide me all information.But when USB Device is connected all ready and my application is start after connecteion of USB Device then i havn't found any information of USB Device.Can any one give me advice to how to get connected USB Device information.Plz help me
|
|
|
|
|
1.You must use RegisterDeviceNotification() to let system notify you application.
2.Add message handler for WM_DEVICECHANGE .
|
|
|
|
|
i am useing both RegisterDeviceNotification and WM_DEVICECHANGE.And i am getting information when my application is running and USB Device is connect.But When my application is not running and USB drive is connected and my application is start after connection of USB Device then information is not showing.But USb Device is still connected.
So problem is that how to get information allready connection of USB Device.Plz help me
|
|
|
|
|
|
See http://www.beyondlogic.org/[^].
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Your RegisterDeviceNotification[^] code is probably working correctly, however it will only detect changes while your application is running.
You failed to mention what type of USB device your application needs to enumerate. I will assume that you need all USB device types. You will essentially need to call SetupDiGetClassDevs[^] and pass the enumerator filter of "USB". Dont be frightened by the Windows Driver Kit references in the MSDN documentation. You will be able to use the SetupAPI without the DDK installed, although I believe you will need Platform SDK/Microsoft SDK.
The following link should be enough to get you started:
How to enumerate hardware devices by using SetupDi calls[^]
You should modify the Microsoft sample code to something like the following:
#pragma comment (lib,"Setupapi.lib")
hDevInfo = SetupDiGetClassDevs(NULL,"USB", 0,DIGCF_PRESENT | DIGCF_ALLCLASSES );
You can perform additional device filtering using the System-Supplied Device Setup Classes[^] or other Enumerator strings such as "USBSTOR".
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
Have a look at the my article [^] which describes a class a wrote for detecting devices. The example screen shots show the detection of USB devices, amongst others. The code example
const GUID Guid = GUID_DEVCLASS_USB;
CDevInfo cDevInfo(m_hWnd, DIGCF_PRESENT , &Guid); shows how to use the class to detect just USB devices actually present.
|
|
|
|
|
Getting error
al error C1083: Cannot open include file: 'atlapp.h': No such file or directory
|
|
|
|
|
AtlApp.h is part of WTL. The article uses WTL for the windows, dialogs, listboxes etc. I guess you're using MFC?
|
|
|
|
|
|
OK, the classes depend on WTL, but I just tried some code an MFC dialog and started getting names of devices. I put this in OnInitDialog to test it as the first wizard generated comment shows. Try it. You'll need to #include devguid.h; and then put a break point on nMemberIndex++; and look at the name in szFriendlyName . After the first name go round the loop looking at the names.
const GUID Guid = GUID_DEVCLASS_PORTS;
DWORD Flags = DIGCF_PRESENT | DIGCF_DEVICEINTERFACE;
HDEVINFO hDevInfo = SetupDiGetClassDevs(&Guid, 0, 0, Flags);
BOOL bDevInfo;
int nMemberIndex = 0;
do{
SP_DEVINFO_DATA spDevInfoData;
spDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
bDevInfo = ::SetupDiEnumDeviceInfo(hDevInfo, nMemberIndex, &spDevInfoData);
DWORD Property = SPDRP_FRIENDLYNAME;
wchar_t szFriendlyName[1024] = {0};
BOOL bGotRegProp = ::SetupDiGetDeviceRegistryProperty(hDevInfo, &spDevInfoData,
Property,
0L,
(PBYTE)szFriendlyName,
2048,
0);
nMemberIndex++;
}
while(bDevInfo);
Once you have this working then change GUID_DEVCLASS_PORTS for something that finds your device, but start with it as it is then were running the same code.
|
|
|
|
|
Hi all,
I am trying to show single-frame/animated GIF images in a window created by 'CreateWindowEx'. I have used Image *, Graphics * (method DrawImage(Image *, INT, INT, INT, INT)) of GdiPlus dll. I used memry DC to avoid flickering. This was working fine.
Now the problem is that - When I add 2 commands /DYNAMICBASE and /NXCOMPAT in linker command line (VS 2005 project settings), the application simply crashes when trying to show any kind of GIF image. Although it is showing BMP, DIB, WMF, JPG, JPEG and TIFF images perfectly.
To see where the actual problem is i ran it in debug mode and find GdiPlus::Graphics::DrawImage fail to process. The Application Verifier 4.0 points that it is due to some bad address pointer. The astonishinig matter is that, in debug mode if I ignore the crash and click on 'Continue', the 'DrawImagw' returns StatusResult "Ok" and 'BitBilt' draws the image perfectly in my application window.
Thanks in advance, for helping me out of this situation.
Subha
|
|
|
|
|
why not use try-catch block to fix this problem?
|
|
|
|
|