|
Tsaejen wrote:
What you mean by main() function. So, I cannot start a program without main() functon?
exactly, that's it....
actually, when a C/C++ program starts, the runtime looks for the main() function...
so, the program must be put into main() (at least, the beginning)...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
You must learn the basics of C++ before you can start working on TCP/IP in C++. If you even don't know what main() is, you can forget TCP and sockets for a long time.
|
|
|
|
|
#include "iostream.h"
#include "afxsock.h"
#include "stdlib.h"
main()
{
return 0;
};
////////////////////////////////////////////////////////////////////////////////////////
// Create a socket
BOOL Create(
UINT nSocketPort = 0,
int nSocketType = SOCK_STREAM,
long lEvent = FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE,
LPCTSTR lpszSocketAddress = NULL
);
////////////////////////////////////////////////////////////////////////////////////////
// Client socket Connect function
BOOL Connect(
LPCTSTR lpszHostAddress,
UINT nHostPort
);
BOOL Connect(
const SOCKADDR* lpSockAddr,
int nSockAddrLen
);
////////////////////////////////////////////////////////////////////////////////////////
// Server socket listen function
BOOL Listen(
int nConnectionBacklog = 5
);
////////////////////////////////////////////////////////////////////////////////////////
// Server socket Accept function
virtual BOOL Accept(
CAsyncSocket& rConnectedSocket,
SOCKADDR* lpSockAddr = NULL,
int* lpSockAddrLen = NULL
);
My code is above but still have error, help.....
error C2575: 'Accept' : only member functions and bases can be virtual
|
|
|
|
|
i think you should first learn for C/C++.
secondly, what are you trying to do with that code ?
your code above is not correct :
#include "iostream.h"
#include "afxsock.h"
#include "stdlib.h"
main()
{
return 0;
};
1) you declare main() without any returning type.
2) the ending ; is not correct there
3) the header files are standard headers, so they shouldn't be between "" but <> instead. Moreover, afx includes should be the first files to be includes
4) the program enters main, then execute the first instruction it finds (here return 0 ), which tells it to exit the function (so, also exiting the program, as main can be seen as the program at your level).
revise it this way :
#include <afxsock.h>
#include <iostream.h>
#include <stdlib.h>
void main(void) {
}
ok, then, what do you want to do with the following functions ?
it seems that you just copied/pasted some code you found in the doc into your source...
DON'T !!
these functions are already coded (and i doubt you could rewrite them by yourself seeing your advanced knowledge on the language).
just use them as the MSDN tells you to (right number of parameter, and matching types). also be careful of the case (C/C++ are case sensitive).
well now, give me a better piece of code in consequence and i'll try to help you more.
see you,
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
|
I was given a sch project and I have a deadline to complete the project. But now I stil don't know how to start the programming part. I also very weak in programming and never study visual c++ before. Very STRESS!!!!
The project is about MODBUSTCP PROTOCOL. I need to create a Dialog that can send data to PLC. I already created a Dialog that contains edit box to enter Destination IP Address, 2 radio button to choose MODBUS or MEWTOCOL, edit box to type message and send the message, and also a group box include some button which label door open that when I click on the button, it will send a message tell the PLC to open the dooor.
And now I don't know how to write the program that when I type a message and send to another Destination(IP Address).
|
|
|
|
|
I think you are in trouble
If anybody in this forum could help you'd have to be more concrete and send the different pieces of code that didn't work.
Do you use a wrapper class or you have to build at your own?
Marc Soleda.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
What is wrapper class?
My lecturer want me to use console application to try to do my testing on sending message first, and tell me to understand how TCP work then I will know how to do the MODBUS part....but I still not very understand the TCP work......
|
|
|
|
|
Tsaejen wrote:
What is wrapper class?
It provides an easy/summarized way (sometimes extends) to use a class and some of its methods.
Tsaejen wrote:
....but I still not very understand the TCP work......
Read CAsyncSockets[^]
and take a look to Client[^] and server[^] samples.
Marc Soleda.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
|
I actually want to start my program to do the socket programming. So the program I send to you yesterday, izit right to start like that?
|
|
|
|
|
Help me, please to change my MFC applications to unicode supported application.
I've already found a lot of articles about it, I've defined _UNICODE symbol and set wWinMainCRTStartup entry point. But I'm still cannot pass link - I get an error "unresolved external symbol WinMain". My quastions are:
1) Do I have to define all this for all DLL-s or only for main project?
2) Which library I have to use - mfc42 or mfc42u etc
3) What else I have to do to link my application?
Thanks,
Bella
|
|
|
|
|
Hi everyone, I am new to C++ Thread Programming, but I ran into a situation where my thread function never gets called, below is my code:
#include "StdAfx.h"
#include
#include
using namespace std;
static DWORD WINAPI kill (LPVOID p)
{
cout<<"Threading now";
return 0;
};
void main()
{
HANDLE t = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)kill, NULL, 0, NULL);
}
Can anyone tell me why the function "kill" never gets called? This is compiled in Visual C++ 6.0 under Windows 2000 Professtional. And how can I fix this?
Thanks
|
|
|
|
|
Now that you are in the right forum, the simple answer is to add a Sleep(1000); right after your call to CreateThread. That will allow you to see the output.
Next, look up the CreateEvent API and replace your Sleep call to a WaitForSingleObject call on the event that gets triggered by the thread function to let you know that it is complete.
This is an excellent book for understanding basic multithreading techniques.
Multithreaded Programming with Win32[^]
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
You don't need an event, you can wait on the thread handle
Pandoras Gift #44: Hope. The one that keeps you on suffering. aber.. "Wie gesagt, der Scheiss is' Therapie" boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
That's true. I always forget about that , since I've mostly worked with threads on servers and you usually only let threads close down when the entire process is shutting down and you stop handling requests.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
As for why that is happening, your main thread is exiting right away, which makes the whole process go away before the second thread gets any CPU time.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | NEW~! CP SearchBar v3.0 | C++ Forum FAQ
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
I have a Cedit subclass which is constructed like this..
CDockBar child is CStatic and CStatic child is CSubEdit..
Now I CeEdit::SetOwner(CDockBar) so that CDockBar would receive the notifications from CEdit.
Particularly i want to process NM_RETURN notifications when I press the ENTER key..
Now I already processed the WM_KEYDOWN from the subclassed c0ntrol.. and i can process the enter key from WM_KEYDOWN already.. but i still want the parent/owner to be notified of the ENTER keypress..(NM_ENTER) notification
I traced the Enter key press on the Cedit Control, in Spy++, the only messages generated are WM_KEYDOWN, WM_KEYUP, and WM_CHAR..
Why does NM_RETURN goesn't get generated?
|
|
|
|
|
i have created a MFC SDI application and want it support multiView.Therefore, i tried to Create another View, but i do not know how to add debug and nondebug versions of the GetDocument function to use data from CDocument.
can anybody help me?
|
|
|
|
|
Class wizard does this automatically for you, but here is the solution:
.h (inside the class):
CMyDoc * GetDocument();
.h (outside the class):
#ifndef _DEBUG // debug version
inline CMyDoc * CMyView::GetDocument()
{ return (CMyDoc *)m_pDocument; }
#endif
.cpp:
#ifdef _DEBUG
CMyDoc * CMyView::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc *)m_pDocument;
}
#endif //_DEBUG
Geert
Want to spread the newest version of your software automatically for free? Use Updater!
Visit my website: www.gvhsoftware.org
|
|
|
|
|
Where can I download the lastest Windows DDK?
I need to use function IoVolumeDeviceToDosName, but it is declared in ntddk.h
but I can't download the DDK from website of Micro$oft...
So any other else place where I can download it?
Thx!
Welcome to my site:
http://www.cntomorrow.com:3310
|
|
|
|
|
as far as I know windows ddk is not available for free. either you have to order it or you must have MSDN subscription.
Saurabh
|
|
|
|
|
In WinVista it will be call WDK - Windows Driver Kit[^]
and by the moment it's only available for MSDN subscribers (Windows Longhorn Beta program).
Marc Soleda.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
How to get the full pathname for a process via PID (Process Identifier)?
Welcome to my site:
http://www.cntomorrow.com:3310
|
|
|
|
|
first call OpenProcess with PROCESS_QUERY_INFORMATION as dwDesiredAccess to obtain a handle to process from PID.
then call GetProcessImageFileName.
Saurabh
|
|
|
|