|
Well after reading a lot about this topic, I have found that this covers a different side of programming I am unfamiliar with.
I have read countless source codes all using winsock.h and have no idea how to properly use this.
Would there be a good tutorial around here explaining C++ programming in conjunction with Networking? I am more familiar with a different aspect of C++.
Thank you again for all the help.
V/R
Rob
|
|
|
|
|
If you are doing what I think you're doing, and writing an application to look at all network traffic passing your computer, then the subject is just plain difficult.
If you are wanting client / server software to talk between computers, then it's a lot easier. Just look in the networking section of codeproject, and there;s a whole range of articles there, from simple chat between 2 pc programs, to full fledged servers.
Either way, it's not an easy topic!
Good luck,
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
Ok, so I have done more reading.
I have been reading about winsocks. I due have a question. Here is the code I have been piecing together. Can someone please tell me what I am doing wrong? I get a compiling error "using Dev++" on line 105. I know I am new to programming with sockets but I need a little guidance. I am stationed in Iraq and there is no reference other than feedback from this forum. Thank you very much in advance.
Errors:
Compiler: Default compiler
Building Makefile: "C:\Users\mininet\C++\socket programming\Makefile.win"
Executing make...
make.exe -f "C:\Users\mininet\C++\socket programming\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
main.cpp:105: error: expected constructor, destructor, or type conversion before '=' token
main.cpp:105: error: expected `,' or `;' before '=' token
main.cpp:106: error: expected unqualified-id before "if"
main.cpp:106: error: expected `,' or `;' before "if"
main.cpp:115: error: expected unqualified-id before "if"
main.cpp:115: error: expected `,' or `;' before "if"
main.cpp:130: error: expected unqualified-id before "if"
main.cpp:130: error: expected `,' or `;' before "if"
make.exe: *** [main.o] Error 1
Execution terminated
------------------------------------------------------------------------------------
Here is the source I am working with.
#include <windows.h><br />
#include <winsock.h><br />
#include <iostream><br />
<br />
<br />
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);<br />
<br />
<br />
char szClassName[ ] = "WindowsApp";<br />
<br />
int WINAPI WinMain (HINSTANCE hThisInstance,<br />
HINSTANCE hPrevInstance,<br />
LPSTR lpszArgument,<br />
int nFunsterStil)<br />
<br />
{<br />
HWND hwnd; <br />
MSG messages; <br />
WNDCLASSEX wincl; <br />
<br />
<br />
wincl.hInstance = hThisInstance;<br />
wincl.lpszClassName = szClassName;<br />
wincl.lpfnWndProc = WindowProcedure; <br />
wincl.style = CS_DBLCLKS; <br />
wincl.cbSize = sizeof (WNDCLASSEX);<br />
<br />
<br />
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);<br />
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);<br />
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);<br />
wincl.lpszMenuName = NULL; <br />
wincl.cbClsExtra = 0; <br />
wincl.cbWndExtra = 0; <br />
<br />
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;<br />
<br />
<br />
if (!RegisterClassEx (&wincl))<br />
return 0;<br />
<br />
<br />
hwnd = CreateWindowEx (<br />
0, <br />
szClassName, <br />
"Windows App", <br />
WS_OVERLAPPEDWINDOW, <br />
CW_USEDEFAULT, <br />
CW_USEDEFAULT, <br />
544, <br />
375, <br />
HWND_DESKTOP, <br />
NULL, <br />
hThisInstance, <br />
NULL <br />
);<br />
<br />
<br />
ShowWindow (hwnd, nFunsterStil);<br />
<br />
<br />
while (GetMessage (&messages, NULL, 0, 0))<br />
{<br />
<br />
TranslateMessage(&messages);<br />
<br />
DispatchMessage(&messages);<br />
}<br />
<br />
<br />
return messages.wParam;<br />
}<br />
<br />
<br />
<br />
<br />
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)<br />
{<br />
switch (message) <br />
{<br />
case WM_DESTROY:<br />
PostQuitMessage (0); <br />
break;<br />
default: <br />
return DefWindowProc (hwnd, message, wParam, lParam);<br />
}<br />
<br />
return 0;<br />
}<br />
<br />
<br />
int (PASCAL FAR * lpfn_recv)(SOCKET, char FAR *, int, int);<br />
int (PASCAL FAR * lpfn_send)(SOCKET, char FAR *, int, int);<br />
int (PASCAL FAR * lpfn_WSAStartup)(WORD, LPWSADATA);<br />
int (PASCAL FAR * lpfn_WSACleanup)(void); <br />
int (PASCAL FAR * lpfn_WSAGetLastError)(void); <br />
<br />
OFSTRUCT stFile; <br />
HFILE hFile; <br />
HINSTANCE hWinSockDLL = 0; <br />
<br />
#ifdef WIN32 <br />
<br />
hFile = OpenFile("wsock32.dll", (OFSTRUCT FAR*)&stFile,OF_EXIST); <br />
if (hFile != HFILE_ERROR) <br />
hWinSockDLL = LoadLibrary ("wsock32.dll");<br />
#else<br />
<br />
hFile = OpenFile("winsock.dll", (OFSTRUCT FAR*)&stFile,OF_EXIST); <br />
if (hFile != HFILE_ERROR) <br />
hWinSockDLL = LoadLibrary ("winsock.dll");<br />
#endif <br />
<br />
if (hWinsockDLL >= 32) { <br />
(FARPROC)lpfn_recv = GetProcAddress (hWinsockDLL,"recv");<br />
(FARPROC)lpfn_send = GetProcAddress (hWinsockDLL,"send");<br />
(FARPROC)lpfn_WSAStartup = GetProcAddress(hWinSockDLL,"WSAStartup");<br />
(FARPROC)lpfn_WSACleanup = GetProcAddress(hWinSockDLL,"WSACleanup"); <br />
(FARPROC)lpfn_WSAGetLastError = GetProcAddress(hWinsockDLL,"WSAGetLastError");<br />
<br />
<br />
if (!lpfn_recv | !lpfn_send | !lpfn_WSAStartup | <br />
!lpfn_WSACleanup | !lpfn_WSAGetLastError) { <br />
FreeLibrary (hWinSockDLL); <br />
hWinSockDLL = 0; <br />
} <br />
} <br />
<br />
if (!hWinSockDLL) { <br />
MessageBox (hwnd, "Unable to load winsock.dll","Error"); <br />
} <br />
<br />
|
|
|
|
|
I have some problems when porting a WIN32 project into 64-Bit using VS2008.
1. I am using many third party libraries in my WIN32 project in which one of them uses old iostream functions. It gives me linker error LNK1104: cannot open file 'LIBCIMT.LIB' when I compile in X64 mode. I have the source code of the library with me. I tried recompiling the third party library using the new iostream header files under VS2008, but it gives me compilation errors which seems to be some in-compatibility issues of new and old iostreams.
2. In my project, I use both SQL and MAPI. The project compiles and runs perfectly in WIN32 mode. But the same gives me compilation error C2371: 'BOOKMARK' : redefinition; different basic types
Here is a sample code to reproduce the problem.
#include "stdafx.h"
#include <comdef.h>
#include <atlbase.h>
#include <sqlext.h>
#include <mapix.h>
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
All the header files are from the VS2008 installation folder.
How do I solve these problem with minimal changes in my code
Thanks in advance
cheers
Varghese Paul
|
|
|
|
|
Varghese Paul M wrote: 1. I am using many third party libraries in my WIN32 project in which one of them uses old iostream functions. It gives me linker error LNK1104: cannot open file 'LIBCIMT.LIB' when I compile in X64 mode. I have the source code of the library with me. I tried recompiling the third party library using the new iostream header files under VS2008, but it gives me compilation errors which seems to be some in-compatibility issues of new and old iostreams.
That sounds about right. I suspect you're going to have to bite the bullet & just start going through them, fixing them.
One thing to remember is that (IIRC) old iostreams weren't in the std namespace, new ones are. Also - this page has some handy migration hints[^].
Varghese Paul M wrote: 2. In my project, I use both SQL and MAPI. The project compiles and runs perfectly in WIN32 mode. But the same gives me compilation error C2371: 'BOOKMARK' : redefinition; different basic types
Here is a sample code to reproduce the problem.
You were lucky before. MAPI and SQL both define BOOKMARK. They happened to both be 32-bit, but now they're not. The only things I can suggest are 1) separating SQL and MAPI functionality into separate source files, or 2) putting (say) the MAPI stuff into a namespace like this:
namespace MAPI
{
#include <mapix.h>
}
and either using using namespace MAPI; or explicitly identifying things in this new MAPI namespace.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
How to reduce the Video capture size using Filters
|
|
|
|
|
Hai!
I have an MFC application in which if i press a button, a message box pops up. In that message box i have to display the Error message and caption so i am using MessageBox () instead of AfxMessageBox () since in AfxMessageBox () i cannot specify the caption.
Now the problem with MessageBox () is for as many times I press the button that many time the message box pops up, but if i use AfxMessage box it pops up once unless i respond to it i am not able to press the button in the main dialog.
So i need in this format i want to display the error message, its caption but unless user responds to that message box i must not be able to press the button as it happens in AfxMessageBox ().
I tried with the following, but still multiple messagebox pops up if i continously press the button in main dialog
MessageBox ("This error is due to XYZ", "Error", MB_ICONERROR | MB_APPLMODAL);
Thanks!
|
|
|
|
|
Thanks !
I got the solution !
|
|
|
|
|
Of whom?
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 )
|
|
|
|
|
Is the solution secret? Other people may learn from it...
My guess is you didn't have the parent window of the ::MessageBox set - Just NULL isn't good enough.
Do I get a prize?
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
windows api function MessageBox yes, AfxMessageBox function MFC Yes
|
|
|
|
|
MessageBox ("This error is due to XYZ", "Error", MB_ICONERROR | MB_APPLMODAL); (YOURS)
MessageBox ("This error is due to XYZ", "Error", MB_ICONERROR | MB_SYSTEMMODAL); (MINES)
The only difference between applmodal and systemmodal is systemmodal is given TOPMOSTWINDOW also, therefore, you would have to manually give focus back to the main application before pressing XYZ, or whatever it is first
|
|
|
|
|
Hello,
I dont why my question was mixed up with other questions so posted again
I have a CRichEditCtrl box on a CMDIChildWnd. When I move the mouse over this edit box its cursor changes to caret pointer indicating that the box is there. This CMDIChildWnd is made by Create()of CMDIChildWNd
Now when I make a Child window by CreateNewChild() and the add CRichEditCTrl on the childwindow the edit box is seen but when I move the mouse cursor on the edit box the cursor doesnt change to caret pointer .
What is the difference or what must be the problem in making child
windows in diff ways?
Pritha
|
|
|
|
|
|
Hello,
Once I got a debug error and from then I am not getting any info in Class Wizard. I did rebuild the project but when I press Ctrl W I am getting this error
Parsing error Expected "virtual"
Input Line "void KILLFOCUS(WPARAM wParam,LPARAM lParam)"
Thanks
Prithaa
|
|
|
|
|
At KILLFOCUS you created in the Class Wizard does not exist.or is not a virtual function.KILLFOCUS in front of you to add at virtual.
|
|
|
|
|
prithaa wrote: Input Line "void KILLFOCUS(WPARAM wParam,LPARAM lParam)"
Is the capitalization correct?
"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
|
|
|
|
|
|
I need to write a PC based application that will utilize a bluetooth dongle using the Microsoft Bluetooth Stack. I was looking for any recommendations on SDKs (comercial or otherwise) that anyone would recommend. Or are the Bluetooth apis well documented enough on the MSDN that no 3rd party SDKs are needed?
Thanks in advance
|
|
|
|
|
What do you need the dongle to do?
As long as it appears in the Device Manager, then all it's capabilities are available. If it's a network device, then it should act like all the other network devices, if it's a sound device, then it should appear in the sound device list.
|
|
|
|
|
The dongle is because the PC won't necessarily have any integrated bluetooth. I just need to be able to connect to a external BT device whose BT address I will receive at run-time and then I need to perform some OBEX transfers in both directions.
I haven't done any windows network programming so this would be new to me.
|
|
|
|
|
Have you looked at http://www.openobex.org/
|
|
|
|
|
Hello,
I'm writing an application that needs to interface with a Maxatec MT-200 receipt printer. This is done through posting bytes to the device. I have successfully changed character encodings and made text bold in the past, so my basic approach is sound.
I am working off the MT-200 technical manual, but I don't seem to be having much luck getting it working printing monochrome bitmap images (bitmap in the traditional sense, 1-bit per pixel).
ftp://ftp.maxatec-europe.com/Public/Maxatec/MT-200_Technical.pdf[^]
Look to page 59 and 60, defining and printing a downloaded bit image. It certainly has me confused.
[Name] Define downloaded bit image
[Format] ASCII GS ∗ x y d1 ... d (x x y x 8)
Hex 1D 2A x y d1 ... d (x x y x 8)
Decimal 29 42 x y d1 ... d (x x y x 8)
.................
The number of dots in the horizontal direction is x x 8, in the vertical
direction it is y x 8.
Surely the number of horizontal dots is the number specified by x. Does it simply mean x must be a multiple of 8? When I write the following bytes to the device:
1D 2A 10 10 66 66 66 66 66 66 66 66
in an effort to define a downloaded device image, the device becomes unresponsive - it doesn't print any additional ascii bytes I might send. It certainly doesn't respond to the print dowloaded image command:
1D 2F 30
What should I do? Can anyone make sense of this documentation? I myself cannot work it out, so I'd appreciate if someone else could weigh in,
Regards,
Sternocera
|
|
|
|
|
My suspicion is that the printer has an 8x8 dot head.
So, anything it prints will have to be in multiples of 8. But they then have a choice. Ask people to set the size, but trust them to set the size on multiples of 8? Or make the parameter be number of "heads", rather than number of dots.
So, you send:
9x3, which means 9 heads wide, and 3 heads deep, which means 72 dots by 24 dots.
I hope that gives you a lightbulb moment! I've had similar fun working with an LCD remote display device in the past.
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
Iain,
hmmm. I'll look into that, thanks. It certainly doesn't help matters when the documentation is written in "engrish", with no practical examples.
Regards,
Sternocera
|
|
|
|
|