Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Access dll over Christof Lange's struct class
Message
De
27/07/2001 08:05:43
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Access dll over Christof Lange's struct class
Divers
Thread ID:
00536282
Message ID:
00536282
Vues:
29
Hello,


i want to access a self written plain C dll from within FVP with help from
christof lange's struct class

the problem is i had to pass a pointer to a structure containing
serveral other pointers and int values ..

the passing works just fine .. but when i want to read out the data
back with the SetString procedure
the values get not updatet properly ..

here are some snipets of the source code:

dll -> struct definition in header file:

struct hlserver {
int id;
char *host_name;
char *address;
unsigned int ipaddr;
unsigned short port;
char *server_name;
char *map_name;
char *gamedir;
char *game;
int num_players;
int max_players;
int protocol_version;
char *sv_type;
char *sv_os;
};

dll -> function that is called from vfp:

char* HLRequestDetail ( struct hlserver *server)
{

SOCKET HLSock;
struct sockaddr_in HLAddr;
int HLpktlen, HLData;
char *HLok;
long pkt_data[PACKET_LEN/sizeof(long)];
char *pkt= (char*)&pkt_data[0];
server->ipaddr = inet_addr(server->address);

HLSock = socket(AF_INET,SOCK_DGRAM,0);
HLAddr.sin_family = AF_INET;
HLAddr.sin_port = htons(server->port);
HLAddr.sin_addr.s_addr = server->ipaddr;
sendto(HLSock,hl_details,12,0,(struct sockaddr *)
&HLAddr,sizeof(HLAddr));
HLpktlen = sizeof(HLAddr);
HLData = recvfrom(HLSock,pkt,sizeof(pkt_data)
,0,(struct sockaddr *)&HLAddr,&HLpktlen);


/* normaly now i would read out the data out of the recieved packet, but for testing purposes i generated the following lines of code to simulate some return values */

server->server_name= "HeinzTest";
server->map_name= "de_test";
server->num_players= 5;
server->max_players= 12;
server->protocol_version= 47;
return;
....


here the code from vfp:

&& Creat object of my subclass hlserverinfo from class struct
lnServerHandle = CreateObject ("hlserverinfo")

&& Start DLL Winsock ( WSAStartup with version checking , must be at least 1.1 )
lnStartNet = HLStartNet()
if lnStartNet = 1
return
endif

lcBuffer = lnServerHandle.GetString( ) && Initiate Structure from Object Strings

lnecho = HLRequestDetail( @lcBuffer ) && Call DLL with Structure Reference

lnServerHandle.SetString( m.lcBuffer ) && Read out of Structure to object properties

&& Read values in form
this.parent.txtTest.value = alltrim(lnServerHandle.sAddress)

and so on ...

declared the dll in fvp as followed:

DECLARE STRING HLRequestDetail in hlspydll STRING @

would be really nice if someone could give me tips/suggestions are even better a solution to my problem .. cause without this function my entire programm would be useless

THX beforehand

Christian Ehlscheid
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform