kalde en funktion.
unit1.cpp//---------------------------------------------------------------------------
#include <vcl.h>
#include <winsock.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
SOCKET thesocket;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::modtag()
{
char recvbuf[1024];
char buf[10000] = "";
int test;
while(1)
{
strcpy(buf,"efter loop");
strcat(buf,"\r\n");
strcat(buf,Memo1->Text.c_str());
Memo1->Text = buf;
memset(recvbuf, 0, 1024);
test = recv(thesocket,recvbuf,256,0); //ioctlsocket(thesocket, FIONBIO, &v);
if(test == INVALID_SOCKET)
{
WSACleanup();
return;
}
strcpy(buf,recvbuf);
strcat(buf,"\r\n");
strcat(buf,Memo1->Text.c_str());
Memo1->Text = buf;
Sleep(100);
}
}
DWORD WINAPI modt(void* sock_)
{
modtag();
return 1;
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
int port = 12345;
char host[32] = "madman";
WORD sockversion;
WSADATA wsadata;
sockversion = MAKEWORD(1,1);
WSAStartup(sockversion, &wsadata);
LPHOSTENT hosten;
hosten = gethostbyname(host);
thesocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(thesocket == INVALID_SOCKET)
{
WSACleanup();
return;
}
SOCKADDR_IN server;
server.sin_family = AF_INET;
server.sin_addr = *((LPIN_ADDR)*hosten->h_addr_list);
server.sin_port = htons(port);
int test;
test = ::connect(thesocket,(LPSOCKADDR)&server,sizeof(struct sockaddr));
if(test == INVALID_SOCKET)
{
WSACleanup();
return;
}
char recvbuf[1024];
char buf[10000] = "";
strcpy(buf,"inden loop");
strcat(buf,"\r\n");
strcat(buf,Memo1->Text.c_str());
Memo1->Text = buf;
DWORD nThreadID;
CreateThread(0, 0, modt,(void*)thesocket, 0, &nThreadID);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
closesocket(thesocket);
WSACleanup();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char buf[1024] = "";
strcpy(buf,Edit1->Text.c_str());
int test;
test = send(thesocket,buf,strlen(buf),0);
if(test == INVALID_SOCKET)
{
WSACleanup();
return;
}
}
//---------------------------------------------------------------------------
unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TMemo *Memo1;
TEdit *Edit1;
TButton *Button1;
TButton *Button2;
TButton *Button3;
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall modtag();
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Det jeg skal have kaldt modtag() fra DWORD WINAPI modt(void* sock_) hvordan skal det gøres.. når jeg compiler min kode så kommer den med Call to undefined function 'modtag'